Skip to content

fix(graph): prevent reset_executor_state from corrupting MultiAgentBase state#1786

Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/graph-node-reset-multiagent-state
Closed

fix(graph): prevent reset_executor_state from corrupting MultiAgentBase state#1786
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/graph-node-reset-multiagent-state

Conversation

@giulio-leone
Copy link

Problem

GraphNode.reset_executor_state() corrupts the executor state when the executor is a MultiAgentBase (e.g. a nested Graph).

The method checks hasattr(self.executor, "state") without distinguishing executor type, then unconditionally assigns AgentState(...). For MultiAgentBase executors whose .state is a GraphState, this overwrites it with the wrong type — breaking the nested executor.

Two call sites are affected:

  • _execute_node: guarded by reset_on_revisit (triggers when revisiting a nested graph node in a cycle)
  • deserialize_state: unguarded (triggers when restoring a completed run with no next_nodes_to_execute)

Root Cause

__post_init__ already has the correct guard:

if hasattr(self.executor, "state") and hasattr(self.executor.state, "get"):
    self._initial_state = AgentState(self.executor.state.get())

But reset_executor_state() was missing the hasattr(self.executor.state, "get") check:

if hasattr(self.executor, "state"):
    self.executor.state = AgentState(self._initial_state.get())  # Wrong for MultiAgentBase

GraphState doesn't have a .get() method, so the guard correctly skips it.

Fix

Add the same hasattr(self.executor.state, "get") guard to reset_executor_state(), matching the existing pattern in __post_init__.

Test

Added test_reset_executor_state_preserves_multiagent_graph_state — verifies that a GraphNode wrapping a MultiAgentBase with GraphState preserves the state type after reset_executor_state().

Fixes #1775

…se state

GraphNode.reset_executor_state() checked hasattr(self.executor, 'state')
without distinguishing executor type. For MultiAgentBase executors (e.g.
nested Graph), this overwrote GraphState with AgentState, breaking the
executor.

Add the same hasattr(self.executor.state, 'get') guard that __post_init__
already uses, so only AgentState-based executors are reset.

Fixes strands-agents#1775

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giulio-leone
Copy link
Author

Closing — focusing on higher-impact contributions.

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

1 participant