Skip to content

fix(eval): point five scenarios at a real agent, and reject unknown agent types - #3906

Merged
itomek merged 4 commits into
amd:mainfrom
kovtcharov:claude/fix-3883-eval-agent-type
Sep 21, 2026
Merged

itomek merged 4 commits into
amd:mainfrom
kovtcharov:claude/fix-3883-eval-agent-type

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Five spreadsheet and CSV eval scenarios asked for the removed data agent, so every run of them was an INFRA_ERROR that never reached the model. Because infra errors are left out of the category average, nobody noticed. They now target the flagship gaia agent, which carries the scratchpad and analyze_data_file tools that replaced the analyst agent. The Agent UI backend now refuses to create or retype a session to an unknown agent id. Its 422 lists every id it accepts and, for an installed agent that failed to import, the load error, so this kind of drift fails immediately instead of producing a session that can never answer.

  • Why gaia and not a data alias: the existing aliases only cover -lite model tiers of agents that still exist. data was removed on purpose, and its work now lives in the flagship's full profile. The doc profile only loads analyze_data_file on demand and has no scratchpad tables. An alias would quietly keep the dead id alive.
  • csv_analysis now runs a different agent from the rest of rag_quality. A scenario's own agent_type wins over --agent-type, so this one runs gaia while the other six run doc, and the category scorecard mixes the two agents by design.
  • Baselines: the three committed scorecard_rag_quality.json baselines were recorded before the scenario ran gaia, so their csv_analysis PASS (9.82 / 9.83 / 9.15) is not a number any current run can reproduce. Each entry now carries a _stale_note saying so. Re-baseline from the first rag_quality run on this branch.
  • A new guard test fails CI if any scenario's agent_type stops resolving to an id the session endpoint accepts: a registered agent, a legacy alias, or a sidecar like email. It needs no Lemonade.

Test plan

  • pytest tests/unit/eval/test_scenario_agent_types.py: every scenario agent_type resolves, and a sidecar id passes like the endpoint accepts it
  • pytest tests/unit/chat/ui/ tests/unit/eval/: 1539 passed, including 422 tests for create and update (unknown id rejected with no session left behind, known id accepted, update leaves the stored type alone, load error named, every accepted id listed)
  • pytest tests/integration/test_chat_ui_integration.py -k test_custom_agent_model_id_honored_through_api: custom ~/.gaia/agents ids still create sessions
  • gaia eval agent --category rag_quality --agent-type doc: csv_analysis now runs and gets a score instead of INFRA_ERROR, then re-baseline it. Runs in the self-hosted CI job once the branch is pushed to amd/gaia.

Fixes #3883

…gent types

csv_analysis and the four real_world xlsx scenarios requested the removed 'data' agent, so every turn got the canned agent-unavailable reply and the scenarios reported INFRA_ERROR without ever reaching the model. They now target the flagship 'gaia' agent, whose full profile carries the scratchpad and analyze_data_file tools.

Session create and update now return 422 naming the registered agent ids when agent_type resolves to nothing, instead of storing a session that can never answer. A unit guard checks every scenario agent_type resolves against built-in agents, hub entry points, and legacy aliases.

Fixes amd#3883
@github-actions github-actions Bot added the tests Test changes label Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Approve with suggestions

Five spreadsheet/CSV eval scenarios were pointed at an agent that no longer exists, so they silently reported infra errors instead of scores. This PR retargets them at the flagship agent, adds a CI guard that fails the moment any scenario names an agent that can't resolve, and makes the Agent UI backend refuse to create or retype a session to an unknown agent instead of handing back a session that can never answer. The direction and the guard test are both right.

The one thing worth doing before merge: nobody has yet run the five scenarios end to end to confirm they now produce a score. The PR is candid about this — the eval box in the test plan is unchecked — but it means the fix is still unproven, and the committed rag_quality baseline keeps a passing score for the CSV scenario that was recorded back when the removed agent existed. Whoever runs the next comparison will be diffing against a number no current checkout can reproduce. One eval run (or a note pinning the baseline as stale) closes that.

