Skip to main content

RouterExt

Trait RouterExt 

Source
pub trait RouterExt<S>: Sized {
    // Required method
    fn route_agui_with<A>(self, path: &str, endpoint: AgentEndpoint<A>) -> Self
       where A: Agent + 'static;

    // Provided method
    fn route_agui<A>(self, path: &str, agent: A) -> Self
       where A: Agent + 'static { ... }
}
Expand description

Mounts AG-UI agents on an [axum::Router].

§What it does to the router

route_agui(path, agent) is route(path, post(handler)) and nothing else: the endpoint composes with the router’s other routes, with nest, merge and fallback, and with any layer applied before or after it. A GET on the path still gets axum’s own 405.

§The state parameter

The handler reads only the request, so it is a Handler<_, S> for every router state S. Mounting an agent therefore places no constraint on S beyond axum’s own Clone + Send + Sync + 'static, and works the same in a Router<()> and in a Router<AppState> — including before with_state is called.

An agent that needs values from the router state should capture them when it is constructed (CartAgent::new(state.catalog.clone())). Extracting State inside the AG-UI handler would tie this crate’s one-line mount to a single application’s state type, which is the opposite of what it is for.

Required Methods§

Source

fn route_agui_with<A>(self, path: &str, endpoint: AgentEndpoint<A>) -> Self
where A: Agent + 'static,

Mounts a configured AgentEndpoint as a POST endpoint at path.

Provided Methods§

Source

fn route_agui<A>(self, path: &str, agent: A) -> Self
where A: Agent + 'static,

Mounts agent as a POST endpoint at path.

The endpoint answers with text/event-stream, cancels the run when the client disconnects, and refuses a request it cannot answer with a 4xx.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S> RouterExt<S> for Router<S>
where S: Clone + Send + Sync + 'static,

Source§

fn route_agui_with<A>(self, path: &str, endpoint: AgentEndpoint<A>) -> Self
where A: Agent + 'static,

Implementors§