Skip to content

fix: guard state reset in GraphNode.reset_executor_state() for MultiAgentBase executors#2071

Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/graph-node-reset-executor-state-multi-agent
Open

fix: guard state reset in GraphNode.reset_executor_state() for MultiAgentBase executors#2071
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/graph-node-reset-executor-state-multi-agent

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Description

reset_executor_state() checked hasattr(self.executor, "state") without
checking whether the state is an AgentState. Graph (a MultiAgentBase) has
a .state attribute of type GraphState, which does not have a .get() method.
The method would overwrite GraphState with a blank AgentState(), corrupting
the nested executor on every reset -- triggered by reset_on_revisit cycles
or deserialize_state after a completed run.

post_init already has the correct guard:
hasattr(self.executor.state, "get")
which resolves to True only for AgentState. The fix mirrors that same
guard in reset_executor_state(), making the two methods consistent.

Related Issues

Resolves #1775

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change?

  • 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.

…gentBase executors

reset_executor_state() checked hasattr(self.executor, "state") without
checking whether the state attribute is an AgentState. Graph (a MultiAgentBase)
has a .state attribute of type GraphState, which does not have a .get() method.
The method would overwrite GraphState with a blank AgentState(), corrupting
the nested executor on every reset (triggered by reset_on_revisit cycles or
deserialize_state after a completed run).

__post_init__ already has the correct guard:
  hasattr(self.executor.state, "get")
which resolves to True only for AgentState. The fix mirrors that same guard
in reset_executor_state(), making the two methods consistent.

Resolves strands-agents#1775
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