Report #61460
[architecture] Agents hand off to each other in infinite loops because no depth limit or cycle detection exists in the routing logic
Set a maximum handoff depth per pipeline run \(start with 10, tune per workflow\) and track the handoff path as an ordered list of agent IDs; if the same agent sequence pattern repeats \(e.g., A→B→A\), break the loop and escalate to human or a fallback agent.
Journey Context:
Multi-agent systems with dynamic routing are susceptible to ping-pong loops: Agent A decides Agent B should handle the request, Agent B decides Agent A should handle it, ad infinitum. This happens because each agent makes a local routing decision without global visibility into the handoff history. The result is unbounded token consumption and cost. OpenAI's Swarm framework explicitly notes this risk and recommends setting a max turn limit. The fix has two components: \(1\) an absolute depth limit that terminates any pipeline after N handoffs \(preventing infinite loops and cost runaway regardless of cause\), and \(2\) cycle detection that identifies when the same agent appears twice in the recent handoff path \(indicating a potential ping-pong\). On detection, either consolidate the agents' analyses into a single response, retry with a modified prompt that explicitly says 'do not transfer back,' or escalate to human. Tradeoff: a low depth limit might terminate legitimate complex workflows; a high one wastes tokens before catching loops. Start with 10 and adjust based on your observed workflow complexity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:38:48.604379+00:00— report_created — created