diff --git a/openhands/agenthub/dummy_agent/agent.py b/openhands/agenthub/dummy_agent/agent.py index f7a654bf75b4..b420a3d5d8ae 100644 --- a/openhands/agenthub/dummy_agent/agent.py +++ b/openhands/agenthub/dummy_agent/agent.py @@ -22,7 +22,6 @@ CmdOutputObservation, FileReadObservation, FileWriteObservation, - NullObservation, Observation, ) from openhands.events.serialization.event import event_to_dict @@ -109,7 +108,7 @@ def __init__(self, llm: LLM, config: AgentConfig): }, { 'action': AgentRejectAction(), - 'observations': [NullObservation('')], + 'observations': [AgentStateChangedObservation('', AgentState.REJECTED)], }, { 'action': AgentFinishAction( diff --git a/openhands/core/cli.py b/openhands/core/cli.py index 1e31537155ac..34186cd5fc8a 100644 --- a/openhands/core/cli.py +++ b/openhands/core/cli.py @@ -29,7 +29,6 @@ AgentStateChangedObservation, CmdOutputObservation, FileEditObservation, - NullObservation, ) @@ -143,19 +142,18 @@ async def on_event_async(event: Event): 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.py index bf710edcd7bd..cfc2dd804c3a 100644 --- a/openhands/events/utils.py +++ b/openhands/events/utils.py @@ -10,7 +10,9 @@ 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.py index 983fc67fa898..8cdd17e18ead 100644 --- a/openhands/runtime/base.py +++ b/openhands/runtime/base.py @@ -254,6 +254,9 @@ async def _handle_action(self, event: Action) -> None: # 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(