From 88dbe85594fb285a74f77658664d9162cd0093ac Mon Sep 17 00:00:00 2001 From: Boxuan Li Date: Thu, 7 Nov 2024 22:26:12 -0800 Subject: [PATCH] Make trajectories_path support file path (#4840) --- config.template.toml | 3 ++- openhands/core/main.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config.template.toml b/config.template.toml index 060ec11ab1eb..d19ff6085e3b 100644 --- a/config.template.toml +++ b/config.template.toml @@ -32,7 +32,8 @@ workspace_base = "./workspace" # Enable saving and restoring the session when run from CLI #enable_cli_session = false -# Path to store trajectories +# Path to store trajectories, can be a folder or a file +# If it's a folder, the session id will be used as the file name #trajectories_path="./trajectories" # File store path diff --git a/openhands/core/main.py b/openhands/core/main.py index 009d1607715b..4b3bce90ce62 100644 --- a/openhands/core/main.py +++ b/openhands/core/main.py @@ -212,7 +212,11 @@ async def on_event(event: Event): # save trajectories if applicable if config.trajectories_path is not None: - file_path = os.path.join(config.trajectories_path, sid + '.json') + # if trajectories_path is a folder, use session id as file name + if os.path.isdir(config.trajectories_path): + file_path = os.path.join(config.trajectories_path, sid + '.json') + else: + file_path = config.trajectories_path os.makedirs(os.path.dirname(file_path), exist_ok=True) histories = [event_to_trajectory(event) for event in state.history] with open(file_path, 'w') as f: