core: fix issue when switching models (mainly between providers) where past reasoning/metadata would be sent to server and cause 400 errors since they came from another account/provider

This commit is contained in:
Aiden Cline
2026-01-20 16:39:00 -06:00
parent 0c4ffec857
commit 021e42c0bb
4 changed files with 164 additions and 30 deletions

View File

@@ -598,7 +598,7 @@ export namespace SessionPrompt {
sessionID,
system: [...(await SystemPrompt.environment()), ...(await SystemPrompt.custom())],
messages: [
...MessageV2.toModelMessages(sessionMessages),
...MessageV2.toModelMessages(sessionMessages, model),
...(isLastStep
? [
{
@@ -1778,18 +1778,19 @@ NOTE: At any point in time through this workflow you should feel free to ask the
const agent = await Agent.get("title")
if (!agent) return
const model = await iife(async () => {
if (agent.model) return await Provider.getModel(agent.model.providerID, agent.model.modelID)
return (
(await Provider.getSmallModel(input.providerID)) ?? (await Provider.getModel(input.providerID, input.modelID))
)
})
const result = await LLM.stream({
agent,
user: firstRealUser.info as MessageV2.User,
system: [],
small: true,
tools: {},
model: await iife(async () => {
if (agent.model) return await Provider.getModel(agent.model.providerID, agent.model.modelID)
return (
(await Provider.getSmallModel(input.providerID)) ?? (await Provider.getModel(input.providerID, input.modelID))
)
}),
model,
abort: new AbortController().signal,
sessionID: input.session.id,
retries: 2,
@@ -1800,7 +1801,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
},
...(hasOnlySubtaskParts
? [{ role: "user" as const, content: subtaskParts.map((p) => p.prompt).join("\n") }]
: MessageV2.toModelMessages(contextMessages)),
: MessageV2.toModelMessages(contextMessages, model)),
],
})
const text = await result.text.catch((err) => log.error("failed to generate title", { error: err }))