Repository navigation
feat(email): code-derived capability matrix + CI drift guard for tool surfaces - #2044
Conversation
|
Verdict: Approve ✅ This adds a code-derived capability matrix for the email agent plus a CI drift guard, so the four capability surfaces (52 internal tools, 16 REST verbs, 4 MCP tools, 6 eval suites) can no longer silently disagree with the manifest and docs. The design is sound: everything is introspected from source (AST for tools/MCP, the already-tested I verified the factual claims against the checked-out tree: the four eval report scripts referenced by the 🔍 Technical details🟢 Minor / nits1. MCP extractor only matches 2. (optional) No npm CHANGELOG entry. Strengths
|
|
Can you make sure this new markdown is added to the agent hub website similar to README, SCORECARD, etc. for the agent? |
Fixed red-state TDD contract for the planned packaging/capability_matrix.py generator: asserts the committed CAPABILITY_MATRIX.md never drifts, tools_count (52) stays consistent across gaia-agent.yaml/__init__.py/AST derivation, all 20 exposed ops (16 REST + 4 MCP) carry an eval-suite annotation or the no-quality-eval sentinel, the MCP scope decision is pinned, and every eval suite has a non-trivial follow-up plan with followups pinned as CI-unwired. The module under test does not exist yet, so this file currently fails at collection (FileNotFoundError loading packaging/capability_matrix.py) -- that is the expected starting state.
Adds packaging/capability_matrix.py: AST-derives the internal @tool count (52, per-mixin breakdown), reuses export_openapi.build_spec() for the REST surface (16 functional / 19 in contract), statically parses mcp_server.py for the 4 MCP tool names, and reads the 6 eval-gate fixture files for enforce/acceptance/wired state. Declares the curated OP_EVAL_COVERAGE, MCP_SCOPE_DECISION, and EVAL_FOLLOWUP_PLAN constants, plus a reconcile_tools_count guard that fails loud (naming the mismatch) if the manifest, registration, and AST-derived tools_count ever disagree. Markdown rendering and the CAPABILITY_MATRIX.md artifact land in the next commit; this one is scoped to introspection + declared constants going green against the test contract.
Checkpoint redirect: REST triage and triage/batch now map to the quality suite in OP_EVAL_COVERAGE, matching their MCP twins (same EmailTriageService code path, same eval coverage — the sentinel was wrong on the REST side). The remaining REST/MCP pairs (draft/draft_reply -> drafting, send/send_email -> sentinel) were already consistent. The test contract's getattr hedges around reconcile_tools_count and the AST-counter name-guessing indirection are replaced with direct references now that the module API is settled — a rename breaks loudly instead of silently reactivating a weaker fallback branch. Follow-up plan text is corrected for issue state (#1266/#1949/#1950 are all closed — cited as provenance, not pending work) and the followups tracking issue promise is kept generic until the issue exists.
Generated by packaging/capability_matrix.py; the freshness test (test_committed_capability_matrix_is_up_to_date) now byte-compares this file against a fresh regeneration, so any surface change that is not re-rendered fails CI with the one-line regenerate command. --check verified to exit 0 on this tree.
#2013) gaia-agent.yaml now carries the TOOLS_COUNT_DEFINITION comment directly above tools_count, and a new test (orchestrator-authorized contract addition) asserts the comment block contains a marker phrase sliced from the constant itself — so the yaml comment, the matrix Definitions section, and the test all trace to one string. SPEC.md and README.md gain one reference line each pointing at CAPABILITY_MATRIX.md as the canonical cross-surface capability inventory. The followups CI-wiring plan now cites its tracking issue (#2040), the Definitions bullet no longer doubles the "tools_count" prefix, and the committed matrix is regenerated in lockstep (--check exits 0).
…ration time Review fixes for the capability matrix: - count_tools_in_source only matched bare @tool decorators; the framework also supports the call form @tool(...) (used by other mixins in the codebase), so the first email mixin adopting @tool(atomic=True) would have been silently uncounted — a hole in the drift guard itself. Both forms now count, and the synthetic-source test gains a call-form case. - reconcile_tools_count is now wired into derive_matrix() (manifest read via raw-text parse, registration literal via AST), so a tools_count mismatch fails the generator and --check loudly, not just the pytest run: "tools_count sources disagree: gaia-agent.yaml=53, __init__.py build_registration()=52, AST-derived=52". - Dead test hedges removed (dict-vs-attr _field helper, followups entry isinstance branch) now the return type is settled; plan-referential inline comment trimmed to a one-line WHY; both files black/isort-formatted. No rendered byte changes; --check exits 0 on the aligned tree.
Main just flipped the briefing/drafting judge gates to report mode (#2038), which would have made the plan prose ("already an enforcing release gate") contradict the live enforce state rendered in each suite's section header the moment this branch rebased. The prose now describes what each gate measures and what happens next, and leaves the enforce/wired flags to the derived header — the same duplication this issue exists to eliminate. Matrix regenerated; --check exits 0.
Rebasing onto main picked up #2038 (briefing/drafting judge gates flipped to report mode), and the freshness test failed until the matrix was regenerated — this is the drift guard doing its job: a fixture change cannot silently leave the committed matrix stale. Only the derived enforce flags changed; the state-agnostic plan prose needed no edit.
|
Good call — filed as a follow-up: #2050 tracks publishing |
…x doc PR #2044 review nits: the MCP name extractor now matches both plain and async def (symmetry with count_tools_in_source — an async migration of the MCP server must not silently zero the derived count), guarded by a synthetic-file test. The npm CHANGELOG's 0.4.0 Added section gains the CAPABILITY_MATRIX.md entry (doc-only for the package, no wire change).
c0953ff to
8dc737c
Compare
|
Both review nits addressed in 8dc737c, plus the rebase:
Post-rebase validation: 12/12 capability-matrix tests, 372 passed full email suite, lint exit 0, |
|
🟡 The "20 exposed ops" count in the capability-matrix table header is hardcoded prose that the byte-compare CI guard cannot catch when the surface changes. After a new REST endpoint or MCP tool is added: The fix is one line: replace the hardcoded string at 🔍 Technical details
# current — silently drifts
lines.append("20 exposed ops (16 REST functional + 4 MCP) and their eval coverage:")
# fix — live-derived, always consistent with Surface totals
total = matrix.rest_functional_count + len(matrix.mcp_tools)
lines.append(
f"{total} exposed ops ({matrix.rest_functional_count} REST functional + "
f"{len(matrix.mcp_tools)} MCP) and their eval coverage:"
)The "Surface totals" section already uses |
…alues The "20 exposed ops (16 REST functional + 4 MCP)" header prose was a literal inside the generator, so a surface change would regenerate a matrix whose table and totals update but whose header still claims the old counts — and the byte-compare drift test cannot catch a literal the generator itself carries. The header now interpolates rest_functional_count and len(mcp_tools), the same derived sources the Surface totals section uses. Rendered bytes are unchanged today (--check exits 0 against the committed artifact); the hand-written 8/4/2-route footnote stays static by design.
|
Header-count nit fixed in 9ee44d0 — the capability-matrix table header now interpolates Also re-validated on top of the branch update that pulled in #2045: 12/12 matrix tests (including the hard-coded 16/19 REST anchors against a fresh |
|
🟡 The header interpolation fix (
The AC1 drift test catches a stale committed doc, but if someone regenerates after adding a REST endpoint, the freshly generated markdown itself has the inconsistency — so AC1 passes while the artifact is wrong. Fix: add one assertion to 🔍 Technical detailsThe gap lives between these two lines in # header — derived from live source
exposed_ops = matrix.rest_functional_count + len(matrix.mcp_tools)
lines.append(f"{exposed_ops} exposed ops ...")
# table body — hardcoded OP_EVAL_COVERAGE, NOT matrix.rest_op_names
for op in sorted(OP_EVAL_COVERAGE):
...Add to def test_op_eval_coverage_matches_derived_ops(matrix):
"""The hardcoded OP_EVAL_COVERAGE and the live-derived REST+MCP ops must
agree, or render_markdown() produces a header count that contradicts the
table row count."""
derived = set(matrix.rest_op_names) | matrix.mcp_tools
declared = set(capability_matrix.OP_EVAL_COVERAGE)
assert derived == declared, (
f"missing from OP_EVAL_COVERAGE: {derived - declared}; "
f"extra in OP_EVAL_COVERAGE: {declared - derived}"
)This closes the gap |
The code-derived capability matrix records each eval gate's enforce flag; setting the perf gate to enforce:false (this PR) made it stale (perf: enforce=True -> False), which the #2044 drift guard (test_capability_matrix.py) correctly caught and failed the Email Agent Unit Tests. Regenerated via packaging/capability_matrix.py.
|
Heads-up from #2066 (hub publishing of this file): the leading Cheapest fix is in the generator: emit the do-not-edit marker as a plain line the renderer shows intentionally (e.g. an italic footer), or move it below the title. Worth folding into this PR since the generator ships here. |
…md#2066) Closes amd#2050 Before: the code-derived `CAPABILITY_MATRIX.md` (amd#2044) only lives in the repo — hub visitors can't see the email agent's validated tool surface without leaving the site. After: publishing a release uploads it like the other catalog docs, the catalog serves it per version exactly like `EVALUATION.md`, and the hub page renders it as a **Capabilities** tab. The doc-tab rendering lives in this repo (`website/src/pages/hub/[id].astro`), so the tab ships here too — no external rendering boundary. Mergeable ahead of amd#2044: the release workflow guards on file presence, so releases cut before the matrix file lands simply publish without it (never a silent default — a *passed-but-missing* flag still fails loudly). **⚠️ Deploy ordering:** the production Worker is deployed manually. Deploy it before the next `agent-pkg-email-*` release, or the old Worker silently ignores the new `capability_matrix` part (the same designed degradation every prior doc-part addition had). Follow-up amd#2065 proposes a response echo that closes this window for good, plus the doc-part dedup. Two deliberate deviations from pure pattern-mirroring, both review-driven: - `toIndexEntry`'s trailing string params became one options object — a positional transposition typechecked silently and would have corrupted scorecard fields for **every** catalog agent on rebuild. - New `agent_hub_worker_ci.yml` — nothing in CI ran the worker suite before; the tests guarding the shared catalog contract were local-only. Known cosmetic: the matrix file's leading `<!-- Generated by … -->` marker renders as visible text on the tab (the site's markdown sanitizer escapes HTML comments). Content comes from amd#2044's generator — noted there. ## Evidence (real-world, local Worker via `wrangler dev` + real CLI) Rendered **Capabilities** tab, served from a real publish → catalog → website round trip:  <details> <summary>🔍 CLI + HTTP evidence (publish 201, catalog field, byte-identical serve, error path, workflow-guard simulation)</summary> Real publish with the real amd#2044 matrix content (5,889 bytes) — tested by running the actual CLI against a local Worker (miniflare R2): ``` $ AGENT_HUB_PUBLISH_TOKEN=*** python hub/agents/python/email/packaging/publish_to_r2.py \ --base-url http://127.0.0.1:8787 --manifest hub/agents/python/email/gaia-agent.yaml \ --capability-matrix CAPABILITY_MATRIX.md --artifact email-agent-linux-x64=linux-x64 [publish] attaching capability matrix: .../CAPABILITY_MATRIX.md (5889 bytes) [publish] email-agent-linux-x64 (4096 bytes, sha256=1a458efa2ae4…) -> [email protected] [publish] OK 201 — stored, server sha256 verified. [email protected] now has 1 artifact(s). ``` Catalog index carries the field; the per-version doc GET is byte-identical to the source: ``` $ curl -s http://127.0.0.1:8787/index.json | jq '…email.capability_matrix' capability_matrix present: True | length: 5889 $ curl -s http://127.0.0.1:8787/agents/email/0.4.0/CAPABILITY_MATRIX.md | diff - CAPABILITY_MATRIX.md HTTP 200, content-type text/markdown; charset=utf-8 BYTE-IDENTICAL ✓ ``` Missing-file error convention (mirrors `--evaluation`): ``` $ python …/publish_to_r2.py … --capability-matrix /nope/CAPABILITY_MATRIX.md error: --capability-matrix path not found: /nope/CAPABILITY_MATRIX.md. Pass the agent's CAPABILITY_MATRIX.md, or omit --capability-matrix to publish without one. exit=1 ``` Workflow-guard block simulated verbatim under the runner's bash (5.3, `set -euo pipefail`), both branches — tested in a `bash:5` container: ``` --- CAPABILITY_MATRIX.md ABSENT (pre-amd#2044) --- assembled: python publish_to_r2.py --artifact bins/email-agent-linux-x64 --- CAPABILITY_MATRIX.md PRESENT (post-amd#2044) --- assembled: python publish_to_r2.py --capability-matrix hub/agents/python/email/CAPABILITY_MATRIX.md --artifact bins/email-agent-linux-x64 ``` Full-page render: [capabilities-tab-fullpage.png](https://raw.githubusercontent.com/amd/gaia/evidence/2050-capability-matrix/capabilities-tab-fullpage.png) </details> ## Test plan - [x] Worker suite: `cd workers/agent-hub && npm test` — 71/71 (was 70; +1 cross-version test, 2 existing tests extended), `npm run typecheck` clean - [x] Website: `npx astro check` 0 errors, `npm test` 26/26 - [x] `publish_to_r2.py --help` shows `--capability-matrix`; missing-file path exits 1 with the exact documented message - [x] Real-world publish → catalog → website round trip (evidence above) - [ ] Reviewer: after merge + manual Worker deploy, the next `agent-pkg-email-*` release's catalog entry should carry `capability_matrix` (needs amd#2044 merged for the file to exist) --------- Co-authored-by: Tomasz Iniewicz <[email protected]>
Closes #2013
Why this matters
Before: the email agent's four capability surfaces (52 internal
@toolfunctions, 16 functional REST verbs, 4 MCP tools, 6 eval suites) had no single source of truth — every count was hand-typed across the manifest and docs, and nothing caught drift (the manifest'stools_counthad already gone stale once, 6 → 52). After: a generator derives the whole picture from code into a committedCAPABILITY_MATRIX.md, and CI fails if any count drifts —tools_countis now reconciled three ways (manifest == registration == AST-derived) at both test time and generation time.Note for reviewers: the issue body was written against a stale baseline —
tools_countis already 52 (fixed in v0.4.0), and the current enforce flags are per #2038 (perf enforcing + quality's acceptance gate). This PR ships the drift guard the issue actually needs and presents the corrected picture; it deliberately does not re-fix numbers that are already right.Decisions documented in the matrix (not just in this PR):
tools_countkeeps its meaning (internal agent-loop tools, 52) with the definition carried as a comment ingaia-agent.yamland guarded by test.followupssuite, which is the only one with no CI wiring at all.Mid-flight proof the guard works: #2038 landed on main during this work and flipped two enforce flags — the drift test went red on rebase exactly as designed, and one regeneration commit (09cd976) absorbed it with zero prose edits.
No eval run required: this change reads tool registration and fixtures; it modifies no prompt, tool docstring, registration, or model-selection surface.
Test plan
pytest hub/agents/python/email/tests/test_capability_matrix.py -v— 11 passedpytest hub/agents/python/email/tests/ -q— 329 passed (full email suite, post-rebase)python util/lint.py --all— exit 0tools_count: 53→ tests red +--checkexit 1; revert → greenpython hub/agents/python/email/packaging/capability_matrix.py --checkon the branch → exit 0Evidence (CLI)
Drift check green on the aligned tree, and failing loud on a perturbed manifest:
🔍 More detail
build_spec() operations: 19 / derived rest_in_contract_count: 19 / derived rest_functional_count: 16 / MATCH.tools_count: 53:test_tools_count_matches_derivedfails withassert 53 == 52, both guard tests fail; revert →11 passed.@tooland@tool(...)forms (the call-form gap was caught in review and is now covered by the synthetic-file test).packaging/(not insidegaia_agent_email/) so the frozen sidecar binary does not ship it —freeze.pyblanket-collects the package.