Skip to content

fix(showcase/built-in-agent): repair six real-LLM defects D6 was masking - #6200

Merged
AlemTuzlak merged 1 commit into
mainfrom
fix/built-in-agent-real-llm-parity
Jul 28, 2026
Merged

AlemTuzlak merged 1 commit into
mainfrom
fix/built-in-agent-real-llm-parity

Conversation

@AlemTuzlak

Copy link
Copy Markdown
Contributor

Six defects reported on staging. All six reproduce; five share one cause.

The shared cause

built-in-agent/src/app/api/copilotkit/route.ts maps ~20 demos to the same prompt-less createBuiltInAgent(). The reference wires each to its own graph and its own system prompt (28 graphs in langgraph-python/langgraph.json).

aimock replays a scripted tool-call sequence keyed on userMessage + context, so D6 is green whether or not the model could have reasoned its way there. This is showcase/GOTCHAS.md #8 verbatim — including its stated "structural tell": grep the integration's route.ts for demos left in the generic fallthrough that LGP wires to a dedicated graph.

Per-defect

Demo Symptom Root cause
gen-ui-tool-based charts plot zeros No prompt. The assistant says so itself: "I used placeholder values since no sales figures were provided." Nondeterministic — one run gave a real 0..220 axis, the next 0 1 2 3 4 with no bars, which is how it passed review.
gen-ui-agent wall of text, steps frozen at "step 1 of 4" set_steps + its /steps STATE_DELTA already worked; nothing told the model to walk pending→in_progress→completed.
subagents left panel always empty grep -rn delegations src/ | grep -v demos/subagents → no output. Frontend reads agent.state.delegations; the converter handles /steps and /notes and has no delegations case. Chat works because the tools do run.
declarative-json-render raw JSON for pills 2 & 3 Intercepted the SSE: the wire is already one closing brace short — nothing is dropped in transport, and the client parser correctly requires a balanced object. Pill 1 only works because the model copies the prompt's worked example verbatim (\$1.24M, +18% vs Q2). Model-level JSON enforcement had been removed with the note "the system prompt already enforces JSON-only output" — it does not.
a2ui-recovery 5 identical cards Reuses declarative-gen-ui's prompt with no "call once" constraint, while the pills literally ask it to "self-correct a malformed first attempt". The retry loop is inside the tool and returns on first valid pass, so every supervisor retry is pure duplication.
declarative-gen-ui D4 though it works live The inverse case. Badges: UI ✓ BE ✓ 1P ✗ D6 — ("gated — blocked by a lower rung"). Not a live bug — a fixture bug. See below.

The D4 cap (declarative-gen-ui, a2ui-recovery)

Both demos' secondary design-call fixtures gated on match.responseFormat: \"json_object\". That matcher can never match this backend:

  • The agent talks to the OpenAI Responses API, where JSON mode is text.format.
  • aimock has no text.format handling at all — responsesToCompletionRequest forwards only a top-level response_format (absent in 1.19.1, forwarded in 1.37.4), a key the Responses API doesn't accept and this client doesn't send.
  • So effective.response_format?.type is always undefined and router.ts skips the fixture → the design call never matched → surface never painted → D5 red, D6 never ran.

Re-keyed onto match.toolName, which aimock does normalize out of a Responses request (responsesToolsToCompletionsTools): the outer call declares generate_a2ui, the in-tool design call declares nothing. Tool-less secondary fixtures moved last, because several pills' brief is a substring of the pill text (\"Build my Q2 revenue summary …\" contains \"Q2 revenue summary\") and would otherwise win the outer request.

Verification

Reproduced live (staging, real LLM): the zero-axis chart plus its self-incriminating message, the unbalanced JSON on the wire, and the reference rendering the same pill correctly for contrast.

Two mutation-verified test suites — both fail with the fix reverted:

  • aimock-a2ui-routing.test.ts drives aimock's real matchFixture. On the old fixtures 14/16 cases fail with no fixture matched the secondary design call for brief \"…\" — the D5 red, reproduced as a unit test.
  • tanstack-factory.test.ts covers the /delegations and /steps deltas (3 delegation tests fail with the branch disabled; the 2 controls still pass).

