Skip to content

πŸ™Œ OpenHands: AI-Driven Development

add error observations (#196)

Robert Brennan9e924ab4b1f0
diff --git a/opendevin/controller/__init__.py b/opendevin/controller/__init__.py
index 62b3cb9337..3570d63ee5 100644
--- a/opendevin/controller/__init__.py
+++ b/opendevin/controller/__init__.py
@@ -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
diff --git a/opendevin/observation.py b/opendevin/observation.py
index 408099453b..0e8c77a804 100644
--- a/opendevin/observation.py
+++ b/opendevin/observation.py
@@ -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):
"""