Skip to content

feat(email): flagship reads threads and finds mail waiting on you - #6124

Merged
kovtcharov-amd merged 6 commits into
mainfrom
kalin/mail-parity-1
Oct 30, 2026
Merged

kovtcharov-amd merged 6 commits into
mainfrom
kalin/mail-parity-1

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The flagship could list, search and open single emails, but it could not read a whole conversation, say which mailbox it was reading, or find the threads where the user owes a reply. The email agent can do all three, and it can't be retired until the flagship can too. After this PR the flagship has all three for Gmail and Outlook, still read-only. A host app that forwards a read-only Gmail connection is also no longer rejected: GAIA used to require the email agent's modify and send scopes, which the flagship never holds.

This is stage 1 of mail parity. The email agent stays in place.

  • New tools: get_thread returns a whole conversation, clipping long bodies so no message is dropped. list_waiting_on_you uses the email agent's detector, ported with its precision checks and passing the same 104-row promotional corpus with zero false positives. list_connected_mailboxes reports connection state without a network call.
  • Eval harnesses: the shared harnesses now measure GaiaAgent. Retrieval results can't change, because GaiaAgent inherits the same search-key function. python -m gaia.eval.tool_cost now reports on the flagship. The old ChatAgent doc-profile numbers (Tool loader — Part 0: measure tool-prompt cost & TTFT baseline #1448) are still reproducible with --agent chat --profile doc. Neither harness needs a new baseline.

Evals to run on the Strix Halo pool (LLM-affecting: three new tools, changed tool docstrings, updated skill): gaia_email, gaia_tool_selection, tool_selection. The scenario baseline needs a new capture only if one of those categories changes on purpose. The gaia_email fixture mailbox has no sent mail, so no current scenario can produce a positive waiting-on-you result. Adding a scenario for it is a follow-up.

Test plan

  • python -m pytest tests/unit/agents/tools/test_email_thread_tools.py tests/unit/agents/tools/test_email_waiting_on_you.py -q. Gmail and Graph request shapes (paths, $filter with no $orderby, label ids), tool behaviour, the corpus precision checks, and the tests that try to fake reply history
  • python -m pytest tests/unit/connectors/test_forwarded_import.py tests/unit/connectors/test_formatting.py -q. A read-only forwarded connection is accepted, and the error never asks for more than read access
  • python -m pytest tests/unit/eval/test_harness_flagship_target.py hub/agents/gaia/python/tests -q
  • python -m gaia.eval.tool_cost reports "gaia agent, full", and --agent chat --profile doc reproduces the old report
  • Dispatch eval_flagship.yml for gaia_email, gaia_tool_selection, tool_selection and compare against tests/fixtures/eval_baselines/gaia-flagship/

The flagship could list, search and open single messages but not read a
whole conversation, say which mailbox it was on, or find the threads where
the user owes a reply - three things the email agent does and the first
gap to close before that agent can be retired.

- get_thread, list_connected_mailboxes and list_waiting_on_you join the
  read-only mail tools (a new email_threads loader bundle), for Gmail
  and Outlook through the existing backends. The waiting-on-you detector
  is ported from the email agent (same predicates, same corpus precision
  gate) rather than imported.
- A forwarded connection with no explicit required scopes now needs any
  one mail read scope instead of gmail.modify + gmail.send, which the
  read-only flagship never holds.
- The retrieval and tool-cost eval harnesses measure GaiaAgent; the
  ChatAgent doc-profile report stays reachable with --agent chat.
- inbox-triage skill, email/gaia guides, connectors SDK doc, flagship
  README/SPEC/SKILL/CHANGELOG and the capability matrix updated; the
  registered tool count is 101.
@github-actions github-actions Bot added documentation Documentation changes eval Evaluation framework changes tests Test changes performance Performance-critical changes agents agent::email Email agent changes labels Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/gaia/npm ✅ ALLOW experimental experimental 3 high body.injection.credential_request, body.injection.guardrail_bypass, body.injection.persona_override
hub/skills/inbox-triage ✅ ALLOW community experimental, community none —

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes (one small fix)

