-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Infinite recursion in src/agents/extensions/visualization.py due to circular references #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Although this is technically possible(once the bug gets fixed), what sense does it make if agents keep forever turning in circle ? They might need a sort of memory context that allows to break the circle somehow. Note that it's always possible to use an Agent as a tool, and that agent could have many as a tools, the difference is that the Agent as a tool will Always return and the handoff "never". So I'd say maybe for your use case the framework needs to have a sort of "conditional return", which means it could then dynamically decide if it should handoff/keep the hand, or return like being called as a tool, that seems to me safer than handoff circles. |
Hi @wassfila, You’re right that an endless loop is pointless, but short, controlled cycles can be useful. Anthropic’s recent post on “Building Effective Agents” describes evaluator-optimizer (or “self-critique”) patterns where two agents deliberately hand a task back and forth until a shared stopping condition—accuracy threshold, max-iterations, etc.—is met. That requires:
With those guards the framework supports both simple chains and the more autonomous, self-refining loops the blog highlights—without risking infinite spins.
|
Uh oh!
There was an error while loading. Please reload this page.
Issue Description
The functions
get_all_nodes
andget_all_edges
insrc/agents/extensions/visualization.py
can lead to infinite recursion when there are circular references between agents (when agents form a cycle through handoffs).Current Behavior
When agents have circular references through handoffs, the visualization functions will recursively traverse the agent graph without any cycle detection, leading to infinite recursion and eventual stack overflow.
Expected Behavior
The visualization functions should handle circular references gracefully by detecting cycles and preventing repeated traversal of the same agents.
Proposed Solution
Add a
visited
set to track already visited agents and prevent repeated recursion. Here's a sketch of the fix:Similar changes would be needed for
get_all_edges
.The text was updated successfully, but these errors were encountered: