fix: prevent API error messages from polluting chat history

Remove error message from API conversation history when assistant provides no response.
Keep error display to user via say("error") but do not add to LLM context.
This fixes the issue where API errors disrupt conversation flow.

Fixes #7249
This commit is contained in:
Roo Code 2025-08-20 08:52:56 +00:00
parent c608392a85
commit 025e6053a6

View file

@ -2132,10 +2132,9 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
"Unexpected API Response: The language model did not provide any assistant messages. This may indicate an issue with the API or the model's output.",
)
await this.addToApiConversationHistory({
role: "assistant",
content: [{ type: "text", text: "Failure: I did not provide a response." }],
})
// Don't add error messages to the API conversation history as it pollutes
// the context sent to the LLM. The error is already shown to the user via say("error").
// This prevents the issue where API errors disrupt the conversation flow.
}
// If we reach here without continuing, return false (will always be false for now)