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 @@ -188,7 +188,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())

# Reset execution status
Expand Down
34 changes: 34 additions & 0 deletions tests/strands/multiagent/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2405,3 +2405,37 @@ async def stream_async(self, prompt=None, **kwargs):
assert result.completed_nodes == 2
assert "custom_node" in result.results
assert "regular_node" in result.results


@pytest.mark.asyncio
async def test_reset_executor_state_preserves_graph_state_for_nested_graph():
"""Verify reset_executor_state does not corrupt MultiAgentBase state.

When a GraphNode wraps a MultiAgentBase executor (e.g. a nested Graph),
reset_executor_state() must not overwrite GraphState with AgentState.
Regression test for #1775.
"""
inner_agent = create_mock_agent("inner", "inner response")
inner_builder = GraphBuilder()
inner_builder.add_node(inner_agent, "inner_node")
inner_builder.set_entry_point("inner_node")
inner_graph = inner_builder.build()

# inner_graph.state is a GraphState, not AgentState
assert isinstance(inner_graph.state, GraphState)

node = GraphNode(node_id="nested", executor=inner_graph)

# Simulate a completed execution
node.execution_status = Status.COMPLETED
node.result = NodeResult(result=MagicMock(), status=Status.COMPLETED)

# Reset should NOT corrupt the nested graph's state
node.reset_executor_state()

# After reset, the executor's state must still be GraphState
assert isinstance(inner_graph.state, GraphState), (
"reset_executor_state overwrote GraphState with AgentState"
)
assert node.execution_status == Status.PENDING
assert node.result is None