AG-UI payloads carry non-schema fields that strict clients reject
Description
Strict AG-UI clients validate the payload of every received event. Two payload shapes emitted by this library are not schema-valid and break or dirty the client:
RUN_FINISHEDinterrupt outcomes serializeexpiresAt,metadataandresponseSchemaasnull.@ag-ui/client1.0.3 rejects these withInvalid input: expected string, received null(and an invalidmetadata), so a HITL run that ends with an interrupt fails on the client.AguiMessageserializes derived helpers (textContent,userMessage,assistantMessage,systemMessage,toolMessage,reasoningMessage), a nulltoolCallIdon non-tool messages, and an emptytoolCalls: []array. Clients strip them with "unrecognised material" warnings, and a user message carryingtoolCallsis not schema-valid.
JsonPatchOperation has the same null-field issue for value/from on remove operations.
Steps to reproduce
- Run an AG-UI agent that ends with a tool-call interrupt.
- Connect with
@ag-ui/[email protected](HttpAgent) and inspect theRUN_FINISHEDoutcome: the client throws on the interrupt fields. - Request a hydrate (
MESSAGES_SNAPSHOT) and inspect the message objects: extra fields and nulltoolCallIdare reported as unrecognised material.
Expected
- Optional interrupt fields are omitted when absent.
- Messages and JSON Patch operations only emit AG-UI schema fields.
- A standard
@ag-ui/clientconsumes text runs, hydrate snapshots and interrupt outcomes without errors.
Verification
Tested against @ag-ui/[email protected] with a scripted local server: text runs, hydrate via MESSAGES_SNAPSHOT, and tool-call interrupt runs all pass with no client-side errors after the fix.
I validated the payload fixes against @ag-ui/[email protected] / @ag-ui/[email protected]; the three issues in the description are addressed locally:
InterruptomitsexpiresAt/metadata/responseSchemawhen null.AguiMessageomits the derived helpers, nulltoolCallId, and emptytoolCalls.JsonPatchOperationomitsvalue/fromforremove, while keeping"value": nullforadd/replace. A blanketNON_NULLwould drop legitimate null values, so this one needs per-operation handling.
E2E result: HttpAgent accepts text runs, hydrate snapshots, and interrupt outcomes. The pre-fix interrupt payload fails with the exact Invalid input: expected string, received null errors.
One more schema mismatch surfaced, and I would like maintainer guidance before expanding scope.
@ag-ui/[email protected] only declares threadId / runId on RUN_STARTED and RUN_FINISHED (not even on RUN_ERROR). The Java AguiEvent interface requires both on all 28 event records, so TEXT_MESSAGE_*, STATE_DELTA, MESSAGES_SNAPSHOT, TOOL_CALL_*, etc. all emit them. The official client strips them with Removed unrecognised material ... warnings; runs still succeed, so this is noise / non-conformance rather than a failure.
Options:
A. Encoder-level filter (small, non-breaking)
In AguiEventEncoder, omit threadId / runId for all events except RUN_STARTED / RUN_FINISHED.
- Keeps the Java model, constructors, getters, and deserialization unchanged.
- Only the SSE wire output changes.
- Direct
JsonUtils.toJson(event)would still include the fields.
B. Model alignment (breaking)
Remove the components from the 26 affected records and keep them only on RUN_STARTED / RUN_FINISHED.
- Protocol-clean for every serialization path.
- Changes public canonical constructors and accessors.
- Breaks serialize → deserialize round-trips and needs a major version or a deprecation cycle.
- Touches roughly 18 main files / 90 event constructions, plus ~125 test constructions.
C. Leave as-is
The official client strips the fields with warnings and continues.
Questions:
- Is
AguiEventconsidered a public, binary-compatible API? That determines whether B is acceptable. - Should we align all events (including
RUN_ERROR) or only the three event types reported here? - Would you prefer A now and a model cleanup later, or keep #3744 focused only on the failing payloads?
Happy to adjust the scope based on your preference.
Draft PR for the payload fixes: #3747. It keeps the current event model and does not change constructors or validation. The threadId/runId options remain open for maintainer guidance.
My opinion is not to do B. The benefits are disproportionate: in return, we will "eliminate a few warnings", and the client can run. And we will examine whether this will affect other agui clients