Skip to content

Conversation

@msalehan
Copy link

Description

Here's the completed PR description:


Description

Add interrupt support for Graph multi-agent pattern, following the same implementation pattern as Swarm (PR #1193).

Implementation Changes:

src/strands/multiagent/graph.py:

  • Added graph reference to GraphNode for interrupt state restoration
  • Enhanced GraphNode.reset_executor_state() to restore from interrupt context (messages, state, interrupt_state)
  • Modified Graph.__init__() to set graph reference on all nodes
  • Updated _execute_node() to distinguish between hook interrupts (activated=False) and agent interrupts (activated=True)
  • Fixed _activate_interrupt() to save agent's actual activated flag (not hardcoded True)
  • Added interrupt response handling in _execute_node() to properly restore node state

Test Coverage:

  • Added 2 unit tests in tests/strands/multiagent/test_graph.py:
    • test_graph_interrupt_on_before_node_call_event - Hook-based interrupt
    • test_graph_interrupt_on_agent - Agent tool interrupt
  • Added 2 integration tests in tests_integ/interrupts/multiagent/test_hook.py:
    • test_graph_interrupt - Full end-to-end with approval
    • test_graph_interrupt_reject - Rejection with cancellation

This enables graphs to be properly interrupted mid-execution (via hooks or agent tools) and resumed from the exact point of interruption, maintaining state consistency.

Related Issues

#204

Documentation PR

None

Type of Change

New feature

Testing

How have you tested the change? 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.

Mohammad Salehan added 2 commits December 16, 2025 14:14
Add comprehensive interrupt handling and resume functionality to the Graph class:

- Import and initialize _InterruptState to track interrupt state across invocations
- Call interrupt_state.resume() at the start of invoke() to properly resume interrupted tasks
- Track MultiAgentNodeInterruptEvent occurrences during graph execution
- Pass interrupts to _build_result() for inclusion in final result
- Fix resume state management by only clearing flags on COMPLETED/FAILED status
- Create a copy of _resume_next_nodes to prevent clearing the list being iterated
- Add detailed debug logging for resume state at execution start
- Detect interrupts during batch execution and break out early when detected

This enables graphs to be properly interrupted mid-execution and resumed from the exact point of interruption, maintaining state consistency across session boundaries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant