Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/strands/multiagent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def reset_executor_state(self) -> None:
if hasattr(self.executor, "messages"):
self.executor.messages = copy.deepcopy(self._initial_messages)

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

if hasattr(self.executor, "_model_state"):
Expand Down
26 changes: 26 additions & 0 deletions tests/strands/multiagent/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,32 @@ async def test_node_reset_executor_state():
assert multi_agent_node.result is None


def test_node_reset_executor_state_does_not_corrupt_nested_graph_state():
"""Test that reset_executor_state does not overwrite a nested Graph's GraphState with AgentState."""
inner_agent = create_mock_agent("inner_agent")
builder = GraphBuilder()
builder.add_node(inner_agent, "inner_a")
inner_graph = builder.build()

# The nested Graph's .state is GraphState, which does not have a .get() method
assert isinstance(inner_graph.state, GraphState)
assert not hasattr(inner_graph.state, "get")

# Wrap the nested graph in a GraphNode
outer_node = GraphNode("outer", inner_graph)
outer_node.execution_status = Status.COMPLETED

# Before fix: reset_executor_state would call AgentState(self._initial_state.get())
# and assign it to inner_graph.state, overwriting GraphState with AgentState.
outer_node.reset_executor_state()

# Verify the nested graph's state was NOT replaced with AgentState
assert isinstance(inner_graph.state, GraphState), (
"reset_executor_state must not replace a nested Graph's GraphState with AgentState"
)
assert outer_node.execution_status == Status.PENDING


def test_graph_dataclasses_and_enums():
"""Test dataclass initialization, properties, and enum behavior."""
# Test Status enum
Expand Down