No regressions: tsc --noEmit is 61 errors before and after (all pre-existing — gpt-5.4 missing from the adapter's model union, zod v3/v4 skew); oxlint clean on changed files; the repo-wide fixture validator passes (858 assertions).

text.format was verified by reading the request mapping in the pinned @tanstack/[email protected] → @tanstack/[email protected]: modelOptions is spread straight into responses.create(), validateTextProviderOptions only inspects metadata/conversation/previous_response_id, and the adapter sets text.format itself only when an outputSchema is passed (none here, so nothing is clobbered).

What is NOT verified

The four prompt/text.format changes have not had a real-LLM click-through — that needs an OpenAI key this environment doesn't have, and D6/aimock cannot verify them by construction (that's the whole point of gotcha #8). Reasoning is documented inline at each site. This area has burned the repo before: a previous response_format attempt made the call return an empty string "verified against real OpenAI", which is why text.format — the Responses API's own param — is used instead. Worth a live click-through on the staging deploy before this is considered closed.

Deliberate non-goals

  • a2ui-recovery only demonstrates recovery under aimock. The heal/exhaust branches need a designer LLM that emits invalid surfaces on demand; a real one succeeds on attempt 1. The single-call constraint fixes the 5-card bug and makes it honest; making recovery visible live needs deliberate fault injection — a product decision, recorded in PARITY_NOTES.md.
  • The reference pins openai:gpt-4o-mini (gen_ui_agent.py:92). Flagged, not touched.

Docs

GOTCHAS.md gains built-in-agent as a second worked instance of #8 (including that the masking runs both ways, and that 1P ✗ D6 — means gated, not failing), plus the text.format and dead-responseFormat traps. PARITY_NOTES.md records that the named-agent registry is not prompt-neutral, and that any new state.<slot> needs a converter branch.

Every affected cell was D6-green (or D4-gated) while the deployed demo was
visibly broken. The common cause is GOTCHAS #8: aimock replays a scripted
tool-call sequence keyed on userMessage + context, so the fixture answers a
question the model was never asked.

Prompt gaps — ~20 demos shared one prompt-less `createBuiltInAgent()` where the
reference wires each to its own graph AND its own system prompt. Adds
`createBuiltInAgent({ systemPrompt })` + `demo-prompts.ts`, ported from the
reference graphs:

- gen-ui-tool-based plotted zeros; the assistant said "I used placeholder values
  since no sales figures were provided". Nondeterministic — some runs invented
  real values, which is how it passed review.
- gen-ui-agent published its plan once then narrated, freezing the progress card
  on step 1 of 4.
- a2ui-recovery painted five identical cards: nothing constrained the supervisor
  to one `generate_a2ui` call, and the pills literally ask it to "self-correct".
  The retry loop lives inside the tool, so supervisor retries are duplication.

subagents' delegation panel was permanently empty — the frontend reads
`agent.state.delegations` and no code emitted that slot. The converter now emits
a `/delegations` delta per sub-agent result (whole-array `add`, since initial
state is `{}` and strict fast-json-patch rejects unresolvable paths while
@ag-ui/client swallows the throw), and ports the reference's
`_MAX_CRITIQUE_ITERATIONS = 1` cap.

declarative-json-render dumped raw JSON for any prompt the model couldn't crib
from the worked example. Captured the SSE: the wire is already one closing brace
short, so nothing is dropped in transport — model-level enforcement had been
removed on the grounds that "the system prompt already enforces JSON-only
output". It does not. Restores it via the Responses API's `text.format`, the
param the removed `response_format` maps to, verified against the pinned
@tanstack/[email protected] -> @tanstack/[email protected] request mapping.

declarative-gen-ui and a2ui-recovery were the inverse: capped at D4 (UI ✓ BE ✓
1P ✗ D6 gated) while working live. Their secondary design-call fixtures gated on
`match.responseFormat`, which aimock can never satisfy here — it has no
`text.format` handling and only forwards a top-level `response_format` the
Responses API doesn't accept. Re-keyed onto `match.toolName` (the outer call
declares `generate_a2ui`, the in-tool design call declares nothing) with the
tool-less fixtures moved last, since several pills' brief is a substring of the
pill text.

