Explorar el Código

History microfixes (#4728)

Engel Nyst hace 1 año
padre
commit
1638968509
Se han modificado 2 ficheros con 13 adiciones y 3 borrados
  1. 11 3
      openhands/controller/agent_controller.py
  2. 2 0
      openhands/memory/history.py

+ 11 - 3
openhands/controller/agent_controller.py

@@ -509,6 +509,16 @@ class AgentController:
             # update iteration that shall be shared across agents
             self.state.iteration = self.delegate.state.iteration
 
+            # emit AgentDelegateObservation when the delegate terminates due to error
+            delegate_outputs = (
+                self.delegate.state.outputs if self.delegate.state else {}
+            )
+            content = (
+                f'{self.delegate.agent.name} encountered an error during execution.'
+            )
+            obs = AgentDelegateObservation(outputs=delegate_outputs, content=content)
+            self.event_stream.add_event(obs, EventSource.AGENT)
+
             # close the delegate upon error
             await self.delegate.close()
             self.delegate = None
@@ -534,9 +544,7 @@ class AgentController:
             content = (
                 f'{self.delegate.agent.name} finishes task with {formatted_output}'
             )
-            obs: Observation = AgentDelegateObservation(
-                outputs=outputs, content=content
-            )
+            obs = AgentDelegateObservation(outputs=outputs, content=content)
 
             # clean up delegate status
             self.delegate = None

+ 2 - 0
openhands/memory/history.py

@@ -12,6 +12,7 @@ from openhands.events.event import Event, EventSource
 from openhands.events.observation.agent import AgentStateChangedObservation
 from openhands.events.observation.delegate import AgentDelegateObservation
 from openhands.events.observation.empty import NullObservation
+from openhands.events.observation.error import FatalErrorObservation
 from openhands.events.observation.observation import Observation
 from openhands.events.serialization.event import event_to_dict
 from openhands.events.stream import EventStream
@@ -33,6 +34,7 @@ class ShortTermHistory(list[Event]):
         NullObservation,
         ChangeAgentStateAction,
         AgentStateChangedObservation,
+        FatalErrorObservation,
     )
 
     def __init__(self):