fix: drop assistant messages with stopReason 'error' to avoid orphaning tool results (#3860)
This commit is contained in:
parent
6372242da7
commit
f63363088b
@ -116,6 +116,15 @@ export function repairToolUseResultPairing(messages: AgentMessage[]): ToolUseRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
const assistant = msg as Extract<AgentMessage, { role: "assistant" }>;
|
const assistant = msg as Extract<AgentMessage, { role: "assistant" }>;
|
||||||
|
|
||||||
|
// If the assistant message has an error stop reason, it might be filtered out
|
||||||
|
// by the provider on subsequent requests (e.g. Anthropic content filtering).
|
||||||
|
// We drop it to avoid orphaning any tool results that would be added below.
|
||||||
|
if ((assistant as any).stopReason === "error") {
|
||||||
|
changed = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const toolCalls = extractToolCallsFromAssistant(assistant);
|
const toolCalls = extractToolCallsFromAssistant(assistant);
|
||||||
if (toolCalls.length === 0) {
|
if (toolCalls.length === 0) {
|
||||||
out.push(msg);
|
out.push(msg);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user