The flagship can now read a whole email conversation, say which mailbox it is reading, and find threads where you owe a reply, for Gmail and Outlook, still read-only. Forwarded read-only Gmail connections are no longer rejected. The detector port is careful, the tests are thorough, and the evidence shows all three tools working. One thing needs fixing before merge:

  • Reading a long thread can overflow the model's context window. Each message keeps at least 400 characters of body even after the turn's reading budget is used up. On an NPU machine that budget is 30,000 characters, so a thread of about 75 messages blows through it on the first read. A short thread read after a few read_email calls can also push past it. Preventing that overflow is the whole job of this guard (it is the [Bug]: 1.4MB file indexed no response to queries in the UI #1030 failure). When the minimum can't fit, refuse the read with the same "budget exhausted" error the other read tools give, instead of reading past the budget.

Real-world evidence

The evidence stage ran the three new tools against an offline mailbox and ran the tool_cost CLI. The Agent UI screenshot is pending strix-halo lane. Forwarded-connection import couldn't run on this runner, so it relies on the unit suite.

### list_waiting_on_you()   (planted mailbox: one real thread + one promo that asks a question)
{ "success": true, "provider": "google", "count": 1,
  "waiting_on_you": [ { "from": "Dana Ortiz <[email protected]>",
      "subject": "Re: Zephyr rollout budget", "age_days": 30,
      "signal": "direct_ask", "corroboration": "thread_reply_history" } ],
  "inbox_scanned": 3, "threads_checked": 2, "scan_truncated": false, "suspicious_count": 0 }

### get_thread('does-not-exist')
{ "error": "Gmail has no such message or thread (404). The id may be mistyped, or the mail was deleted. Use an id returned by list_inbox or search_email. (request: GET /users/me/threads/does-not-exist)",
  "action": "get_thread", "success": false }
$ python -m gaia.eval.tool_cost            # exit 0
- Measured: gaia agent, full  |  Tools (deterministic): **92**
$ python -m gaia.eval.tool_cost --agent chat --profile doc   # exit 0
- Measured: chat agent, doc  |  Tools (deterministic): **44**
$ python -m gaia.eval.tool_cost --profile doc    # exit 2
error: the flagship only ships the 'full' profile; pass --agent chat --profile doc to measure that ChatAgent profile

get_thread returned the planted two-message conversation in order. On the 42-message eval fixture, list_waiting_on_you correctly found 0, because no fixture thread has a message from the user. These runs support the verdict. The overflow above only shows up with long threads or a nearly spent budget, and these runs didn't exercise either. Eval categories gaia_email, gaia_tool_selection and tool_selection still need the next RC run, as the PR says.

🔍 Technical details

🟡 get_thread per-message floor overruns the turn budget (src/gaia/agents/tools/email_tools.py:1441-1448 in the diff)

share = max(_THREAD_MIN_BODY_CHARS, min(_MAX_BODY_CHARS, (budget - used) // len(raw))). When len(raw) * 400 > budget - used, the floor wins and the read adds more than the remaining budget. The entry check only refuses when used >= budget. Gmail threads have no message cap. Graph caps at _THREAD_TOP = 100, which is 40K chars at the floor against a 30K NPU budget (truncation_budget). The wrap_untrusted_body markers aren't charged either. The existing test (test_get_thread_tool_charges_the_turn_budget_and_then_refuses) only covers a thread that fits. Suggested fix, with a test for a thread whose floor exceeds the remainder:

                remaining = budget - used
                if len(raw) * _THREAD_MIN_BODY_CHARS > remaining:
                    return _fail(
                        f"Thread {thread_id!r} has {len(raw)} messages; reading "
                        f"each would need {len(raw) * _THREAD_MIN_BODY_CHARS} "
                        f"chars but only {remaining} of {budget} remain this "
                        "turn, so it was not read. Tell the user the thread is "
                        "too long to read here and ask them to continue in a "
                        f"new turn. See {_EMAIL_DOCS_URL}",
                        "get_thread",
                        refusal=True,
                        turn_budget_exhausted=True,
                        budget_chars=budget,
                        budget_used_chars=used,
                    )
                share = min(_MAX_BODY_CHARS, remaining // len(raw))

🟢 Gmail silently scans fewer messages than the tool advertises. list_waiting_on_you says "max 200", but GmailReadBackend._clamp caps at _GMAIL_MAX_LIMIT = 100. The scan does report scan_truncated: true, so nothing is hidden. Still, either page through results in list_thread_ids or make the docstring say Gmail's cap is 100.

🟢 _sent_messages in waiting.py is misnamed. It returns every non-draft message, not just sent mail, and both callers rely on that. A name like _non_draft_messages would avoid misreading.

Strengths

  • The precision rules hold up against attempts to fake them. Only the user's own earlier messages in the same thread count as history, plus-tagged senders can't dodge an opt-out, and a promo label gives way to a real deadline. The 104-row corpus test and the fake-history tests cover the cases that matter.
  • It fails loudly when it should: one failed thread fetch fails the whole scan instead of returning a short list, a missing threadId or bad timestamp raises with a remedy, and truncated or unchecked threads are reported, not guessed.
  • The forwarded-scope change is correct "any-of" logic. Its error asks only for the narrowest scope, and a drift test pins the duplicated scope table.

The eval-harness change made three lanes import the flagship package they
never install, so the email unit lane, the chat lane and the RAG retrieval
gate went red.

- tests/unit/eval/test_harness_flagship_target.py is allowlisted to skip
  outside test_gaia_agent.yml, which installs both wheels before its skip
  guard and now runs the file.
- test_chat_agent.yml, test_rag.yml's retrieval gate and eval_retrieval.yml
  install hub/agents/gaia/python, and the chat lane triggers on it.
- list_waiting_on_you's docstring and the email guide state Gmail's real
  scan cap (100), not 200.
…dget

get_thread and list_waiting_on_you shipped 543- and 540-char descriptions, over the flagship's per-tool schema budget, so the code-quality lane failed. Trimmed to what the tool does, when to use it, and what it returns.
…dget

get_thread gave every message at least 400 chars even when less budget was left, and only refused when the budget was already spent. On an NPU budget (30K chars) a ~75-message thread, or a short thread after a few read_email calls, overflowed the context window on the first read. It now refuses up front with turn_budget_exhausted when messages x 400 exceeds what is left, names the thread size and remaining budget, and points at read_email.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit c3f66e2 Oct 30, 2026
77 of 79 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/mail-parity-1 branch October 30, 2026 07:10
tylerbea pushed a commit to tylerbea/gaia that referenced this pull request Oct 30, 2026
…#6158)

The published `@amd-gaia/gaia` 0.3.3 changelog listed two changes that
version does not ship: the mail thread tools and the read-only Gmail
connection fix from amd#6124 merged after the 0.3.3 release (amd#6122) but
were filed under `[0.3.3]`. They now sit under `[Unreleased]`, so the
next release notes pick them up and the 0.3.3 notes match what was
published. amd#6124's entries are the only ones added under `[0.3.3]` since
the `agent-pkg-gaia-v0.3.3` tag; the other changelogs main has touched
since are already under Unreleased.

## Test plan

- [ ] `git diff agent-pkg-gaia-v0.3.3 HEAD --
hub/agents/gaia/npm/CHANGELOG.md` shows no change inside `## [0.3.3]`
- [ ] Both amd#6124 bullets appear once, under `## [Unreleased]` → `###
Added`
- [ ] CI green
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 30, 2026
6 of 12 tasks
akshat-lakhera pushed a commit to akshat-lakhera/gaia that referenced this pull request Oct 31, 2026
## Why this matters

v0.25.4 is cut for Arabic support: the Agent UI runs right to left in
Arabic, and people can ask about Arabic, English or mixed documents in
either language (amd#6165). It also adds a local-only mode that keeps every
AI request on the PC, image indexing, and email thread reading for the
GAIA agent. Among the fixes, chats no longer get stuck on "Waiting for
the GPU", and file paths resolve to the chat's folder and the real
Documents folder. 59 commits since v0.25.3; the notes are in
`docs/releases/v0.25.4.mdx` and credit 7 outside contributors.

This is a patch carrying 8 `feat` commits, approved as v0.25.4 for the
Arabic RC.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.4.mdx
--tag v0.25.4` passes, and with `--tag v0.25.4-rc1`
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/release_versions.py --check`, `python
util/check_doc_links.py --internal-only` and `python
util/check_doc_versions.py` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.4`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py tests/unit/test_hub_core_version_gate.py
tests/unit/test_release_versions.py
hub/agents/gaia/python/tests/test_npm_doc_min_version.py`: 230 passed
- [x] Re-run the above after amd#6165 merged and main was merged in
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.4-rc1`:

- `rag_quality` and `real_world` (amd#6165, amd#6057)
- `gaia_rag` and `gaia_media` (amd#5651)
- `gaia_email` (amd#6124)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5450, amd#5454, amd#6080)
- `gaia_files` and `gaia_shell` (amd#6069, amd#6074, amd#6120)
- `gaia_code` (amd#6056)
- `gaia_core` and `context_retention` (amd#6152)
- `gaia_data` and `tool_selection` (amd#6053, amd#6130)
- `memory` and `gaia_memory` (amd#6127, amd#6081)
- `gaia_tool_selection` for tool confirmations (amd#5541)

## Release checklist

- [ ] Keep amd#6114 unmerged until v0.25.4 is tagged, so main stays on
0.25.4
- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.4-rc1` (the RC freezes its
own flagship; no agent release needed)
- [ ] Before the final: release the flagship from the release commit
(`agent-pkg-gaia-v<next>`), merge its pin-lock PR, and pass
`check_flagship_release.py`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes agents devops DevOps/infrastructure changes documentation Documentation changes eval Evaluation framework changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant