Skip to content

Conversation

mkmeral
Copy link
Contributor

@mkmeral mkmeral commented Aug 29, 2025

Description

This PR fixes a bug in the Graph multiagent pattern where the reset_on_revisit feature failed to enable cycles and feedback loops. The issue was in the _find_newly_ready_nodes method, which filtered out completed nodes before they could be revisited, making it impossible to implement feedback loops even when reset_on_revisit=True.

Key Changes:

  1. Fixed node revisiting logic: Modified _find_newly_ready_nodes to accept a completed_batch parameter and check conditions against the current batch rather than the global completed nodes state
  2. Improved condition checking: Updated _is_node_ready_with_conditions to work with the current execution batch instead of relying on global state
  3. Enhanced test coverage: Added comprehensive tests for:
    • Basic cyclic graph execution with proper exit conditions
    • Self-loop functionality with various scenarios
    • Complex multi-node graphs with cycles
    • Edge cases including infinite loop prevention and state reset behavior

Technical Details:

  • The bug prevented completed nodes from being reconsidered for execution, breaking feedback loops
  • The fix allows nodes to be revisited when their incoming edge conditions are satisfied
  • State reset functionality now works correctly for revisited nodes
  • Added safety mechanisms (execution limits and timeouts) to prevent infinite loops

Related Issues

Fixes #684

Documentation PR

No documentation changes required - this is a bug fix that restores intended functionality.

Type of Change

Bug fix

Testing

How have you tested the change?

  • Added comprehensive test suite covering cyclic graph execution scenarios
  • Tested self-loop functionality with various conditions
  • Verified state reset behavior during node revisits
  • Added edge case testing for infinite loop prevention
  • All existing tests continue to pass

Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@zastrowm zastrowm enabled auto-merge (squash) September 5, 2025 20:12
@zastrowm zastrowm dismissed their stale review September 8, 2025 14:56

I updated the PR

@zastrowm zastrowm merged commit b568864 into strands-agents:main Sep 8, 2025
12 of 14 checks passed
This was referenced Sep 17, 2025
Unshure pushed a commit to Unshure/sdk-python that referenced this pull request Sep 24, 2025
fix a bug in the Graph multiagent pattern where the reset_on_revisit feature fails to enable cycles and feedback loops. The issue was in the _find_newly_ready_nodes method, which filtered out completed nodes before they could be revisited, making it impossible to implement feedback loops even when reset_on_revisit=True.

---------

Co-authored-by: Murat Kaan Meral <[email protected]>Co-authored-by: Mackenzie Zastrow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] reset_on_revisit doesn't work with cycles/feedback loops in Graph

4 participants