agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

AG-UI payloads carry non-schema fields that strict clients reject

Open chcodex opened this issue 1 month ago • 3 comments

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:

  1. RUN_FINISHED interrupt outcomes serialize expiresAt, metadata and responseSchema as null. @ag-ui/client 1.0.3 rejects these with Invalid input: expected string, received null (and an invalid metadata), so a HITL run that ends with an interrupt fails on the client.
  2. AguiMessage serializes derived helpers (textContent, userMessage, assistantMessage, systemMessage, toolMessage, reasoningMessage), a null toolCallId on non-tool messages, and an empty toolCalls: [] array. Clients strip them with "unrecognised material" warnings, and a user message carrying toolCalls is 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 the RUN_FINISHED outcome: the client throws on the interrupt fields.
  • Request a hydrate (MESSAGES_SNAPSHOT) and inspect the message objects: extra fields and null toolCallId are 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/client consumes 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.

chcodex avatar Oct 23 '26 12:10 chcodex

I validated the payload fixes against @ag-ui/[email protected] / @ag-ui/[email protected]; the three issues in the description are addressed locally:

  • Interrupt omits expiresAt / metadata / responseSchema when null.
  • AguiMessage omits the derived helpers, null toolCallId, and empty toolCalls.
  • JsonPatchOperation omits value / from for remove, while keeping "value": null for add / replace. A blanket NON_NULL would 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:

  1. Is AguiEvent considered a public, binary-compatible API? That determines whether B is acceptable.
  2. Should we align all events (including RUN_ERROR) or only the three event types reported here?
  3. 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.

chcodex avatar Oct 23 '26 13:10 chcodex

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.

chcodex avatar Oct 23 '26 14:10 chcodex

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

jujn avatar Oct 24 '26 11:10 jujn