From bae6fc498a235abcfc92a68b124eacb72aacc77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chuyusong=E2=80=9D?= <1350460443@qq.com> Date: Fri, 20 Mar 2026 19:21:43 +0800 Subject: [PATCH] feat: add temperature parameter to task tool for subagent control - Add optional temperature parameter (0.0-2.0) to task tool - Temperature is passed through to the subagent session - Priority: user-provided temperature > agent temperature > provider default - Update task.txt documentation with usage note for temperature override This allows dynamic control over subagent behavior during task delegation, enabling LLMs to adjust temperature based on task requirements. --- packages/opencode/src/session/llm.ts | 2 +- packages/opencode/src/session/message-v2.ts | 1 + packages/opencode/src/session/prompt.ts | 2 ++ packages/opencode/src/tool/task.ts | 7 +++++++ packages/opencode/src/tool/task.txt | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index daf70180e52d..ddfcf312c232 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -123,7 +123,7 @@ export namespace LLM { }, { temperature: input.model.capabilities.temperature - ? (input.agent.temperature ?? ProviderTransform.temperature(input.model)) + ? (input.user.temperature ?? input.agent.temperature ?? ProviderTransform.temperature(input.model)) : undefined, topP: input.agent.topP ?? ProviderTransform.topP(input.model), topK: ProviderTransform.topK(input.model), diff --git a/packages/opencode/src/session/message-v2.ts b/packages/opencode/src/session/message-v2.ts index f1335f6f21a3..8b09984ed352 100644 --- a/packages/opencode/src/session/message-v2.ts +++ b/packages/opencode/src/session/message-v2.ts @@ -369,6 +369,7 @@ export namespace MessageV2 { system: z.string().optional(), tools: z.record(z.string(), z.boolean()).optional(), variant: z.string().optional(), + temperature: z.number().min(0).max(2).optional(), }).meta({ ref: "UserMessage", }) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index bac958ec1033..00f2f464ec59 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -112,6 +112,7 @@ export namespace SessionPrompt { format: MessageV2.Format.optional(), system: z.string().optional(), variant: z.string().optional(), + temperature: z.number().min(0).max(2).optional(), parts: z.array( z.discriminatedUnion("type", [ MessageV2.TextPart.omit({ @@ -986,6 +987,7 @@ export namespace SessionPrompt { system: input.system, format: input.format, variant, + temperature: input.temperature, } using _ = defer(() => InstructionPrompt.clear(info.id)) diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts index 9cabf47eb1dc..83bd997fc38b 100644 --- a/packages/opencode/src/tool/task.ts +++ b/packages/opencode/src/tool/task.ts @@ -23,6 +23,12 @@ const parameters = z.object({ ) .optional(), command: z.string().describe("The command that triggered this task").optional(), + temperature: z + .number() + .min(0) + .max(2) + .describe("Override the agent's temperature for this task (0.0 to 2.0)") + .optional(), }) export const TaskTool = Tool.define("task", async (ctx) => { @@ -142,6 +148,7 @@ export const TaskTool = Tool.define("task", async (ctx) => { ...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])), }, parts: promptParts, + temperature: params.temperature, }) const text = result.parts.findLast((x) => x.type === "text")?.text ?? "" diff --git a/packages/opencode/src/tool/task.txt b/packages/opencode/src/tool/task.txt index 585cce8f9d0a..0e70d51c04b2 100644 --- a/packages/opencode/src/tool/task.txt +++ b/packages/opencode/src/tool/task.txt @@ -22,6 +22,7 @@ Usage notes: 4. The agent's outputs should generally be trusted 5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent. Tell it how to verify its work if possible (e.g., relevant test commands). 6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement. +7. You can optionally override the agent's temperature setting by providing a temperature parameter (0.0 to 2.0). Lower values (e.g., 0.2) make the output more deterministic and focused, while higher values (e.g., 0.8) make it more creative and varied. Use this when you need fine-grained control over the subagent's behavior for specific tasks. Example usage (NOTE: The agents below are fictional examples for illustration only - use the actual agents listed above):