fix: stop changing main model/agent from subtasks invocation (#7681)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
@@ -168,6 +168,12 @@ export namespace MessageV2 {
|
|||||||
prompt: z.string(),
|
prompt: z.string(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
agent: z.string(),
|
agent: z.string(),
|
||||||
|
model: z
|
||||||
|
.object({
|
||||||
|
providerID: z.string(),
|
||||||
|
modelID: z.string(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
command: z.string().optional(),
|
command: z.string().optional(),
|
||||||
})
|
})
|
||||||
export type SubtaskPart = z.infer<typeof SubtaskPart>
|
export type SubtaskPart = z.infer<typeof SubtaskPart>
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ export namespace SessionPrompt {
|
|||||||
// TODO: centralize "invoke tool" logic
|
// TODO: centralize "invoke tool" logic
|
||||||
if (task?.type === "subtask") {
|
if (task?.type === "subtask") {
|
||||||
const taskTool = await TaskTool.init()
|
const taskTool = await TaskTool.init()
|
||||||
|
const taskModel = task.model ? await Provider.getModel(task.model.providerID, task.model.modelID) : model
|
||||||
const assistantMessage = (await Session.updateMessage({
|
const assistantMessage = (await Session.updateMessage({
|
||||||
id: Identifier.ascending("message"),
|
id: Identifier.ascending("message"),
|
||||||
role: "assistant",
|
role: "assistant",
|
||||||
@@ -334,8 +335,8 @@ export namespace SessionPrompt {
|
|||||||
reasoning: 0,
|
reasoning: 0,
|
||||||
cache: { read: 0, write: 0 },
|
cache: { read: 0, write: 0 },
|
||||||
},
|
},
|
||||||
modelID: model.id,
|
modelID: taskModel.id,
|
||||||
providerID: model.providerID,
|
providerID: taskModel.providerID,
|
||||||
time: {
|
time: {
|
||||||
created: Date.now(),
|
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()
|
template = template.trim()
|
||||||
|
|
||||||
const model = await (async () => {
|
const taskModel = await (async () => {
|
||||||
if (command.model) {
|
if (command.model) {
|
||||||
return Provider.parseModel(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 {
|
try {
|
||||||
await Provider.getModel(model.providerID, model.modelID)
|
await Provider.getModel(taskModel.providerID, taskModel.modelID)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (Provider.ModelNotFoundError.isInstance(e)) {
|
if (Provider.ModelNotFoundError.isInstance(e)) {
|
||||||
const { providerID, modelID, suggestions } = e.data
|
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 templateParts = await resolvePromptParts(template)
|
||||||
const parts =
|
const isSubtask = (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
|
||||||
(agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
|
const parts = isSubtask
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
type: "subtask" as const,
|
type: "subtask" as const,
|
||||||
agent: agent.name,
|
agent: agent.name,
|
||||||
description: command.description ?? "",
|
description: command.description ?? "",
|
||||||
command: input.command,
|
command: input.command,
|
||||||
// TODO: how can we make task tool accept a more complex input?
|
model: {
|
||||||
prompt: templateParts.find((y) => y.type === "text")?.text ?? "",
|
providerID: taskModel.providerID,
|
||||||
|
modelID: taskModel.modelID,
|
||||||
},
|
},
|
||||||
]
|
// TODO: how can we make task tool accept a more complex input?
|
||||||
: [...templateParts, ...(input.parts ?? [])]
|
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({
|
const result = (await prompt({
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
messageID: input.messageID,
|
messageID: input.messageID,
|
||||||
model,
|
model: userModel,
|
||||||
agent: agentName,
|
agent: userAgent,
|
||||||
parts,
|
parts,
|
||||||
variant: input.variant,
|
variant: input.variant,
|
||||||
})) as MessageV2.WithParts
|
})) as MessageV2.WithParts
|
||||||
|
|||||||
Reference in New Issue
Block a user