diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index 075f070e4264..a2d13e5c8382 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -139,7 +139,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 b3c34539e77e..53d89229e739 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({ @@ -1017,6 +1018,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 e3781126d0c1..ee96ada16b9a 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):