mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
add error observations (#196)
This commit is contained in:
@@ -13,6 +13,7 @@ from opendevin.action import (
|
||||
)
|
||||
from opendevin.observation import (
|
||||
Observation,
|
||||
AgentErrorObservation,
|
||||
NullObservation
|
||||
)
|
||||
|
||||
@@ -78,9 +79,16 @@ class AgentController:
|
||||
print_with_indent("\nBACKGROUND LOG:\n%s" % obs)
|
||||
|
||||
state: State = self.get_current_state()
|
||||
action: Action = self.agent.step(state)
|
||||
action: Action = NullAction()
|
||||
observation: Observation = NullObservation("")
|
||||
try:
|
||||
action = self.agent.step(state)
|
||||
print_with_indent("\nACTION:\n%s" % action)
|
||||
except Exception as e:
|
||||
observation = AgentErrorObservation(str(e))
|
||||
print_with_indent("\nAGENT ERROR:\n%s" % observation)
|
||||
traceback.print_exc()
|
||||
|
||||
print_with_indent("\nACTION:\n%s" % action)
|
||||
await self._run_callbacks(action)
|
||||
|
||||
if isinstance(action, AgentFinishAction):
|
||||
@@ -93,14 +101,14 @@ class AgentController:
|
||||
action = action_cls(**_kwargs)
|
||||
print(action, flush=True)
|
||||
if action.executable:
|
||||
observation: Observation = action.run(self)
|
||||
else:
|
||||
observation = NullObservation("")
|
||||
print_with_indent("\nOBSERVATION:\n%s" % observation)
|
||||
observation = action.run(self)
|
||||
|
||||
if not isinstance(observation, NullObservation):
|
||||
print_with_indent("\nOBSERVATION:\n%s" % observation)
|
||||
|
||||
self.add_history(action, observation)
|
||||
await self._run_callbacks(observation)
|
||||
|
||||
|
||||
async def _run_callbacks(self, event):
|
||||
if event is None:
|
||||
return
|
||||
|
||||
@@ -105,6 +105,16 @@ class AgentRecallObservation(Observation):
|
||||
return "The agent recalled memories."
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentErrorObservation(Observation):
|
||||
"""
|
||||
This data class represents an error encountered by the agent.
|
||||
"""
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
return "Oops. Something went wrong: " + self.content
|
||||
|
||||
@dataclass
|
||||
class NullObservation(Observation):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user