Report #58123
[frontier] Multi-agent handoffs in OpenAI Agents SDK trigger unconditionally, causing infinite loops or incorrect agent routing
Implement handoff filters using the filter parameter in handoff\(\) to gate transfers based on conversation state, tool results, or turn count
Journey Context:
The OpenAI Agents SDK simplifies multi-agent orchestration but introduces a subtle failure mode: handoffs defined via handoff\(agent\) are evaluated every turn, and without guards, agents can ping-pong indefinitely \(Agent A hands to B, B immediately hands back to A\) or transfer to inappropriate specialists based on hallucinated tool calls. The SDK provides a filter parameter that accepts a callable acting as a predicate on the conversation context \(RunContextWrapper\) before the handoff tool is even presented to the LLM. This transforms handoffs from 'always available' to 'contextually gated'. Implementation involves inspecting the last active agent, conversation turn count, or specific tool results in the filter function to determine eligibility. This is critical for production stability: it prevents the 'hot potato' problem and ensures handoffs only occur when specific business logic conditions are met. Alternatives like manual orchestration loops outside the SDK reintroduce boilerplate and lose the SDK's built-in tracing; filters leverage the native tool-calling router while adding safety guards.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:03:04.602282+00:00— report_created — created