A Rust implementation of the AG-UI protocol — the open, event-based protocol for streaming structured events between AI agents and frontend applications.
use ag_ui_server::axum::agent_router;
use ag_ui_server::protocol::{Message, RunAgentInput, UserContent};
use ag_ui_server::{Agent, AgentError, EventEmitter, RunOutcome};
struct MyAgent;
impl Agent for MyAgent {
async fn run(&self, input: RunAgentInput, emitter: EventEmitter)
-> Result<RunOutcome, AgentError> {
let msg = emitter.start_text_message().await?;
msg.content("Hello from Rust!").await?;
msg.end().await?;
Ok(RunOutcome::success())
}
}
// axum::serve(listener, agent_router(MyAgent)).await?;
Protocol compliance handled for you, without giving up control of the transport.
98% spec coverage, wire-compatible with the official TypeScript and Python SDKs.
RUN_STARTED / RUN_FINISHED / RUN_ERROR emitted automatically around every run.
Ordering violations are caught and surfaced as RUN_ERROR before they ever reach the client.
TextMessageHandle and ToolCallHandle make invalid event sequences unrepresentable at the type level.
RFC 6902 JSON Patch diffing via diff_states() for efficient STATE_DELTA events.
Use the Axum integration, or call run_agent() directly and stream it over any HTTP framework.
A pure data layer you can depend on anywhere, and a runtime for serving it.
Wire-compatible data types for all 33 AG-UI events, 7 message roles, capabilities, and input payloads. Zero runtime deps beyond serde.
ag-ui-protocol = "0.1"
Async runtime: Agent trait, lifecycle pipeline, protocol verification, SSE encoding, and an optional Axum integration.
ag-ui-server = { version = "0.1", features = ["axum"] }
A full spec breakdown lives in the repo — every event, message type, and lifecycle rule.
ag-ui-rust is free to use, modify, and distribute under the MIT license. Built on Tokio and Serde, with an optional Axum integration.