You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(email): POST /v1/email/query — the SSE agent loop on the sidecar (contract 2.4) #2016
Part of #2014 (Phase 0). The v2 keystone: the sidecar becomes a complete agent product — NL request in, the agent reasons and chains tools into multi-step workflows, typed SSE events out — instead of only a bag of fixed-function endpoints. Every front-door (UI, CLI, gaia api) then relays to this one loop.
Scope:
New POST /v1/email/query route running the agent loop with an SSE output handler + the translation layer from the /query spec issue; per-run_id state namespacing; POST /v1/email/query/{run_id}/cancel.
Acceptance:curl -N against a dev-mode sidecar streams the specced vocabulary end-to-end for a triage query; cancel stops tool execution between steps; an eval-harness scenario asserts the event sequence, not just a final string. Size: L. Deps: the /query spec issue.
Solid framing — one thing worth nailing down before implementation starts: most of this loop already exists on the sidecar today, so the real work is a deliberate promotion/redesign, not a greenfield route. The email agent already ships an SSE agent-loop endpoint with per-session state, a cancel route, and the exact SSEOutputHandler relay this issue describes. The new /v1/email/query should reuse that machinery; the genuinely new deltas are (1) the top-level path, (2) run_id namespacing instead of session_id, and (3) the /query-spec translation layer. Calling that out here keeps the implementer from standing up a parallel second loop.
The contract math checks out: SCHEMA_VERSION is currently 2.3, so an additive bump to 2.4 is correct.
🔍 Technical details
Existing agent loop (the thing to reuse, not reinvent) lives in hub/agents/python/email/gaia_agent_email/agent_routes.py:
POST /v1/email/agent/query (agent_routes.py:384) — already runs process_query on a worker thread with gaia.ui.sse_handler.SSEOutputHandler as agent.console, streaming thoughts/steps/tool-usage/permission-requests/run_complete. This is exactly the "SSE output handler + agent loop" in the scope.
POST /v1/email/agent/cancel (agent_routes.py:365), /session create/reset/delete, /session/{id}/history, memory toggle — the full session lifecycle.
The per-session run_lock (agent_routes.py:88, :404) already enforces one turn at a time with a 409, and has the careful lock-release-on-setup-failure guard the new route will also need.
Design questions the issue should pin down so the implementer doesn't guess:
run_id vs session_id. The issue asks for "per-run_id state namespacing" and /v1/email/query/{run_id}/cancel, but the current model is session-keyed with a session-scoped lock and history. Is /v1/email/query replacing /agent/query, sitting beside it, or is run_id a sub-identity within a session? The cancel-route shape (/{run_id}/cancel vs the current body-param /cancel) depends on that answer.
Doc surfaces (feat(agent-email): auto-reap sidecar on parent exit/crash (no manual wiring) #1841 rule). Per CLAUDE.md, the 2.4 bump must land together across openapi.email.json, specification.html, spec_html.py, SPEC.md, SKILL.md, README.md, and CHANGELOG.md — grep the old 2.3 claim across all of them, not just the contract module (contract.py:77).
Acceptance test. The "assert the event sequence, not just a final string" criterion maps cleanly onto the existing SSE handler — an eval scenario can collect the emitted event types off the stream and assert order/vocabulary. Worth referencing the existing /agent/query tests under hub/agents/python/email/tests/ as the starting harness.
Blocking dep to confirm before merge: the confirmation-event behavior hinges on epic decision D1 (per the issue). Until D1 is signed off, the safe interim is the specced final-refusal-pointing-at-the-fixed-function-route path — make sure that fallback is itself a loud, actionable final event, not a silent no-op.
For the epic-level run_id-vs-session_id and D1 confirmation-flow decisions, @kovtcharov-amd is the right person to sign off.
Activity
github-actions commentedon Jul 10, 2026
Solid framing — one thing worth nailing down before implementation starts: most of this loop already exists on the sidecar today, so the real work is a deliberate promotion/redesign, not a greenfield route. The email agent already ships an SSE agent-loop endpoint with per-session state, a cancel route, and the exact
SSEOutputHandlerrelay this issue describes. The new/v1/email/queryshould reuse that machinery; the genuinely new deltas are (1) the top-level path, (2)run_idnamespacing instead ofsession_id, and (3) the/query-spec translation layer. Calling that out here keeps the implementer from standing up a parallel second loop.The contract math checks out:
SCHEMA_VERSIONis currently2.3, so an additive bump to2.4is correct.🔍 Technical details
Existing agent loop (the thing to reuse, not reinvent) lives in
hub/agents/python/email/gaia_agent_email/agent_routes.py:POST /v1/email/agent/query(agent_routes.py:384) — already runsprocess_queryon a worker thread withgaia.ui.sse_handler.SSEOutputHandlerasagent.console, streaming thoughts/steps/tool-usage/permission-requests/run_complete. This is exactly the "SSE output handler + agent loop" in the scope.POST /v1/email/agent/cancel(agent_routes.py:365),/sessioncreate/reset/delete,/session/{id}/history, memory toggle — the full session lifecycle.run_lock(agent_routes.py:88,:404) already enforces one turn at a time with a 409, and has the careful lock-release-on-setup-failure guard the new route will also need.Design questions the issue should pin down so the implementer doesn't guess:
run_idvssession_id. The issue asks for "per-run_idstate namespacing" and/v1/email/query/{run_id}/cancel, but the current model is session-keyed with a session-scoped lock and history. Is/v1/email/queryreplacing/agent/query, sitting beside it, or isrun_ida sub-identity within a session? The cancel-route shape (/{run_id}/cancelvs the current body-param/cancel) depends on that answer.openapi.email.json,specification.html,spec_html.py,SPEC.md,SKILL.md,README.md, andCHANGELOG.md— grep the old2.3claim across all of them, not just the contract module (contract.py:77).types off the stream and assert order/vocabulary. Worth referencing the existing/agent/querytests underhub/agents/python/email/tests/as the starting harness.Blocking dep to confirm before merge: the confirmation-event behavior hinges on epic decision D1 (per the issue). Until D1 is signed off, the safe interim is the specced
final-refusal-pointing-at-the-fixed-function-route path — make sure that fallback is itself a loud, actionablefinalevent, not a silent no-op.For the epic-level
run_id-vs-session_idand D1 confirmation-flow decisions, @kovtcharov-amd is the right person to sign off.test(email): reconcile capability matrix + contract version with /que…
feat(email): POST /v1/email/query — the SSE agent loop on the sidecar…
docs(spec): freeze the /query SSE event contract + vocabulary transla…