Smaller points, all non-blocking: when an agent is installed but failed to import, the new rejection message tells the user to install it from the Agent Hub, dropping the load-failure reason the backend already has recorded; the list of valid ids in that message doesn't quite match what the check actually accepts; and the new eval guard would reject a scenario aimed at the email agent even though the backend allows it.

No security concerns found.

Real-world evidence

N/A — no evidence bundle was produced for this PR, and the description carries only pytest results. The new 422 behaviour is an HTTP surface the CI lane could have exercised with a real request/response against POST /api/sessions; the eval scenario change is a gaia eval agent surface that needs a machine with inference. The verdict here rests on static review plus the unit tests the author ran.

🔍 Technical details

Issues

🟡 The eval fix is unverified, and the baseline it will be compared against is stale (eval/scenarios/rag_quality/csv_analysis.yaml:4)

The test plan's gaia eval agent --category rag_quality item is unchecked, so there's no evidence the five retargeted scenarios now reach the model and score rather than failing a different way (e.g. the flagship's scratchpad / analyze_data_file path on multi-sheet .xlsx). Separately, all three scorecard_rag_quality.json baselines still record csv_analysis as a 9.82 PASS from the analyst-agent era — the PR says so explicitly but leaves them untouched, so the next --compare diffs against an unreproducible number. Either run the category once and re-baseline per CLAUDE.md ("Interpreting regressions"), or mark that entry stale so the next reader doesn't read a false regression. Also worth noting in the PR: csv_analysis now runs a different agent from the rest of its category (runner.py:1942 — per-scenario agent_type wins over --agent-type), so that scorecard mixes agents by design.

🟢 The 422 discards the recorded load-error reason (src/gaia/ui/routers/sessions.py:87)

_agent_type_unknown is true both for an id that was never installed and for one whose import blew up during discovery. _agent_unavailable_message (_chat_helpers.py:632) surfaces registry.get_load_error(...) for exactly that case; this new path doesn't, so a broken-but-installed agent gets told to install itself. The existing assertions ("'data'", "chat, gaia") still hold with this change:

    valid_ids = sorted({reg.id for reg in registry.list()} | {"chat"})
    load_error = registry.get_load_error(agent_type)
    reason = f" It failed to load: {load_error}." if load_error else ""
    raise HTTPException(
        status_code=422,
        detail=(
            f"Unknown agent_type '{agent_type}'.{reason} Registered agent ids: "
            f"{', '.join(valid_ids)}. Pick one of these, or install the agent "
            "from the Agent Hub (`gaia hub`) and restart the server."
        ),
    )

🟢 The advertised id list doesn't match what's accepted (src/gaia/ui/routers/sessions.py:87)

_agent_type_unknown exempts _SIDECAR_AGENT_TYPES unconditionally (_chat_helpers.py:120), so email is accepted even on a machine where register_sidecar never ran — but it won't appear in valid_ids. Conversely builder is hidden=True in the registry yet gets listed. Folding _SIDECAR_AGENT_TYPES into the union would at least make the message a superset of what's accepted.

🟢 The guard can't express a sidecar-backed scenario (tests/unit/eval/test_scenario_agent_types.py:264)

_hub_agent_ids() reads [project.entry-points."gaia.agent"], and hub/agents/email/python/pyproject.toml declares none (verified locally — it's the one hub package with no match). So a future agent_type: email scenario fails this guard even though POST /api/sessions accepts it. Adding the sidecar ids to known keeps the guard and the endpoint agreeing on the same rule.

🟢 The helpful 422 body never reaches the user in the UI (src/gaia/apps/webui/src/components/ChatView.tsx:243)

handleAgentChange catches the failure, rolls the picker back, and shows nothing. Pre-existing, and unlikely to fire since the picker only lists registered agents — but the id list this PR adds is invisible on the path most users are on. Worth a follow-up rather than a change here.

Strengths

  • The guard test is built to not pass vacuously: test_hub_entry_points_parsed asserts the parser actually found chat/doc/file/gaia, so a regex regression fails loudly instead of shrinking known to nothing. Reading entry points from source rather than importlib.metadata also makes it independent of which wheels happen to be installed in CI.
  • Validation reuses _agent_type_unknown rather than re-deriving the rule, so the REST endpoints and chat dispatch can't drift apart on what counts as unknown — including the sidecar exemption and legacy alias resolution through registry.get.
  • _reject_unknown_agent_type runs before the try in create_session, so the 422 isn't swallowed into the generic 500 handler, and it no-ops when the registry isn't yet set — no startup-ordering hazard.
  • The rejection tests assert the side effect, not just the status code (total == 0 after a rejected create, stored agent_type unchanged after a rejected update).

Kalin Ovtcharov added 2 commits September 18, 2026 19:52
…pted id

An installed agent that failed to import was told to install itself; the
422 now carries the recorded load error. The id list names every id the
endpoint accepts, including the email sidecar, and the scenario guard
accepts the same ids the endpoint does.

The csv_analysis entry in the three rag_quality baselines is marked stale:
it was recorded before the scenario ran the gaia agent, and needs
re-baselining from the next rag_quality run.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Merged main and addressed the review. When an installed agent failed to import, the rejection now says why instead of telling the user to install it. The error lists every agent id the endpoint accepts, and the scenario guard accepts email the same way the endpoint does. The stale csv_analysis score in the three baselines is marked as such, and the PR description now notes that this scenario runs a different agent from the rest of its category.

Still open: the rag_quality eval run and the re-baseline it enables. That runs in the self-hosted CI job once a maintainer pushes this branch to amd/gaia. The UI swallowing the 422 is filed as #4015.

🔍 Technical details
  • Merge (952b14c): only routers/sessions.py conflicted, on imports. Kept both: main's GaiaConfigError/resolved_default_model and this branch's registry helpers.
  • 🟡 Eval / stale baseline (40e5f9e): I can't re-baseline without a run. Each csv_analysis entry now carries _stale_note, the same underscore-note convention as the existing top-level _rerun_note. compare_scorecards ignores the key; comparing each baseline against itself is still 7/7 unchanged. The note doesn't say the score came from data: two of the three baselines (Apr 25) predate data existing (May 7), so it only says the score came from an agent other than the one the scenario now runs. The eval box stays unticked.
  • 🟢 422 drops the load error (40e5f9e): applied your patch. Test: test_rejection_names_why_an_installed_agent_failed_to_load.
  • 🟢 Advertised vs accepted ids (40e5f9e): _SIDECAR_AGENT_TYPES is folded into the list. I left builder listed on purpose: the endpoint accepts it, and App.tsx creates agent_type: 'builder' sessions for the New Agent flow, so the list now matches what the endpoint accepts. Test: test_the_listed_ids_include_every_accepted_one.
  • 🟢 Guard vs endpoint (40e5f9e): _known_agent_ids now adds _SIDECAR_AGENT_TYPES (imported, not copied). Test: test_a_sidecar_agent_type_passes_the_guard.
  • 🟢 ChatView.tsx swallows the 422: not a one-liner. It needs the error detail threaded into useNotificationStore plus a frontend test, so it's filed as fix(webui): show why an agent switch was rejected instead of silently rolling back #4015.
  • Verified: pytest tests/unit/chat/ui/ tests/unit/eval/ (1539 passed); the custom-agent integration test passes; flake8, black and isort are clean on the touched files.

@itomek

itomek commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Synced this branch onto current main and re-verified the whole thing there, because the green run above was measured against a main that was 8 commits older. Nothing regressed, and the 422 this PR adds now has real evidence behind it instead of unit tests alone.

An unknown agent id is rejected on both session create and session retype, with a message naming every id the server actually accepts. The rejected create leaves no session behind, and the rejected retype leaves the existing session's agent untouched — so the failure mode this prevents (a session bound to an agent that can never answer) is closed on both paths.

Worth calling out: the first probe accidentally ran against main's code, and there the same request is accepted with 200 and a junk-typed session is persisted. That is this bug observed live, and it is also why #4030's review couldn't find the validation it was built on — it genuinely isn't on main until this lands.

One thing this does not prove, stated rather than glossed over: nobody has run gaia eval agent --category rag_quality. What is proven is that the id those five scenarios now name is one the backend accepts, and that the new guard test enforces it. Whether they score well under the flagship agent is still unknown. Landing this is still strictly better than the status quo — today those scenarios name a removed agent and are guaranteed INFRA_ERROR, which is excluded from the category average, so the failure is invisible. Once a real score starts counting, the rag_quality average may move; that is the correct signal, not a regression, and all three baselines already carry _stale_note.

🔍 Technical details

Verified on c6e0b7a3 — this PR's head merged with current origin/main.

The 422, against a live server

Backend booted with no Lemonade running (a session-create rejection needs no inference). curl is blocked in this environment, so the probe uses Python's http.client — same raw socket, verbatim status line and body. Mutating routes need X-Gaia-UI: 1 or the CSRF guard 403s before the agent-type check is ever reached.

Control, proving the endpoint works:

POST /api/sessions  {"title": "control-good", "agent_type": "chat"}
HTTP/1.1 200 OK     -> agent_type "chat", session count 6 -> 7

Rejection:

POST /api/sessions  {"title": "should-be-rejected", "agent_type": "definitely-not-an-agent"}
HTTP/1.1 422 Unprocessable Entity
{"detail": "Unknown agent_type 'definitely-not-an-agent'. Registered agent ids: builder, chat, doc, email, file, gaia. Pick one of these, or install the agent from the Agent Hub (`gaia hub`) and restart the server."}

GET /api/sessions   -> count still 7; no session created
PUT /api/sessions/{id}  {"agent_type": "definitely-not-an-agent"}
HTTP/1.1 422 Unprocessable Entity   (same detail)

GET /api/sessions/{id}  -> agent_type still "chat"; unchanged

The accidental control run against main

The venv here is editable-installed against a different checkout, so the first attempt served main's router:

import gaia.ui.routers.sessions as m
/home/tomas/src/amd/gaia/src/.../sessions.py   hasattr(_reject_unknown_agent_type) -> False
PYTHONPATH=<this branch>/src                   hasattr(_reject_unknown_agent_type) -> True

Against the first: POST and PUT with the same unknown id both returned 200, and the junk-typed session persisted.

Suites on the merged tree

pytest tests/unit/chat/ui/                       946 passed
pytest tests/unit/eval/                          661 passed, 1 skipped
                                                 combined: 1607 passed, 0 failed
pytest tests/unit/eval/test_scenario_agent_types.py     58 passed
pytest tests/integration/test_chat_ui_integration.py \
       -k test_custom_agent_model_id_honored_through_api    1 passed
python util/lint.py                              exit 0

The plan's 1539 grew to 1607 because main added tests; nothing fails. The two MyPy/workflow warnings from lint are repo-wide and pre-existing, and cite no file this PR touches.

Did main move under this PR?

No contract it depends on changed. Neither src/gaia/ui/routers/sessions.py nor src/gaia/agents/registry.py was touched by the 8 new commits. #4007 adds a separate outcome-scored task harness under eval/tasks/ with its own JSON manifest — it does not read eval/scenarios/**/*.yaml and does not redefine agent ids, so the scenario path retargeted here is untouched by it.

All five retargeted scenarios declare agent_type: gaia (static read), and gaia appears in the accepted set the running server printed in its own 422 body (runtime evidence).

Not verified

  • No gaia eval agent run — needs a Lemonade backend and a judge credential, neither available here. The self-hosted eval lane shows skipping on a fork PR and runs on main post-merge.
  • Linux (WSL2), GPU device profile only. No Windows or NPU check.

Earlier CI on this branch showed one red job — Test GAIA CLI on Linux — which was Launchpad returning HTTP 500: GPGKeyTemporarilyNotFoundError while adding the lemonade PPA. Unrelated to this change; it passed on re-run.

@itomek
itomek added this pull request to the merge queue Sep 21, 2026
Merged via the queue into amd:main with commit 54e71c9 Sep 21, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(eval): csv_analysis and 4 real_world scenarios request the removed 'data' agent

2 participants