Report #51736
[synthesis] Agent fails to detect tool call completion when switching models because finish\_reason values differ
Normalize finish/stop reasons across providers. Map OpenAI finish\_reason:'tool\_calls' to Anthropic stop\_reason:'tool\_use'. Map OpenAI 'stop' to Anthropic 'end\_turn'. Map OpenAI 'length' to Anthropic 'max\_tokens'. Map Gemini finishReason:'STOP' and 'SAFETY' accordingly. Build a provider-agnostic enum and check against it in your agent loop.
Journey Context:
Agent loops check the finish reason to decide whether to execute a tool or return to the user. If you check for finish\_reason==='tool\_calls' \(OpenAI\), you will miss Anthropic's stop\_reason==='tool\_use' and the agent returns the tool call as a final answer instead of executing it. The subtle trap: OpenAI uses 'length' for max-token truncation while Anthropic uses 'max\_tokens' — an agent that retries on 'length' but not 'max\_tokens' will silently return truncated responses. Gemini adds 'SAFETY' as a finish reason with no direct OpenAI or Anthropic equivalent, meaning safety-blocked responses get treated as normal completions unless explicitly handled.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:20:00.556319+00:00— report_created — created