Add run_context to agent tool calls for FE run logging

- AgentTriggerRequest accepts optional agent_id (FE's stable electron-store UUID)
- _make_agent_executor injects run_context into every tool_call frame
  so Electron can attribute actions to the correct agent run
- run_local_agent accepts run_context and sends a run_complete WS frame
  when the run finishes so the FE can close the run record
- trigger_agent_run builds run_context with run_id=run_log.id and the
  stable agent_id, passes it through to run_local_agent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Roberto Musso
2026-03-20 09:46:17 +01:00
parent 297e20ce8d
commit 725cece5c1
3 changed files with 32 additions and 3 deletions

View File

@@ -190,8 +190,11 @@ async def trigger_agent_run(
enabled=True,
)
# Use the FE's stable agent_id if provided, fall back to the ephemeral config id.
stable_agent_id = body.agent_id or config.id
run_log = AgentRunLog(
agent_id=config.id,
agent_id=stable_agent_id,
agent_type="local",
user_id=current_user.id,
status="running",
@@ -200,8 +203,14 @@ async def trigger_agent_run(
await db.commit()
await db.refresh(run_log)
run_context = {
"type": "agent_batch",
"run_id": run_log.id,
"agent_id": stable_agent_id,
}
asyncio.create_task(
run_local_agent(current_user.id, config, run_log, device_manager)
run_local_agent(current_user.id, config, run_log, device_manager, run_context)
)
return _to_run_log_response(run_log)