A typed event stream makes the chat easy. The host still has to own the chart, the SQL and the write
AG-UI standardizes delivery. It does not make a model's chart, its SQL arguments or its write proposals safe to trust, so the host has to.
A chart is valuable only when it represents the question the person asked. This case follows a synthetic employee-data question through the evidence and the visible artifact, so the reader can distinguish a tool's result from the way it is presented.
A people-ops lead types: which department has the worst attrition, and show me a chart. The model calls attrition_analysis. A bar chart appears with Customer Success first, at seven exits in the last twelve months. The data is a synthetic company of about 180 people in SQLite, and the recorded run behind that answer shows one terminal RUN_FINISHED frame and no leaked reasoning.
Notice what the model did there. The model chose the tool and may set chart_kind; the tool wrote the query and the ChartSpec, and the page built the ECharts option. The bars came from code it cannot edit.
The claim is that AG-UI is a good seam between agent and frontend only while the host keeps everything the browser could mistake for authority: the chart schema, the SQL inputs, the model's private reasoning and every write. The protocol standardizes the envelope. The README says so itself: AG-UI ships no chart primitive and does nothing for answer quality.
The argument
- The model picks tools, arguments and the final text. Code runs the tools. In each tool round the model chooses among nine allowlisted tools with
tool_choice: auto, for at mostMAX_TOOL_ROUNDSrounds (4 by default), and supplies the arguments. The round that makes no tool call writes the text; after the round cap, a tools-free round is forced. Every tool is deterministic SQL. - A chart is a closed schema. The model may set
chart_kind; the tool writes theChartSpec. Charts travel on the protocol's genericCUSTOMevent as aChartSpecthe project defines. The page builds the ECharts options itself and writes text withtextContent. - A
group_byvalue must match the allowlist or the tool raises; the allowlisted SQL fragment is then interpolated. Allowlisted dimensions are not raw model text, and no model-supplied string is interpolated into SQL. Name, department, and level filters still reach SQL as bound parameters. - A write is a proposal until a person approves it. Staging a promotion flag creates a pending action and writes no flag.
Who is allowed to decide
Calling this product "an agent with charts" hides where the model's discretion ends. Its discretion is which of nine tools to call next, with what arguments, and what to say in the final text; the query, the ChartSpec and the writes are decided in the host.
The figure below separates the two. Look at what sits inside the dashed line, and at the orange card outside it.
The browser renders ECharts from a ChartSpec and sets text with textContent, and it also posts chat and approval decisions. Inside the dashed line, the app/agui.py card lists _drive_turn (tool_choice: auto), run_turn (AG-UI typed SSE), ChartSpec (closed allowlist) and run_tool (9 SQL tools). That file frames typed events; ChartSpec is defined in app/contracts.py and run_tool in app/tools.py. On the right sit SQLite and the Codex model, gpt-6-luna by default, reached through app/llm.py. The orange card, staged writes, is the one place a human decides: staging leaves a flag pending; decide_action applies it only on a human approval.
Two rules sit on the host side of that line, and both have a reason. ChartSpec is a closed schema because ECharts options accept string formatters and rich text, and handing raw model output to the renderer would put the model in charge of the browser. Reasoning never leaves the server because the adapter never reads the model's reasoning items, and the emitter sends no REASONING_* or THINKING_* events, although AG-UI defines them. Private deliberation is not narration an operator should see.
Authorization is the open edge. The product routes are mounted twice: /api/* for the static page, with no token, and /v1/agui/* behind a bearer token when a session token is configured. The migration notes list the open /api/* routes as an unresolved item. This is a proof of concept, not a multi-tenant design.
What the evidence shows
The tests prove guards, not judgement. Each row below is a failure the host refuses, and the right-hand column says what the test leaves open.
| Guard | What the test does | What it does not show |
|---|---|---|
| One terminal frame | Stubs the model and a failing tool, and expects exactly one RUN_ERROR; a failing model stream yields RUN_STARTED then RUN_ERROR only | Which errors users see most often |
| No reasoning on the wire | Feeds the stream reasoning_content and asserts it appears nowhere in the raw output | That the model reasons well |
| Injection-shaped dimension | Passes group_by text that tries to inject SQL and expects Invalid group_by | Every possible hostile argument |
| Staged write | Counts promotion_review_flags before and after the flag tool and expects no change | That the model proposes flags sensibly |
| Repeat approval | Approves twice and expects zero additional writes | Concurrent approvers |
Two other guards are about delivery. Every data: frame is validated against the official Event union, and TOOL_CALL_RESULT must carry a messageId. The transport owns the rest, and the next figure shows what to look for.
On the left is agui_response: an eight-frame queue, a heartbeat comment when the queue is idle, and cleanup that is awaited on disconnect. On the right is the test file that holds each of those to account. A heartbeat times out only the queue read and does not cancel the idle source. A disconnect under backpressure closes the model generator without inventing a RUN_FINISHED. The README states that a heartbeat times out only a queue read, and that backpressure drops no frames. None of this says anything about whether the attrition numbers are right.
That question has its own harness. The evals copy the seeded database for each run and judge live answer correctness separately from wire validity. The recorded live turns in the migration notes are observations from single runs: 34 to 47 frames, a flag turn that staged 31 affected employees and left the database at zero active flags until approval. They show the path completing. They are not a measured rate.
Wire tests and answer quality are different studies. Stubbed tests show the stream keeps its shape, ends once and carries no reasoning. The database cannot jump to an applied flag on the model's word. Our only evidence on answer quality is a 15-case live evaluation (14 of 15 passed in the recorded run) and single recorded turns.
The turn we ran
The canonical offline turn is one test, test_happy_path_order_chart_and_no_reasoning_leak. It replaces the model with a stub. Round one emits private reasoning, then a tool call whose arguments arrive in fragments. Round two emits more reasoning, then the answer in two text deltas. The stubbed tool returns a bar chart for two departments.
Read the five boxes top to bottom: RUN_STARTED, the tool-call events, a CUSTOM event named chart, the TEXT_MESSAGE_* frames and one RUN_FINISHED, drawn in blue. The orange caption under the boxes says a raised tool or model stream ends in RUN_ERROR, with one terminal event. The test asserts that the emitted tool-argument delta parses as one JSON object and that both text deltas share one message id.
The privacy assertion is the one to remember. The stub's stream contains reasoning_content. The emitted bytes must not contain that key, any reasoning event type, or the deliberation phrases. A second test checks streaming: each frame is validated through ag_ui.core.Event, the sequence numbers must strictly increase, and the model's last chunk waits until a TEXT_MESSAGE_CONTENT frame has been yielded. A server that buffered the whole answer would fail that wait.
The one check to copy
Copy the reasoning firewall and the single terminal event. After building an event stream from any model loop, assert on the parsed types and the raw bytes together.
assert types_seen[0] == "RUN_STARTED"
terminal = [t for t in types_seen if t in ("RUN_FINISHED", "RUN_ERROR")]
assert terminal == ["RUN_FINISHED"]
assert not any(t.startswith("REASONING") or t.startswith("THINKING") for t in types_seen)
assert "reasoning_content" not in rawPair it with a typed chart check: find the CUSTOM event, assert its name is chart, and construct ChartSpec(**value), so a widened schema cannot slip past. If your agent can write, copy the delta assertion from test_staging_writes_nothing: count rows before the write-capable tool runs, run it, and assert the count is unchanged while the staged action reads pending. And keep a hand-maintained allowlist test with one injection case, as test_allowlist_rejects_injection_dimension does with department; DROP TABLE employees--.
The README's own commands are separate questions. The pytest entry point checks the guards. scripts/e2e_smoke.py checks the wire against a live server. python -m evals.run_eval scores answers over a live model. None of them replaces the offline leak test.
Close
A typed stream earns trust when four things stay in the host: how a turn ends, what a chart may contain, which SQL can run, and which flags become active. The model's discretion is narrow and real. It steers tool selection and the arguments on those calls inside MAX_TOOL_ROUNDS, and the wording of the final text; the host owns the chart, the SQL and the writes.
Authenticated /api/* routes are an open migration item; reconnectable streams are a README limit this POC does not implement. For a first presentation layer, the position that holds is the smaller one: let the model choose the tool, its arguments and the final text, and keep the chart, the SQL and any flag that decide_action has not approved in the host.
How is this page?
Last updated on