Clean up NullObservations from the stream (#6260)

This commit is contained in:
Engel Nyst 2025-02-19 20:40:40 +01:00 committed by GitHub
parent e92e4a1cbc
commit 663e36109c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 17 deletions

View File

@ -22,7 +22,6 @@ from openhands.events.observation import (
CmdOutputObservation,
FileReadObservation,
FileWriteObservation,
NullObservation,
Observation,
)
from openhands.events.serialization.event import event_to_dict
@ -109,7 +108,7 @@ class DummyAgent(Agent):
},
{
'action': AgentRejectAction(),
'observations': [NullObservation('')],
'observations': [AgentStateChangedObservation('', AgentState.REJECTED)],
},
{
'action': AgentFinishAction(

View File

@ -29,7 +29,6 @@ from openhands.events.observation import (
AgentStateChangedObservation,
CmdOutputObservation,
FileEditObservation,
NullObservation,
)
@ -143,19 +142,18 @@ async def main(loop: asyncio.AbstractEventLoop):
AgentState.FINISHED,
]:
await prompt_for_next_task()
if (
isinstance(event, NullObservation)
and controller.state.agent_state == AgentState.AWAITING_USER_CONFIRMATION
):
user_confirmed = await prompt_for_user_confirmation()
if user_confirmed:
event_stream.add_event(
ChangeAgentStateAction(AgentState.USER_CONFIRMED), EventSource.USER
)
else:
event_stream.add_event(
ChangeAgentStateAction(AgentState.USER_REJECTED), EventSource.USER
)
if event.agent_state == AgentState.AWAITING_USER_CONFIRMATION:
user_confirmed = await prompt_for_user_confirmation()
if user_confirmed:
event_stream.add_event(
ChangeAgentStateAction(AgentState.USER_CONFIRMED),
EventSource.USER,
)
else:
event_stream.add_event(
ChangeAgentStateAction(AgentState.USER_REJECTED),
EventSource.USER,
)
def on_event(event: Event) -> None:
loop.create_task(on_event_async(event))

View File

@ -10,7 +10,9 @@ from openhands.events.observation import (
def get_pairs_from_events(events: list[Event]) -> list[tuple[Action, Observation]]:
"""Return the history as a list of tuples (action, observation)."""
"""Return the history as a list of tuples (action, observation).
This function is a compatibility function for evals reading and visualization working with old histories."""
tuples: list[tuple[Action, Observation]] = []
action_map: dict[int, Action] = {}
observation_map: dict[int, Observation] = {}

View File

@ -254,6 +254,9 @@ class Runtime(FileEditRuntimeMixin):
# this might be unnecessary, since source should be set by the event stream when we're here
source = event.source if event.source else EventSource.AGENT
if isinstance(observation, NullObservation):
# don't add null observations to the event stream
return
self.event_stream.add_event(observation, source) # type: ignore[arg-type]
def clone_repo(