Skip to content

Commit 025e605

Browse files
committed
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
1 parent c608392 commit 025e605

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/core/task/Task.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,10 +2132,9 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
21322132
"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.",
21332133
)
21342134

2135-
await this.addToApiConversationHistory({
2136-
role: "assistant",
2137-
content: [{ type: "text", text: "Failure: I did not provide a response." }],
2138-
})
2135+
// Don't add error messages to the API conversation history as it pollutes
2136+
// the context sent to the LLM. The error is already shown to the user via say("error").
2137+
// This prevents the issue where API errors disrupt the conversation flow.
21392138
}
21402139

21412140
// If we reach here without continuing, return false (will always be false for now)

0 commit comments

Comments
 (0)