Skip to content

fix: skip AgentState reset for MultiAgentBase executors in GraphNode#1791

Open
giulio-leone wants to merge 3 commits intostrands-agents:mainfrom
giulio-leone:fix/issue-1775-reset-executor-state-multiagent
Open

fix: skip AgentState reset for MultiAgentBase executors in GraphNode#1791
giulio-leone wants to merge 3 commits intostrands-agents:mainfrom
giulio-leone:fix/issue-1775-reset-executor-state-multiagent

Conversation

@giulio-leone
Copy link

Problem

GraphNode.reset_executor_state() unconditionally overwrites executor.state with AgentState(...), corrupting the GraphState dataclass on nested Graph/Swarm executors.

Two call sites are affected:

  1. _execute_node (guarded by reset_on_revisit): triggers when a nested graph node is revisited in a cycle
  2. deserialize_state (unguarded): iterates all nodes unconditionally when restoring a completed graph run

Root Cause

__post_init__ correctly guards against capturing MultiAgentBase state (hasattr(self.executor.state, "get")), so _initial_state stays as the default empty AgentState(). But reset_executor_state lacks this guard:

# Before (corrupts GraphState on MultiAgentBase executors)
if hasattr(self.executor, "state"):
    self.executor.state = AgentState(self._initial_state.get())

Fix

Add isinstance(self.executor, MultiAgentBase) guard to skip the state reset for multi-agent executors whose state is not an AgentState dict:

# After (preserves GraphState on MultiAgentBase executors)
if hasattr(self.executor, "state") and not isinstance(self.executor, MultiAgentBase):
    self.executor.state = AgentState(self._initial_state.get())

Test

Added test_reset_executor_state_preserves_multiagent_state_type that:

  1. Creates a MultiAgentBase mock with a GraphState attribute
  2. Calls reset_executor_state()
  3. Asserts the state remains a GraphState instance (not overwritten to AgentState)

Fixes #1775

GraphNode.reset_executor_state() unconditionally overwrites executor.state
with AgentState(...), corrupting the GraphState dataclass on nested
Graph/Swarm executors. This breaks:
- Cyclic graphs with reset_on_revisit enabled (nested graph revisit)
- Session persistence deserialization of completed graph runs

Add isinstance(self.executor, MultiAgentBase) guard to skip the state
reset for multi-agent executors whose state is not an AgentState dict.

Fixes strands-agents#1775

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 1, 2026 00:45
@github-actions github-actions bot added the size/s label Mar 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a state-type corruption bug in GraphNode.reset_executor_state() where nested multi-agent executors (e.g., Graph/Swarm) could have their dataclass state overwritten with an AgentState during node resets and session deserialization.

Changes:

  • Skip resetting executor.state when the executor is a MultiAgentBase, preserving GraphState/SwarmState types.
  • Add a regression test ensuring reset_executor_state() does not overwrite a multi-agent executor’s state type.
  • Expand method docstring to clarify why multi-agent state resets are skipped.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/strands/multiagent/graph.py Adds MultiAgentBase guard in GraphNode.reset_executor_state() to prevent clobbering nested executor state types.
tests/strands/multiagent/test_graph.py Adds regression test for #1775 validating multi-agent state type is preserved across resets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…aph_state

Replace plain string with AgentResult instance for NodeResult.result to
match the type annotation (AgentResult | MultiAgentResult | Exception)
and prevent future breakage from type-checking code paths.

Refs: strands-agents#1791
@giulio-leone
Copy link
Author

All CI checks pass. Ready for review.

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.

[BUG] GraphNode.reset_executor_state() corrupts MultiAgentBase executor state

2 participants