Save complete trajectory in presence of history truncation (#6751)

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
Boxuan Li
2025-02-21 00:14:30 -08:00
committed by GitHub
parent d33913e036
commit fab4532f6b
3 changed files with 77 additions and 21 deletions

View File

@@ -27,7 +27,6 @@ from openhands.events.action.action import Action
from openhands.events.event import Event
from openhands.events.observation import AgentStateChangedObservation
from openhands.events.serialization import event_from_dict
from openhands.events.serialization.event import event_to_trajectory
from openhands.io import read_input, read_task
from openhands.runtime.base import Runtime
@@ -167,6 +166,8 @@ async def run_controller(
# NOTE: the saved state does not include delegates events
end_state.save_to_session(event_stream.sid, event_stream.file_store)
await controller.close(set_stop_state=False)
state = controller.get_state()
# save trajectories if applicable
@@ -177,7 +178,7 @@ async def run_controller(
else:
file_path = config.save_trajectory_path
os.makedirs(os.path.dirname(file_path), exist_ok=True)
histories = [event_to_trajectory(event) for event in state.history]
histories = controller.get_trajectory()
with open(file_path, 'w') as f:
json.dump(histories, f)