mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Clean up NullObservations from the stream (#6260)
This commit is contained in:
parent
e92e4a1cbc
commit
663e36109c
@ -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(
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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] = {}
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user