Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up NullObservations from the stream #6260

Merged
merged 9 commits into from
Feb 19, 2025
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
Loading