Tests (both mutation-verified — they fail with the fix reverted):
- aimock-a2ui-routing.test.ts drives aimock's real `matchFixture`; 14/16 cases
  fail on the old fixtures with "no fixture matched the secondary design call".
- tanstack-factory.test.ts covers the `/delegations` and `/steps` deltas.

Typecheck unchanged at 61 pre-existing errors; oxlint clean on changed files.

NOT verified live: the four prompt/`text.format` changes need a real-LLM
click-through, which needs a key this environment doesn't have. Reasoning and
the exact request mapping are documented inline.
@github-actions

Copy link
Copy Markdown
Contributor

Production Digest-Pinning Audit

All 41 services digest-pinned.

Run 2026-07-28 07:51:45 PDT — 0 finding(s).

@AlemTuzlak
AlemTuzlak merged commit 9a501d5 into main Jul 28, 2026
28 checks passed
@AlemTuzlak
AlemTuzlak deleted the fix/built-in-agent-real-llm-parity branch July 28, 2026 15:32
AlemTuzlak added a commit that referenced this pull request Jul 29, 2026
## Summary

Fixes staging click-through failures on **ms-agent-dotnet** and
**ms-agent-harness-dotnet** demos. Same class of bug as #6200 (GOTCHAS
#8): aimock D6 was green while real LLMs failed.

### Root causes & fixes

| Demo | Symptom | Fix |
|------|---------|-----|
| beautiful-chat Sales Dashboard | `Catalog not found: sales_dashboard`
| Force page-registered `catalogId`; stronger secondary design prompt |
| declarative-gen-ui KPI / pie / bar / status | Loader never resolves;
`without a type`; `SummaryCard` missing `id` | Sanitize + normalize flat
A2UI components; drop invalid entries; force
`declarative-gen-ui-catalog` |
| shared-state-read-write Remember something | Notes panel never updates
| AsyncLocal store write misses (tool EC); mirror writes + read
fallback; wire dead deterministic reply path for the pill |
| subagents left panel | Chat works, side UI empty | Same AsyncLocal
store bug for `state.delegations` |
| open-gen-ui-advanced calculator / ping host | Form/input calculator;
ping no-ops | System prompt for clickable keypad + `notifyHost` /
`evaluateExpression` wiring |
| beautiful-chat calculator | Buttons do nothing | OGUI guidance:
`type=button`, no `form`, click handlers |

### Voice auth error

Not a code defect in the voice route:
`GuardedOpenAITranscriptionService` correctly fails when
`OPENAI_API_KEY` is missing on the **Next.js** process. Staging needs
that env var on the showcase frontend service (transcription hits real
OpenAI, not aimock).

### MCP Excalidraw empty iframe

Left as follow-up — likely external MCP host / sandbox CSP; no
agent-side bug found in wiring.

## Test plan

- [x] `dotnet test` ms-agent-dotnet (79/79) in Docker SDK 9 — includes
new A2UI force-catalog / type-as-key / drop-invalid tests
- [x] harness agent build + cvdiag tests (5/5)
- [ ] Staging click-through after deploy:
- [ ] `/react/ms-agent-dotnet/beautiful-chat` — Sales Dashboard paints;
calculator interactive
- [ ] `/react/ms-agent-harness-dotnet/declarative-gen-ui` — all four
pills paint without A2UI errors
- [ ] `/react/ms-agent-harness-dotnet/shared-state-read-write` —
Remember something updates notes
- [ ] `/react/ms-agent-harness-dotnet/subagents` — left panel shows
running/completed delegations
- [ ] `/react/ms-agent-harness-dotnet/open-gen-ui-advanced` — calculator
keypad + ping host
- [ ] Voice: confirm `OPENAI_API_KEY` present on staging frontend, then
mic works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants