Skip to content

Commit

Permalink
Clean up NullObservations from the stream (#6260)
Browse files Browse the repository at this point in the history
  • Loading branch information
enyst authored Feb 19, 2025
1 parent e92e4a1 commit 663e361
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions openhands/agenthub/dummy_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
CmdOutputObservation,
FileReadObservation,
FileWriteObservation,
NullObservation,
Observation,
)
from openhands.events.serialization.event import event_to_dict
Expand Down Expand Up @@ -109,7 +108,7 @@ def __init__(self, llm: LLM, config: AgentConfig):
},
{
'action': AgentRejectAction(),
'observations': [NullObservation('')],
'observations': [AgentStateChangedObservation('', AgentState.REJECTED)],
},
{
'action': AgentFinishAction(
Expand Down
26 changes: 12 additions & 14 deletions openhands/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
AgentStateChangedObservation,
CmdOutputObservation,
FileEditObservation,
NullObservation,
)


Expand Down Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion openhands/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
3 changes: 3 additions & 0 deletions openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 663e361

Please sign in to comment.