History microfixes (#4728)

This commit is contained in:
Engel Nyst 2024-11-04 16:37:22 +01:00 committed by GitHub
parent 250fcbe62c
commit 1638968509
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

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

View File

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