Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export namespace MessageV2 {
description: z.string(),
agent: z.string(),
command: z.string().optional(),
model: z.object({ providerID: z.string(), modelID: z.string() }).optional(),
})
export type SubtaskPart = z.infer<typeof SubtaskPart>

Expand Down
39 changes: 36 additions & 3 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ export namespace SessionPrompt {
// TODO: centralize "invoke tool" logic
if (task?.type === "subtask") {
const taskTool = await TaskTool.init()
const taskAgent = await Agent.get(task.agent)

const resolveModel = task.model ?? taskAgent.model ?? lastUser.model
const taskModel = await Provider.getModel(resolveModel.providerID, resolveModel.modelID)

const assistantMessage = (await Session.updateMessage({
id: Identifier.ascending("message"),
role: "assistant",
Expand All @@ -334,8 +339,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(),
},
Expand Down Expand Up @@ -376,7 +381,6 @@ export namespace SessionPrompt {
{ args: taskArgs },
)
let executionError: Error | undefined
const taskAgent = await Agent.get(task.agent)
const taskCtx: Tool.Context = {
agent: task.agent,
messageID: assistantMessage.id,
Expand Down Expand Up @@ -1545,6 +1549,7 @@ export namespace SessionPrompt {
}

const templateParts = await resolvePromptParts(template)
<<<<<<< HEAD
const parts =
(agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
? [
Expand All @@ -1558,12 +1563,40 @@ export namespace SessionPrompt {
},
]
: [...templateParts, ...(input.parts ?? [])]
=======
const isSubtask = (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
const parts = isSubtask
? [
{
type: "subtask" as const,
agent: agent.name,
model: { providerID: model.providerID, modelID: model.modelID },
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 ?? "",
},
]
: [...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)
: model
>>>>>>> 4c0b95417 (fix: restore main session model on subtask completion)

const result = (await prompt({
sessionID: input.sessionID,
messageID: input.messageID,
<<<<<<< HEAD
model,
agent: agentName,
=======
model: userModel,
agent: userAgent,
>>>>>>> 4c0b95417 (fix: restore main session model on subtask completion)
parts,
variant: input.variant,
})) as MessageV2.WithParts
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ export type Part =
description: string
agent: string
command?: string
model?: {
providerID: string
modelID: string
}
}
| ReasoningPart
| FilePart
Expand Down Expand Up @@ -1832,6 +1836,10 @@ export type SubtaskPartInput = {
description: string
agent: string
command?: string
model?: {
providerID: string
modelID: string
}
}

export type Command = {
Expand Down
Loading