Skip to content

feat(email): POST /v1/email/query — the SSE agent loop on the sidecar (contract 2.4) #2016

Closed

Description

@kovtcharov

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:

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.

Activity

  1. added
    enhancement
    agent::email
    on Jul 10, 2026
  2. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    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:

    1. 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.
    2. 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).
    3. 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.

  3. added 2 commits that reference this issue on Jul 14, 2026
    e35e138
    b5e5ef4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent::emailenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions