mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
Reset a failed tool call (#5666)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -335,6 +335,28 @@ class AgentController:
|
||||
def _reset(self) -> None:
|
||||
"""Resets the agent controller"""
|
||||
|
||||
# make sure there is an Observation with the tool call metadata to be recognized by the agent
|
||||
# otherwise the pending action is found in history, but it's incomplete without an obs with tool result
|
||||
if self._pending_action and hasattr(self._pending_action, 'tool_call_metadata'):
|
||||
# find out if there already is an observation with the same tool call metadata
|
||||
found_observation = False
|
||||
for event in self.state.history:
|
||||
if (
|
||||
isinstance(event, Observation)
|
||||
and event.tool_call_metadata
|
||||
== self._pending_action.tool_call_metadata
|
||||
):
|
||||
found_observation = True
|
||||
break
|
||||
|
||||
# make a new ErrorObservation with the tool call metadata
|
||||
if not found_observation:
|
||||
obs = ErrorObservation(content='The action has not been executed.')
|
||||
obs.tool_call_metadata = self._pending_action.tool_call_metadata
|
||||
obs._cause = self._pending_action.id # type: ignore[attr-defined]
|
||||
self.event_stream.add_event(obs, EventSource.AGENT)
|
||||
|
||||
# reset the pending action, this will be called when the agent is STOPPED or ERROR
|
||||
self._pending_action = None
|
||||
self.agent.reset()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user