add error observations (#196)

This commit is contained in:
Robert Brennan
2024-03-26 11:43:59 -04:00
committed by GitHub
parent 4ee0ae9c4a
commit 9e924ab4b1
2 changed files with 25 additions and 7 deletions

View File

@@ -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

View File

@@ -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):
"""