π OpenHands: AI-Driven Development
Clean up NullObservations from the stream (#6260)
Engel Nyst663e36109c85
diff --git a/openhands/agenthub/dummy_agent/agent.py b/openhands/agenthub/dummy_agent/agent.pyindex f7a654bf75..b420a3d5d8 100644--- a/openhands/agenthub/dummy_agent/agent.py+++ b/openhands/agenthub/dummy_agent/agent.py@@ -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(diff --git a/openhands/core/cli.py b/openhands/core/cli.pyindex 1e31537155..34186cd5fc 100644--- a/openhands/core/cli.py+++ b/openhands/core/cli.py@@ -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))diff --git a/openhands/events/utils.py b/openhands/events/utils.pyindex bf710edcd7..cfc2dd804c 100644--- a/openhands/events/utils.py+++ b/openhands/events/utils.py@@ -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] = {}diff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex 983fc67fa8..8cdd17e18e 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -254,6 +254,9 @@ class Runtime(FileEditRuntimeMixin):# this might be unnecessary, since source should be set by the event stream when we're heresource = event.source if event.source else EventSource.AGENT+ if isinstance(observation, NullObservation):+ # don't add null observations to the event stream+ returnself.event_stream.add_event(observation, source) # type: ignore[arg-type]def clone_repo(