From 4f38cb785045d4906b9c71d0cd080f18730629a2 Mon Sep 17 00:00:00 2001 From: Alexander Al-Bahrani Date: Tue, 24 Feb 2026 23:05:43 +0100 Subject: [PATCH] feat: add model parameter to Task tool for dynamic subagent model selection --- packages/opencode/src/tool/task.ts | 9 ++++++++- packages/opencode/src/tool/task.txt | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts index 8c8cf827abaf..0a94d16da373 100644 --- a/packages/opencode/src/tool/task.ts +++ b/packages/opencode/src/tool/task.ts @@ -10,6 +10,7 @@ import { iife } from "@/util/iife" import { defer } from "@/util/defer" import { Config } from "../config/config" import { PermissionNext } from "@/permission/next" +import { Provider } from "../provider/provider" const parameters = z.object({ description: z.string().describe("A short (3-5 words) description of the task"), @@ -22,6 +23,12 @@ const parameters = z.object({ ) .optional(), command: z.string().describe("The command that triggered this task").optional(), + model: z + .string() + .describe( + "Optional model to use for this task in the format 'provider/model' (e.g. 'github-copilot/claude-sonnet-4.6'). Overrides the agent's default model.", + ) + .optional(), }) export const TaskTool = Tool.define("task", async (ctx) => { @@ -103,7 +110,7 @@ export const TaskTool = Tool.define("task", async (ctx) => { const msg = await MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID }) if (msg.info.role !== "assistant") throw new Error("Not an assistant message") - const model = agent.model ?? { + const model = (params.model ? Provider.parseModel(params.model) : undefined) ?? agent.model ?? { modelID: msg.info.modelID, providerID: msg.info.providerID, } diff --git a/packages/opencode/src/tool/task.txt b/packages/opencode/src/tool/task.txt index 585cce8f9d0a..b29c452d71cb 100644 --- a/packages/opencode/src/tool/task.txt +++ b/packages/opencode/src/tool/task.txt @@ -18,6 +18,7 @@ When NOT to use the Task tool: Usage notes: 1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses 2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result. The output includes a task_id you can reuse later to continue the same subagent session. +7. You can optionally specify a `model` parameter to override the agent's default model. The format is "provider/model" (e.g. "github-copilot/claude-sonnet-4.6"). This is useful when orchestrating agents that need different model tiers for different tasks. 3. Each agent invocation starts with a fresh context unless you provide task_id to resume the same subagent session (which continues with its previous messages and tool outputs). When starting fresh, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you. 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).