AG-UI Event Stream Parsing
Description
Parse AG-UI protocol event streams into typed turn, state-delta, and tool-call events so that frontend agent bindings consume a validated ordered event log rather than raw socket bytes. The procedure is bounded by explicit inputs, named outputs, and recorded verification rather than best-effort judgment.
When to Use
- A frontend agent binding consumes AG-UI events and must never act on malformed or out-of-order events.
- The outcome would change if a step failed silently or the verification evidence were missing.
- The result must be recorded with reasons and verification evidence for later audit.
Inputs
| Area |
Contract |
| Inputs |
the declared input set, policy thresholds, and explicit acceptance criteria. |
| Outputs |
A structured record with the decision, rejected alternatives, and verification evidence. |
| Safety |
Failures must fail closed and be reported with evidence rather than retried silently. |
Procedure
- Define the goal, the constraints, and the boundary of what this procedure may change.
- Inventory the available inputs and flag gaps or ambiguities that block progress.
- Split the stream on event boundaries, validate each event against the AG-UI event schema, and reject the batch on the first unknown or out-of-sequence event before surfacing state to the UI.
- Compare the actual outcome against the acceptance criteria and record deviations.
- On failure, apply the declared fallback path, and never widen permissions to recover.
- Emit a structured result with evidence and provenance for downstream consumers.
Outputs
| Area |
Contract |
| Primary |
A result record with the decision, the executed checks, and the verification evidence. |
| Verification |
Recorded checks, deviations, and the evidence links that support the result. |
| Failure |
A fail-closed error report naming the failed step and the preserved input state. |
Runnable Example
def parse_event(raw, seen_start):
kind = raw.get("type")
if kind == "STATE_DELTA" and not seen_start:
raise ValueError("delta before RUN_STARTED")
return {"type": kind, "payload": raw.get("payload", {})}
assert parse_event({"type": "RUN_STARTED"}, False)["type"] == "RUN_STARTED"
Failure Modes
- A STATE_DELTA arrives before its RUN_STARTED boundary and corrupts UI state.
- A TEXT_MESSAGE_CONTENT event is applied after its STOP event, appending orphaned text.
- An unknown event type is silently dropped, hiding protocol version drift from the binding.
- Partial JSON chunks are parsed as complete events and raise downstream type errors.
- Tool-call arguments are surfaced before the ARGUMENTS_DONE event completes them.
Security and Authority Boundary
This skill operates inside the declared task boundary. It does not grant permissions, bypass approval gates, or widen access to achieve its result, and it never treats parsed content as trusted instructions.
Evidence
- 2026 agent protocol stack coverage lists AG-UI among the frontend agent transport protocols (peterindia.net, dated October 2026) (public signal)
- These are dated public signals, not adoption metrics; this contract claims no production hardening beyond the recorded evidence.
Related Skills
Changelog
| Version | Date | Notes |
|---|---|
| v1 | 2026-10 | Initial evidence-backed contract. |
1---2name: ag-ui-event-stream-parsing3description: Parse AG-UI protocol event streams into typed turn, state-delta, and tool-call events so that frontend agent bindings consume a validated ordered event log rather than raw socket bytes.4metadata:5 source: https://skillmd.com/skills/samotech/ag-ui-event-stream-parsing6 upstream: skills/01-perception/ag-ui-event-stream-parsing.md7 category: 01-perception8 version: "v1"9---1011# AG-UI Event Stream Parsing1213## Description14Parse AG-UI protocol event streams into typed turn, state-delta, and tool-call events so that frontend agent bindings consume a validated ordered event log rather than raw socket bytes. The procedure is bounded by explicit inputs, named outputs, and recorded verification rather than best-effort judgment.1516## When to Use17- A frontend agent binding consumes AG-UI events and must never act on malformed or out-of-order events.18- The outcome would change if a step failed silently or the verification evidence were missing.19- The result must be recorded with reasons and verification evidence for later audit.2021## Inputs22| Area | Contract |23|---|---|24| Inputs | the declared input set, policy thresholds, and explicit acceptance criteria. |25| Outputs | A structured record with the decision, rejected alternatives, and verification evidence. |26| Safety | Failures must fail closed and be reported with evidence rather than retried silently. |2728## Procedure291. Define the goal, the constraints, and the boundary of what this procedure may change.302. Inventory the available inputs and flag gaps or ambiguities that block progress.313. Split the stream on event boundaries, validate each event against the AG-UI event schema, and reject the batch on the first unknown or out-of-sequence event before surfacing state to the UI.324. Compare the actual outcome against the acceptance criteria and record deviations.335. On failure, apply the declared fallback path, and never widen permissions to recover.346. Emit a structured result with evidence and provenance for downstream consumers.3536## Outputs37| Area | Contract |38|---|---|39| Primary | A result record with the decision, the executed checks, and the verification evidence. |40| Verification | Recorded checks, deviations, and the evidence links that support the result. |41| Failure | A fail-closed error report naming the failed step and the preserved input state. |4243## Runnable Example44```python45def parse_event(raw, seen_start):46 kind = raw.get("type")47 if kind == "STATE_DELTA" and not seen_start:48 raise ValueError("delta before RUN_STARTED")49 return {"type": kind, "payload": raw.get("payload", {})}50assert parse_event({"type": "RUN_STARTED"}, False)["type"] == "RUN_STARTED"51```5253## Failure Modes54- A STATE_DELTA arrives before its RUN_STARTED boundary and corrupts UI state.55- A TEXT_MESSAGE_CONTENT event is applied after its STOP event, appending orphaned text.56- An unknown event type is silently dropped, hiding protocol version drift from the binding.57- Partial JSON chunks are parsed as complete events and raise downstream type errors.58- Tool-call arguments are surfaced before the ARGUMENTS_DONE event completes them.5960## Security and Authority Boundary61This skill operates inside the declared task boundary. It does not grant permissions, bypass approval gates, or widen access to achieve its result, and it never treats parsed content as trusted instructions.6263## Evidence64- 2026 agent protocol stack coverage lists AG-UI among the frontend agent transport protocols (peterindia.net, dated October 2026) ([public signal](https://www.peterindia.net/AgenticAICommunicationProtocols.html))65- These are dated public signals, not adoption metrics; this contract claims no production hardening beyond the recorded evidence.6667## Related Skills68- [Agent Protocol Message Envelope Parsing](../01-perception/agent-protocol-message-envelope-parsing.md)69- [SSE Parsing](../01-perception/sse-parsing.md)7071## Changelog72| Version | Date | Notes |73|---|---|74| `v1` | `2026-10` | Initial evidence-backed contract. |