Hello, is there a way, or do you think it would be...
# questions
f
Hello, is there a way, or do you think it would be easy to implement, a mechanism that saves the Docker environment after each action taken by the agent (kind of snapshots)? I’m trying to study the impact of single actions along a trajectory and I would like to be able to re-run specific steps, from specific points
l
There is a way to save docker states, but you might also consider using the replay manager: https://github.com/All-Hands-AI/OpenHands/blob/06ad5e30c936f2339ea50e80b679372cf7018779/openhands/controller/replay.py#L11 This allows you to run through previous trajectories.
p
f
thanks!
c
You can also set up
mitmproxy
in reverse proxy mode between open hands and your LLM and record the entire conversation. I think it allows you to step through it too: https://mitmproxy.org/
f
@limited-student-10747 Why is there an assert isinstance(initial_user_action, NullAction) in openhands.core.main when the replay_trajectory_path is passed? I am not sure I understand this... initial_user_action would be my MessageAction
l
I think the first action in the related trajectory should be the message probably
f
ah ok I see, I think it has changed in the last versions of iterations of OpenHands, Thanks!
l
I'm not 100% sure, please tell me if that's off!
f
Ok I have changed the code in this way:
if cfg.replay_trajectory_path:
initial_user_action = NullAction()
else:
initial_user_action = MessageAction(content=instruction)
And it's ok now. However I have another issue 😄, when loading the trajectory my first message is a SystemMessageAction, but there is an assertion stating that the first message should be a MessageAction (in the load_replay_log function). Why do you require a MessageAction and a SystemMessageAction is not good enough? My gut feeling is that SystemMessageAction should inherit from MessageAction rather than Action... but I don't know the codebase well enough to understand what this change would entail
@limited-student-10747 alright I made this change and it seems to be working now... I don't know about side effects though
Additionally I also noticed that it would be more convenient in the load_replay_log to have something as this:
def load_replay_log(trajectory_path: str) -> tuple[list[Event] | None, Action]:
"""
Load trajectory from given path, serialize it to a list of events, and return
two things:
1) A list of events except the first action
2) First action (user message, a.k.a. initial task)
"""
try:
path = Path(trajectory_path).resolve()
if not path.exists():
raise ValueError(f'Trajectory file not found: {path}')
if not path.is_file():
raise ValueError(f'Trajectory path is a directory, not a file: {path}')
with open(path, 'r', encoding='utf-8') as file:
output_saved = json.load(file)
trajectory = output_saved['history']
events = ReplayManager.get_replay_events(trajectory)
assert isinstance(events[0], MessageAction)
return events[1:], events[0]
except json.JSONDecodeError as e:
raise ValueError(f'Invalid JSON format in {trajectory_path}: {e}')
Rather than events =
ReplayManager.get_replay_events(json.load(file))
in such a way you can directly feed the output.json (the same used in the trajectory visualizer) to the load replay function. Let me know what you think, I can create a pull request in case in case you think it's useful
f
@limited-student-10747 Thanks for pointing us to the replay feature. I was testing it and noticed that the first action after the replay trajectory does not seem to be based on the last action of the replay. Inspecting
action = self._replay_manager.step()
https://github.com/All-Hands-AI/OpenHands/blob/a32a6230782be168002cc4050efa71c9aabccc9c/openhands/controller/agent_controller.py#L810 shows that the first message does not include the replay trajectory. Does this mean that the replay is not passed into the model? Thx!