Open Source · MIT

AG-UI for Rust.

A Rust implementation of the AG-UI protocol — the open, event-based protocol for streaming structured events between AI agents and frontend applications.

src/main.rs
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?;

What you get

Protocol compliance handled for you, without giving up control of the transport.

Protocol fidelity

98% spec coverage, wire-compatible with the official TypeScript and Python SDKs.

Lifecycle framing

RUN_STARTED / RUN_FINISHED / RUN_ERROR emitted automatically around every run.

Protocol verification

Ordering violations are caught and surfaced as RUN_ERROR before they ever reach the client.

Typed streaming handles

TextMessageHandle and ToolCallHandle make invalid event sequences unrepresentable at the type level.

State management

RFC 6902 JSON Patch diffing via diff_states() for efficient STATE_DELTA events.

Framework flexibility

Use the Axum integration, or call run_agent() directly and stream it over any HTTP framework.

Two crates, one protocol

A pure data layer you can depend on anywhere, and a runtime for serving it.

ag-ui-protocol

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"

ag-ui-server

Async runtime: Agent trait, lifecycle pipeline, protocol verification, SSE encoding, and an optional Axum integration.

ag-ui-server = { version = "0.1", features = ["axum"] }

Open source, always

ag-ui-rust is free to use, modify, and distribute under the MIT license. Built on Tokio and Serde, with an optional Axum integration.

Rust Tokio Axum Serde JSON Patch
Star on GitHub