mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 04:00:10 +00:00
fix(ai): filter empty error assistant messages in transformMessages
When 429/500 errors occur during tool execution, empty assistant messages with stopReason='error' get persisted. These break the tool_use -> tool_result chain for Claude/Gemini APIs. Added centralized filtering in transformMessages to skip assistant messages with empty content and no tool calls. Provider-level filters remain for defense-in-depth.
This commit is contained in:
parent
d2f9ab110c
commit
fbb74bb29e
11 changed files with 125 additions and 8 deletions
|
|
@ -118,6 +118,14 @@ export function transformMessages<TApi extends Api>(messages: Message[], model:
|
|||
existingToolResultIds = new Set();
|
||||
}
|
||||
|
||||
// Skip empty assistant messages (no content and no tool calls)
|
||||
// This handles error responses (e.g., 429/500) that produced no content
|
||||
// All providers already filter these in convertMessages, but we do it here
|
||||
// centrally to prevent issues with the tool_use -> tool_result chain
|
||||
if (assistantMsg.content.length === 0 && toolCalls.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push(msg);
|
||||
} else if (msg.role === "toolResult") {
|
||||
existingToolResultIds.add(msg.toolCallId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue