Skip to main content

Crate ag_ui_a2ui

Crate ag_ui_a2ui 

Source
Expand description

A2UI protocol types, semantic validator, and agent-side authoring toolkit.

A2UI is a declarative, agent-driven UI protocol: an agent streams JSON describing a surface, and a renderer draws it. This crate is the agent half of that exchange.

§This crate does not render

Nothing here draws pixels, lays out a tree, or evaluates a UI at runtime. It produces A2UI, validates it, and transports it. Rendering is the client’s job, and it is a genuinely different program — one with a widget toolkit, an event loop, and a reactive data model. What this crate gives you instead:

  • message — the ten protocol envelopes, in both directions.
  • catalog — what a surface may contain, including the standard 18-component basic catalog.
  • validate — the semantic checks JSON Schema cannot express: does every child reference resolve, is there a root, is the tree acyclic. Plus the two a generating model gets wrong often enough to be worth checking without a schema engine: the message envelope, and property values against the type the catalog declares.
  • binding — JSON Pointer resolution, template scopes, and the formatString interpolation grammar, so an agent can check its own bindings before shipping them.
  • toolkit (feature toolkit) — building ops, negotiating a catalog, assembling prompts, parsing a model’s output as it streams, recovering a surface from conversation history, and the validate-and-retry loop around a generating model.
  • agui (feature ag-ui) — the glue for an agent hosted on AG-UI: history entries from ag_ui::Message, toolkit tool definitions as offerable ag_ui::Tools.

§Transport

A2UI says nothing about how messages reach the renderer, and everything outside one module keeps it that way — turn the ag-ui feature off and the dependency goes with it, leaving a crate you can drive over A2A or MCP. That module is agui. What every toolkit does in practice is wrap a batch of operations in a {"a2ui_operations": [...]} envelope and let the frontend sniff for that key. toolkit::envelope produces exactly that, as a plain JSON string that fits in an AG-UI assistant message, an A2A data part, or an MCP tool result without further wrapping.

§Conformance

The A2UI project publishes a language-agnostic conformance suite as YAML. It is vendored under tests/conformance/ and run as a normal test; the report prints what passed, what was skipped, and why. See the README there for the current standing.

§Version

Messages are stamped v0.9. The specification has moved on to v1.0, but the shipping toolkits in every other language still speak v0.9 on the wire, and interoperating with them matters more than tracking the newest revision. See constants before changing anything there.

§Example

use ag_ui_a2ui::{Catalog, Component, Validator};
use serde_json::json;

let catalog = Catalog::basic();
let components = vec![
    Component::new("root", "Card").with("child", json!("greeting")),
    Component::new("greeting", "Text").with("text", json!("Hello!")),
];

let report = Validator::new(&catalog).validate(&components);
assert!(report.is_valid());

Re-exports§

pub use catalog::Catalog;
pub use error::Error;
pub use error::Result;
pub use error::ValidationErrors;
pub use message::AgentMessage;
pub use message::AgentPayload;
pub use message::ChildList;
pub use message::ChildTemplate;
pub use message::Component;
pub use message::RendererMessage;
pub use message::RendererPayload;
pub use validate::ErrorCode;
pub use validate::ValidateOptions;
pub use validate::ValidationError;
pub use validate::ValidationReport;
pub use validate::Validator;
pub use toolkit::StreamParser;
pub use toolkit::wrap_as_operations_envelope;
pub use toolkit::wrap_error_envelope;
pub use agui::find_prior_surface_in;

Modules§

agui
Interop with ag_ui (feature ag-ui).
binding
Data-model binding: JSON Pointer resolution, scopes, and formatString.
catalog
Component catalogs: what a surface is allowed to contain.
constants
Wire-contract constants shared across every A2UI toolkit.
error
Error types for the A2UI protocol layer.
message
A2UI protocol envelopes.
toolkit
Agent-side authoring: producing A2UI, not rendering it (feature toolkit).
validate
Semantic validation of a component tree.