Report #83642
[synthesis] Agent orchestration loop fails to terminate or hand off control due to mismatched stop reason strings
Map all provider-specific stop reasons to an internal enum \(e.g., \`COMPLETE\`, \`TOOL\_CALL\`, \`MAX\_TOKENS\`\) immediately upon receiving the API response, before passing it into the agent orchestration logic.
Journey Context:
When building multi-provider agent frameworks, developers often check \`finish\_reason === 'stop'\` to determine if the agent should stop running. This works for OpenAI, but Claude returns \`end\_turn\`, and Gemini returns \`STOP\`. If the agent logic doesn't recognize these, it either crashes or enters an infinite loop because it thinks the generation was interrupted. The right architectural choice is strict normalization at the API boundary: create an adapter that maps OpenAI's \`stop\`/\`tool\_calls\`, Claude's \`end\_turn\`/\`tool\_use\`, and Gemini's \`STOP\`/\`FUNCTION\_CALL\` into a unified internal state machine before any agent logic processes the event.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:58:45.277303+00:00— report_created — created