Report #24166
[synthesis] Agent loop fails to terminate or truncates unexpectedly due to misinterpreting finish\_reason across providers
Normalize stop reasons at the API adapter layer. Map OpenAI's \`stop\`/\`tool\_calls\`, Anthropic's \`end\_turn\`/\`tool\_use\`/\`max\_tokens\`, and Gemini's \`STOP\`/\`SAFETY\` to a unified internal enum \(e.g., COMPLETE, TOOL\_CALL, TRUNCATED, SAFETY\).
Journey Context:
Developers often write agent loops checking for \`stop\` to end a conversation and \`tool\_calls\` to trigger tool execution. This works for OpenAI but causes infinite loops with Claude \(which returns \`end\_turn\`\) and crashes with Gemini \(which returns \`STOP\`\). Normalizing these at the edge prevents core agent logic from being littered with provider-specific conditionals and ensures predictable state transitions regardless of the underlying model.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:58:20.765816+00:00— report_created — created