Skip to content

Commit 845d5dd

Browse files
committed
feat: add agent history file to org agents
1 parent 4b64685 commit 845d5dd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

webui.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def run_browser_agent(
131131
api_key=llm_api_key,
132132
)
133133
if agent_type == "org":
134-
final_result, errors, model_actions, model_thoughts, trace_file = await run_org_agent(
134+
final_result, errors, model_actions, model_thoughts, trace_file, history_file = await run_org_agent(
135135
llm=llm,
136136
use_own_browser=use_own_browser,
137137
keep_browser_open=keep_browser_open,
@@ -140,6 +140,7 @@ async def run_browser_agent(
140140
window_w=window_w,
141141
window_h=window_h,
142142
save_recording_path=save_recording_path,
143+
save_agent_history_path=save_agent_history_path,
143144
save_trace_path=save_trace_path,
144145
task=task,
145146
max_steps=max_steps,
@@ -201,8 +202,8 @@ async def run_browser_agent(
201202
'', # model_actions
202203
'', # model_thoughts
203204
None, # latest_video
204-
None, # trace_file
205205
None, # history_file
206+
None, # trace_file
206207
gr.update(value="Stop", interactive=True), # Re-enable stop button
207208
gr.update(value="Run", interactive=True) # Re-enable run button
208209
)
@@ -217,6 +218,7 @@ async def run_org_agent(
217218
window_w,
218219
window_h,
219220
save_recording_path,
221+
save_agent_history_path,
220222
save_trace_path,
221223
task,
222224
max_steps,
@@ -270,14 +272,17 @@ async def run_org_agent(
270272
)
271273
history = await agent.run(max_steps=max_steps)
272274

275+
history_file = os.path.join(save_agent_history_path, f"{agent.agent_id}.json")
276+
agent.save_history(history_file)
277+
273278
final_result = history.final_result()
274279
errors = history.errors()
275280
model_actions = history.model_actions()
276281
model_thoughts = history.model_thoughts()
277-
282+
278283
trace_file = get_latest_files(save_trace_path)
279-
280-
return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip')
284+
285+
return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip'), history_file
281286
except Exception as e:
282287
import traceback
283288
traceback.print_exc()
@@ -381,7 +386,7 @@ async def run_custom_agent(
381386
import traceback
382387
traceback.print_exc()
383388
errors = str(e) + "\n" + traceback.format_exc()
384-
return '', errors, '', '', None
389+
return '', errors, '', '', None, None
385390
finally:
386391
# Handle cleanup based on persistence configuration
387392
if not keep_browser_open:

0 commit comments

Comments
 (0)