a2ui-rs
A runtime-agnostic, stateless Rust toolkit implementing the A2UI protocol (v0.8 & v0.9) for server-side agent applications. It provides typed message models, catalog negotiation, LLM prompt generation, JSON Schema validation, and message builders — all as pure functions and minimal traits.
All session management, agent memory, and conversation state are owned by the agent harness (e.g. Rig), not this library.
Architecture
┌──────────────────────────────────────────────────────────────┐
│ Agent Harness (Rig etc.) │
│ Owns: LLM loop, session state, memory, surface tracking │
│ Uses a2ui-rs to: │
│ - Build system prompt context (catalog + protocol schema) │
│ - Construct typed server-to-client messages │
│ - Validate LLM output before sending to client │
│ - Parse incoming client-to-server messages │
│ - Negotiate catalogs with client capabilities │
│ - Send validated messages via ClientTransport trait │
└──────┬──────────────────┬──────────────────┬─────────────────┘
│ │ │
▼ ▼ ▼
CatalogProvider a2ui-core ClientTransport
(trait impl by (pure functions (trait impl by
harness/plugin) + utilities) harness/plugin)
The library is a toolkit, not an engine. The harness calls into it; it never drives control flow.
Crate Structure
| Crate | Description |
|---|---|
a2ui-types |
Serde-based typed models for v0.8 and v0.9 messages, capabilities, catalogs, and data binding types. Pure data — no logic, no async. |
a2ui-core |
Traits (ClientTransport, CatalogProvider), pure functions for negotiation, validation, prompt building, message construction, and parsing. |
a2ui-validation |
JSON Schema validation engine. Validates outgoing messages against catalog schemas and returns structured ValidationErrors matching the spec's VALIDATION_FAILED format. |
Module Map
a2ui-types/src/
├── common.rs # SurfaceId, ComponentId, CatalogId, SpecVersion
├── v08/
│ ├── server_to_client.rs # surfaceUpdate, beginRendering, dataModelUpdate, deleteSurface
│ ├── client_to_server.rs # userAction, error
│ ├── capabilities.rs # ClientCapabilities
│ └── data_model.rs # BoundValue, DataEntry, Action, Children
└── v09/
├── server_to_client.rs # createSurface, updateComponents, updateDataModel, deleteSurface
├── client_to_server.rs # action, error (VALIDATION_FAILED)
├── capabilities.rs # ClientCapabilities, ServerCapabilities
├── client_data_model.rs # ClientDataModel (sendDataModel sync)
├── common_types.rs # DynamicString/Number/Boolean, ChildList, Action, FunctionCall, CheckRule
└── catalog.rs # Catalog, FunctionDefinition
a2ui-core/src/
├── traits.rs # ClientTransport, CatalogProvider
├── negotiation.rs # negotiate_catalog(), negotiate_catalog_with_inline()
├── validation.rs # validate_message(), parse_client_message_*(), serialize_message_*()
├── prompt.rs # build_prompt_context_v08(), build_prompt_context_v09()
├── message.rs # CreateSurfaceBuilder, UpdateComponentsBuilder, etc.
└── error.rs # A2uiError
a2ui-validation/src/
└── schema_validator.rs # SchemaValidator, validate()
Quick Start
1. Implement the Traits
use ;
use CatalogId;
use Catalog;
use async_trait;
2. Negotiate a Catalog
use negotiate_catalog;
// Client sends its supported catalog IDs (e.g. from a2uiClientCapabilities)
let client_supported = vec!;
let result = negotiate_catalog?;
println!;
3. Build LLM Prompt Context
use build_prompt_context_v09;
let catalog = my_catalog_provider.get_catalog.unwrap;
let schema = my_catalog_provider.get_catalog_schema.unwrap;
let prompt_ctx = build_prompt_context_v09;
// Inject into your LLM system prompt
let system_prompt = format!;
4. Construct & Validate Messages
use *;
use *;
use json;
// Build a v0.9 createSurface message
let create_msg = new
.send_data_model
.build;
// Build a component update
let update_msg = new
.add_component
.add_component
.build;
// Validate before sending
let msg_json = to_value?;
validate_message?;
5. Serialize & Send
use serialize_message_v09;
let bytes = serialize_message_v09?;
my_transport.send_to_client.await?;
6. Parse Incoming Client Messages
use ;
let parsed = parse_client_message_auto?;
match parsed
7. Handle Validation Errors
When the LLM generates invalid A2UI JSON, the validation functions return structured errors that can be fed back to the LLM:
use A2uiError;
match validate_message
v0.8 Usage
The library fully supports v0.8 with separate type hierarchies:
use *;
use *;
use ComponentInstance;
use json;
// Begin rendering
let begin_msg = new
.catalog_id
.build;
// Surface update with components
let surface_msg = new
.surface_id
.add_component
.build;
// Serialize
let bytes = serialize_message_v08?;
Spec Version Support Matrix
| Feature | v0.8 | v0.9 |
|---|---|---|
| Surface creation | beginRendering |
createSurface |
| Component updates | surfaceUpdate |
updateComponents |
| Data model updates | dataModelUpdate (adjacency list) |
updateDataModel (JSON Pointer + value) |
| Surface deletion | deleteSurface |
deleteSurface |
| Client actions | userAction |
action |
| Error reporting | error (flexible) |
error (structured with code) |
| Data binding | BoundValue (literalString/path) |
DynamicString/DynamicNumber/DynamicBoolean |
| Function calls | — | FunctionCall (client-side) |
| Check rules | — | CheckRule (client-side validation) |
| Data model sync | — | sendDataModel + ClientDataModel |
| Server capabilities | — | ServerCapabilities |
| Client capabilities | supportedCatalogIds |
supportedCatalogIds + inlineCatalogs |
| Theme | styles (free-form) |
theme (schema-validated) |
| Version field | Not required | Required ("v0.9") |
| Catalog negotiation | ✓ | ✓ (with inline support) |
| Message validation | ✓ | ✓ |
| Prompt generation | ✓ | ✓ |
Design Philosophy
- Stateless toolkit: No session management, no surface tracking, no data model storage. The harness owns all state and calls library functions as needed.
- Runtime-agnostic: Only the
ClientTransporttrait is async (viaasync-trait). Everything else is synchronous pure functions. No tokio/async-std dependency in the library itself. - Separate type hierarchies:
v08::ServerToClientMessageandv09::ServerToClientMessageare distinct types. The harness chooses which module to use. No version-polymorphism overhead. - Catalog as typed + raw JSON:
Catalogstructs for negotiation metadata; rawserde_json::Valuefor validation and LLM prompt injection. - Spec-compatible error reporting:
ValidationErrormirrors the A2UIVALIDATION_FAILEDformat so the harness can forward errors directly to the LLM or client.
Dependencies
| Crate | Purpose |
|---|---|
serde + serde_json |
Serialization / deserialization |
async-trait |
Async trait support for ClientTransport |
thiserror |
Ergonomic error types |
jsonschema |
JSON Schema validation engine |
Building & Testing
# Build all crates
# Run all tests (60 tests across unit, round-trip, and integration)
# Run tests for a specific crate
License
MIT