Repository navigation
feat(email): add batch triage endpoint alongside the single-email API (array in / array out) - #1893
Conversation
|
Verdict: Approve ✅ This PR turns the email-triage surface from one-email-per-call into a batch contract: every call now takes The standout: this is the kind of breaking change CLAUDE.md asks for — every consumer and doc surface moved in lockstep. REST endpoint, MCP tool schema, npm client types, playground/spec HTML, smoke test, OpenAPI, and all four doc files (README/SPEC/SKILL/CHANGELOG) are migrated together, with TDD-style contract + service tests covering per-item isolation, the Only one tiny nit, and nothing blocking. 🔍 Technical details🟢 MinorStale doc comment now misstates the default schema version ( Notes (not blocking)
Strengths
|
New batch tests (currently failing — TDD red state):
- test_batch_contract.py: BatchTriageRequest/BatchTriageResponse/BatchItemResult
round-trips, exactly-one constraint, SCHEMA_VERSION=2.0 guard, additive
guarantee (original EmailTriageRequest.payload / EmailTriageResponse.request_kind
untouched)
- test_batch_triage_service.py: 3-item success, per-item isolation, 422 on
empty/over-cap/wrong-shape, 502 on Lemonade unreachable, single-endpoint
regression (POST /triage still returns {request_kind, result})
Adds a new batch triage endpoint beside the unchanged single-email path: - contract.py: BatchItemError, BatchItemResult, BatchTriageRequest, BatchTriageResponse, MAX_BATCH_SIZE=100 (SCHEMA_VERSION stays "2.0") - api_routes.py: triage_batch service method + /triage/batch route - mcp_server.py: triage_email_batch tool + _BATCH_TRIAGE_SCHEMA - Regenerated openapi.email.json; updated test_rest_contract.py + test_email_openapi_conformance.py with batch route entries - AGENT_VERSION 0.2.5 → 0.3.0; stamp_version.py propagated to npm/yaml
- spec_html.py: batch endpoint block beside the single one (derived from the new contract models); unwrap Annotated[...] in the type-label helper so the discriminated-union list element renders as list[SingleEmailInput | ThreadInput] - specification.html: add ep-triage-batch reference entry + integration-matrix note - playground_html.py: add a Batch triage card + doTriageBatch probe (array in / array out), reusing renderTriage per item - tests updated: list-label guard tolerates union inner; playground asserts the /triage/batch path is called
npm @amd-gaia/agent-email (additive — triage()/single types unchanged): - types.ts: BatchTriageRequest/BatchTriageResponse/BatchItemResult/BatchItemError + MAX_BATCH_SIZE - client.ts: triageBatch() → POST /v1/email/triage/batch - index.ts: export MAX_BATCH_SIZE alongside SCHEMA_VERSION - test: triageBatch() round-trip (existing triage() test stays green) Docs (additive batch sections beside the unchanged single contract): - npm README/SPEC/SKILL: triageBatch() example + interface row - npm CHANGELOG: 0.3.0 additive-batch entry (no breaking callout) - docs/spec/email-contract.mdx: Batch endpoint section + examples Also: black-format the L1 batch test files; drop unused imports in the single-endpoint regression test.
42c6e4d to
526e42f
Compare
Mirrors the existing single triage_email parity test for the batch tool:
drives the same {items:[single, thread]} envelope through both surfaces —
triage_email_batch over MCP stdio and EmailTriageService.triage_batch on
REST — and asserts the structured results[] arrays are byte-identical after
stripping non-reproducible per-item usage. Extends _strip_runtime_usage to
walk the batch results[] envelope; adds triage_email_batch to the tools-list
assertion. The single triage_email parity tests are untouched and green.
|
Verdict: Approve ✅ This adds a One tiny, optional cleanup is noted below. 🔍 Technical detailsStrengths
🟢 Minor (optional, non-blocking)
|
Reconciles the schema-2.1 REST surfaces (search, prescan, archive/quarantine, calendar) with main's additive batch triage endpoint (#1893). Both feature sets now coexist on the email contract: the package version is 0.3.0 and the contract SCHEMA_VERSION is 2.1 (additive over 2.0 — no triage-shape change). Conflict resolutions: - contract.py: grafted main's Batch* models alongside the 2.1 models; restored MAX_BATCH_SIZE and added Annotated import; merged __all__. - api_routes.py / spec_html.py / client.ts / types.ts: kept both endpoint sets, imports merged alphabetically. - openapi.email.json + specification.html: regenerated/3-way-merged to carry all 16 paths. - Docs (README/SKILL/SPEC/CHANGELOG): merged both into a single 0.3.0 entry. - test_batch_contract.py: the additive-version assertion now checks MAJOR==2 (contract legitimately sits at 2.1, not 2.0) instead of the stale ==2.0.
Closes #1887
Before: the email triage surface handled one email (or thread) per call —
POST /v1/email/triagetakes a singlepayloadand returns a singleresult, so triaging an inbox meant one HTTP round-trip per message. After: a newPOST /v1/email/triage/batchaccepts an array (items: […]) and returns one structured result per item (results: […], order-preserved, 1:1), with per-item errors isolated so one bad message doesn't sink the batch. A single email is simply an array of one.This is purely additive — the existing single
/triageendpoint, its schema (2.0), the MCPtriage_emailtool, the npmtriage()method, and every existing consumer are untouched. Callers opt into batch when they want it. No migration; schema stays2.0; package bumps0.2.5 → 0.3.0(additive minor).What's added (beside the unchanged single path)
POST /v1/email/triage/batchwith a sequential, per-item-isolated service loop; a new MCPtriage_email_batchtool; an npmtriageBatch()method + batch types.openapi.email.json(now carries both routes),specification.html, and a playground batch probe.docs/spec/email-contract.mdxand npmREADME/SPEC/SKILL, plus0.3.0additiveCHANGELOGentries (no breaking callout).Test plan
git diff mainshows zero deletions totriage_request/ the/triageroute /triage_email(MCP) /triage()(npm); a regression test confirmsPOST /v1/email/triagestill returns{request_kind, result}at schema 2.0. All existing single-path tests stay green untouched.test_batch_contract.py+test_batch_triage_service.py+ an MCP↔REST parity test (test_batch_parity, driving{items:[…]}through the real MCP stdio subprocess and the REST path and asserting identicalresults[]): 3-item mixed (single+thread) array → orderedresultswithresults[i].index == i; per-item isolation (a stateful fake fails item 1, items 0 & 2 still succeed); empty / over-100 / wrong-shape ({payload}) →422; envelope-level502when Lemonade is unreachable. 602 email tests pass.export_openapi --check,stamp_version.py --check, npmbuild+test(47/47),util/lint.py --all— all green.SCHEMA_VERSIONstays2.0.Real-world evidence — AMD Strix Halo (Ryzen AI MAX+ 395, RDNA 3.5 iGPU),
gemma-4-E4B-it-GGUFon GPUBranch
@526e42f8deployed;gaia-agent-email 0.3.0installed editable (resolution verified in-tree); 25 batch tests pass;gaia apiup on:8080, both routes serving; inference on the GPU-loaded gemma-4-e4b (~53–57 tok/s).(A) The single
/triageendpoint is UNCHANGED — old{payload}body still returns the 2.0{request_kind, result}shape:(B) The new
/triage/batchendpoint — 3-item mixed array (2 single + 1 thread) → 3 ordered results (HTTP 200):response — categories correct (URGENT / PROMOTIONAL / FYI)
{"schema_version":"2.0","results":[ {"index":0,"result":{"category":"URGENT","suggested_action":"reply","message_id":"b1", "summary":"Immediate action is required because the production database has been unreachable…"},"error":null}, {"index":1,"result":{"category":"PROMOTIONAL","suggested_action":"archive","message_id":"b2", "summary":"A 50% off sale on all items is running this weekend only; use code SAVE50…"},"error":null}, {"index":2,"result":{"category":"FYI","suggested_action":"none","message_id":"thread-99", "summary":"Thread of 2 messages. The recipient confirmed attendance at the Friday team lunch…"},"error":null} ]}results.length == 3,results[i].index == i, everyresultpopulated,error: null— order-preserved, correct live classification on the GPU model.Breaking-shape guards on the batch endpoint: empty
items→422("List should have at least 1 item"); the single-endpoint{payload}body POSTed to/triage/batch→422(missingitems+ forbiddenpayload).Per-item error isolation is unit-proven (
test_per_item_isolation_failure_at_item_1); a natural input couldn't force a live LLM exception, so it was not fabricated on the live path./triagesingle (A)/triage/batch3-item (B)