Repository navigation
docs(plans): email agent in the Agent UI — frozen sidecar + user/dev modes - #1882
Conversation
Plan for triaging personal Gmail through the Agent UI with two interchangeable sidecar backends behind one fixed REST seam: a frozen npm binary for users and a hot-reloading uvicorn-from-source server for developers. Both run the same agent code against the same local Google grant, so personal email works identically in each and improving the agent is a one-file edit with no freeze/publish/patch loop.
|
Verdict: Approve ✅ This is a docs-only PR adding one design plan for running the email agent inside the Agent UI as an out-of-process sidecar, with a user mode (frozen npm binary) and a dev mode ( 🔍 Technical detailsClaims verified against the tree (all accurate):
🟢 Minor — "existing UI services" overstates the renderer side ( Strengths:
|
The first draft assumed the renderer calls a fixed /v1/email REST URL and that an Electron-main sidecar manager would host it. Code review found the UI surfaces email through the chat agent loop + SSE cards (the frontend has no email REST client), and the agent already runs in-process in the Python backend reading ~/.gaia/connectors/grants.json. Reframe: the seam is the chat agent's email-tool layer and the host is the Python UI backend (no Node backend needed). Both modes proxy over the same HTTP path to a sidecar on :8131 — frozen binary for users, uvicorn --reload from source for devs — keeping process isolation identical across modes and preserving the existing SSE card pipeline.
Fold in the two product requirements and resolve every open item from the architecture review: - Dogfooding: user mode runs the exact Hub-published frozen binary (pinned via binaries.lock.json), so the Agent UI validates the shipped product. This is the rationale the sidecar earns over an editable in-process install. - Lightweight UI: the sidecar is lazy-fetched on first email use, one platform binary only; core ships no email deps. - Resolve open questions: use a proxy AGENT reusing agent_type=email machinery; remove the redundant in-process /v1/email mount (#1768) so the UI has one backend. - Review fixes: own the dev-mode enabler (module-level app = build_app()), reuse the npm fetch SHA/lock integrity check instead of porting it to Python, ephemeral per-instance port (no fixed-8131 multi-instance clash), single-writer grant model (OAuth stays on backend; sidecar reads only), exact current-contract table. - Sequence behind the in-flight REST build-out (pre-scan + #1779/#1780/#1781) and flag the #1767 in-process decision must be superseded with @itomek sign-off.
…tion) itomek closed #1767/#1785 because mixing an npm package requiring Node.js into the Python-backed Agent UI is too dirty. Remove that entirely: the Python backend fetches the binary itself (verified SHA-256 download, no npx), spawns it, and proxies over HTTP. No Node runtime, no npm package in the UI's path. The npm package remains the external Node-integrator channel only.
Before: the Agent UI could only run the email agent in-process, importing the heavy email deps into core — the exact Node-free objection that closed epic #1767. After: the Python backend runs the email agent as an out-of-process **sidecar** it fetches (verified), spawns, health-checks, proxies to, and tree-kills directly — no Node.js, no npm on the runtime path. User mode runs the published frozen binary (SHA-256 verified against `binaries.lock.json`); dev mode runs the same REST contract from local source with hot reload, so prompt/tool edits show up live without a freeze → publish loop. This is **additive and gated** behind `GAIA_EMAIL_AGENT_MODE` (`user` default / `dev`): the existing in-process path is untouched until the supersede decision (#1767) lands, so nothing breaks today. Routes that don't exist yet (inbox pre-scan, search #1781, archive/quarantine #1779, calendar #1780) are gated in the proxy with a loud, issue-named error — never silently faked. Implements the approved design in `docs/plans/email-sidecar-agent-ui.md` (#1882); step-by-step plan + hardening addendum in `docs/plans/email-sidecar-agent-ui-implementation.md`. > **Depends on #1882** (the design doc). This branch builds on those plan commits; > they'll resolve once #1882 merges. ### What's complete (this PR) A bulletproof, fully-tested standalone sidecar capability ready to wire: - **Verified fetch** — SHA-256 gate (tamper → refuse), `~/.gaia/agents/email/` cache, placeholder-refuse, atomic write. - **Lifecycle** — ephemeral port (never 4001), spawn (user binary / dev `uvicorn server:app --app-dir …`), health-poll with **service-identity** check, process-group tree-kill, `atexit` orphan reaping, **port-race retry**, concurrency lock (one sidecar under concurrent first-use), `/version` contract handshake. - **Proxy** — forwards triage/draft/send/health/version unchanged; preserves the sidecar's actionable error detail via `SidecarHTTPError`; gates the not-yet-built routes. - **No pipe deadlock** — sidecar output goes to a pruned per-port log file, not an undrained PIPE. - **Integration seam** — `EmailSidecarManager.proxy()` + context-manager lifecycle. ### One design correction (verified live) The design's `uvicorn packaging.server:app` does not resolve — the email package's `packaging/` dir collides with the PyPI `packaging` library, and adding `packaging/__init__.py` would shadow `packaging.version` for every dependency. Dev mode instead loads the file as the top-level module `server` via `uvicorn server:app --app-dir hub/agents/python/email/packaging`. ## Test plan - [x] `python -m pytest tests/unit/test_email_sidecar_*.py` — 58 tests, incl. **live dev-mode spawn/health/tree-kill** and a **live real-LLM triage round-trip** through the manager-owned proxy against the frozen contract (skips cleanly without the email wheel / Lemonade). - [x] `python -m pytest tests/unit/agents/email/test_connector_routes.py` — no regression from the new module-level `app`. - [x] `python util/lint.py --all` — passes. - [x] Manual dev mode: `uv pip install -e hub/agents/python/email` then `GAIA_EMAIL_AGENT_MODE=dev gaia chat --ui`. ## Gated / deferred (by design) - Not wired into live `agent_type=email` sessions; in-process `/v1/email` mount kept — until @itomek/maintainer sign-off on superseding #1767. - Inbox pre-scan / search (#1781) / archive-quarantine (#1779) / calendar (#1780) REST routes are owned by other tasks; this PR only consumes/gates them. - User-mode binary fetch refuses loudly while `binaries.lock.json` carries `PENDING` SHAs; the cold-start keyring + dogfood checks unlock once the publish pipeline populates real SHAs. --------- Co-authored-by: Tomasz Iniewicz <[email protected]> Co-authored-by: Tomasz Iniewicz <[email protected]>
…cess /v1/email) (amd#1910) ## Why this matters Before this PR the Agent UI's email surface was split and the heavy email agent ran inside the UI process: the `/v1/email/*` REST routes were served by an **in-process mount of the email wheel by default** (only by the sidecar when `GAIA_EMAIL_AGENT_MODE` was set), and the in-app email chat agent (`agent_type=email`) loaded live Gmail/Outlook backends, an action DB, and a memory store **into the UI backend**. After this PR the out-of-process **sidecar is the sole, default backend for both surfaces**. The core UI backend no longer imports the email wheel — it stays lightweight, crash-isolated, and **dogfoods the exact schema-2.1 product third-party integrators consume**. This is the deferred cutover from epic amd#1767, on the foundations from amd#1884 and the now-complete REST 2.1 contract from amd#1883 (design: amd#1882). ### What changed (three threads a reviewer should evaluate independently) - **Proxy ungated → full contract.** `EmailSidecarProxy` now forwards the full schema-2.1 surface (prescan, search, archive/unarchive, quarantine/unquarantine, confirm, batch triage, calendar view/preview/create/respond) returning the sidecar's envelopes unchanged. The UI router exposes the full contract, so removing the in-process mount does **not** shrink the external `/v1/email` surface. - **Sidecar is the sole + default `/v1/email` surface.** The in-process `gaia_agent_email.api_routes` mount is removed from the UI server; unset `GAIA_EMAIL_AGENT_MODE` now defaults to **user mode** (frozen binary, lazy-fetched + SHA-verified). No in-process fallback — a missing/unpublished binary fails loudly with a remedy. (The separate `gaia api` / `openai_server` mount is intentionally out of scope.) - **`agent_type=email` flipped to the sidecar.** New `EmailProxyAgent` keeps the local-LLM tool loop in the UI backend, but every tool is a thin HTTP call to the sidecar. `pre_scan_inbox` returns the **identical** `email_pre_scan` envelope so the triage card renders unchanged. Its tool surface is the subset the REST contract serves today (inbox pre-scan, search, calendar view, archive + undo); the unmapped in-process tools (labels/stars/move/trash/delete/summarize/profile/preferences/forward/send) are not exposed in chat until their REST routes land — the agent product still implements them, they're just not reachable over the contract yet. ## Test plan - [x] `python -m pytest tests/unit/test_email_sidecar_*.py` — 91 pass (proxy, router, server-wiring, manager, fetch, platform, devmode-app, **new** proxy-agent). - [x] `python util/lint.py --black --isort --flake8` — all pass. - [x] Chat-path regression: `pytest tests/unit/test_session_mail_provider.py tests/unit/test_agents_split.py tests/unit/test_chat_preflight.py tests/unit/chat/ui/test_server.py` — 141 pass. - [x] **End-to-end card property (no Gmail):** the proxy agent's real `pre_scan_inbox` output, fed through the real `SSEOutputHandler`, injects an `email_pre_scan` render payload (test `test_pre_scan_envelope_triggers_real_sse_card_injection`). - [x] **Live dev-mode round-trip:** spawned the dev sidecar (`apiVersion=2.1 agentVersion=0.3.0`), drove the proxy agent's real `pre_scan_inbox`/`search_messages` tools against live `/prescan` and `/search`; with no mailbox connected they fail loudly with the sidecar's verbatim "No mailbox connected…" detail (full chain: proxy agent → shared manager → sidecar → REST → fail-loud passthrough). Clean tree-kill on shutdown. - [x] `create_app()` with `GAIA_EMAIL_AGENT_MODE` unset → manager mode `user`, full contract routes mounted, no in-process mount. To exercise locally with a connected Gmail: ```bash uv pip install -e hub/agents/python/email GAIA_EMAIL_AGENT_MODE=dev gaia chat --ui # email session → "what's in my inbox" → pre-scan card via the sidecar ``` ### Notes for the reviewer - **Eval:** no `gaia eval agent` run — the change touches neither the in-core ChatAgent prompts nor the wheel's `EmailTriageAgent`; the eval harness targets the wheel agent (unchanged), and there is no eval path for the new `EmailProxyAgent`. Its behavior is covered by the integration + live tests above. - **Reduced chat tool surface** is a deliberate, maintainer-approved product decision (sidecar-mapped tools only) — backwards compat for *other* Agent-UI agents (chat/code/browser/…) is untouched. - **Follow-up:** the registry gate still requires the email wheel for the `email` id to resolve, so a no-wheel install can use the REST surface but not the chat agent. Decoupling that (registering proxy-agent metadata without the wheel) is a separate change.
Why this matters
Improving the email agent and getting the fix into the Agent UI today means a freeze → `npm publish` → version-bump → re-integrate loop — slow, and a wall of patches just to test a change. This plan removes that loop and lets the UI triage personal Gmail through two modes over one shared REST contract:
Both read the same `~/.gaia` Google grant, so personal Gmail works identically in each; the mode only swaps which process answers the calls.
This PR is docs-only — the implementation plan, for review before any code lands. It went through an independent architecture review and was corrected twice: the original draft wrongly assumed the renderer calls a REST sidecar (it's actually chat-loop + SSE cards, in-process today), and it has to be sequenced behind the in-flight REST capability build-out (inbox pre-scan + #1779/#1780/#1781) since the sidecar contract is triage/draft/send-only right now.
Decision needed before build
This pivots from epic #1767's in-process-mount decision (whose capstone PR #1785 was closed unmerged 2026-06-26). Needs maintainer + @itomek sign-off to supersede it, plus confirmation to remove the redundant in-process `/v1/email` mount (#1768).
Test plan