summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDaniel Polito <[email protected]>2026-01-15 20:18:39 -0300
committerGitHub <[email protected]>2026-01-15 17:18:39 -0600
commit8b08d340acb99f4fae71c974f2f430154c1d6cc1 (patch)
tree42ed994a649ad146e60f0270cd0f8c9a9d54a5f3
parent81983d4a2e4506211db8482b8e4fe0384863bf85 (diff)
downloadopencode-8b08d340acb99f4fae71c974f2f430154c1d6cc1.tar.gz
opencode-8b08d340acb99f4fae71c974f2f430154c1d6cc1.zip
fix: stop changing main model/agent from subtasks invocation (#7681)
Co-authored-by: Aiden Cline <[email protected]>
-rw-r--r--packages/opencode/src/session/message-v2.ts6
-rw-r--r--packages/opencode/src/session/prompt.ts48
2 files changed, 36 insertions, 18 deletions
diff --git a/packages/opencode/src/session/message-v2.ts b/packages/opencode/src/session/message-v2.ts
index 7a55599fd..9f2e0ba06 100644
--- a/packages/opencode/src/session/message-v2.ts
+++ b/packages/opencode/src/session/message-v2.ts
@@ -168,6 +168,12 @@ export namespace MessageV2 {
prompt: z.string(),
description: z.string(),
agent: z.string(),
+ model: z
+ .object({
+ providerID: z.string(),
+ modelID: z.string(),
+ })
+ .optional(),
command: z.string().optional(),
})
export type SubtaskPart = z.infer<typeof SubtaskPart>
diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts
index 345b1c49e..8327698fd 100644
--- a/packages/opencode/src/session/prompt.ts
+++ b/packages/opencode/src/session/prompt.ts
@@ -316,6 +316,7 @@ export namespace SessionPrompt {
// TODO: centralize "invoke tool" logic
if (task?.type === "subtask") {
const taskTool = await TaskTool.init()
+ const taskModel = task.model ? await Provider.getModel(task.model.providerID, task.model.modelID) : model
const assistantMessage = (await Session.updateMessage({
id: Identifier.ascending("message"),
role: "assistant",
@@ -334,8 +335,8 @@ export namespace SessionPrompt {
reasoning: 0,
cache: { read: 0, write: 0 },
},
- modelID: model.id,
- providerID: model.providerID,
+ modelID: taskModel.id,
+ providerID: taskModel.providerID,
time: {
created: Date.now(),
},
@@ -1633,7 +1634,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
template = template.trim()
- const model = await (async () => {
+ const taskModel = await (async () => {
if (command.model) {
return Provider.parseModel(command.model)
}
@@ -1648,7 +1649,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
})()
try {
- await Provider.getModel(model.providerID, model.modelID)
+ await Provider.getModel(taskModel.providerID, taskModel.modelID)
} catch (e) {
if (Provider.ModelNotFoundError.isInstance(e)) {
const { providerID, modelID, suggestions } = e.data
@@ -1673,25 +1674,36 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
const templateParts = await resolvePromptParts(template)
- const parts =
- (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
- ? [
- {
- type: "subtask" as const,
- agent: agent.name,
- description: command.description ?? "",
- command: input.command,
- // TODO: how can we make task tool accept a more complex input?
- prompt: templateParts.find((y) => y.type === "text")?.text ?? "",
+ const isSubtask = (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
+ const parts = isSubtask
+ ? [
+ {
+ type: "subtask" as const,
+ agent: agent.name,
+ description: command.description ?? "",
+ command: input.command,
+ model: {
+ providerID: taskModel.providerID,
+ modelID: taskModel.modelID,
},
- ]
- : [...templateParts, ...(input.parts ?? [])]
+ // TODO: how can we make task tool accept a more complex input?
+ prompt: templateParts.find((y) => y.type === "text")?.text ?? "",
+ },
+ ]
+ : [...templateParts, ...(input.parts ?? [])]
+
+ const userAgent = isSubtask ? (input.agent ?? (await Agent.defaultAgent())) : agentName
+ const userModel = isSubtask
+ ? input.model
+ ? Provider.parseModel(input.model)
+ : await lastModel(input.sessionID)
+ : taskModel
const result = (await prompt({
sessionID: input.sessionID,
messageID: input.messageID,
- model,
- agent: agentName,
+ model: userModel,
+ agent: userAgent,
parts,
variant: input.variant,
})) as MessageV2.WithParts