pub struct AgentEndpoint<A> { /* private fields */ }Expand description
An agent plus the per-run settings it is served with.
route_agui mounts an agent with the defaults;
build one of these and use route_agui_with
when you want to change them.
use ag_ui::axum::{AgentEndpoint, RouterExt};
use ag_ui::server::FilterToolCalls;
use axum::Router;
use std::time::Duration;
let endpoint = AgentEndpoint::new(CartAgent)
.transformer(|| FilterToolCalls::deny(["internal_debug"]))
.keep_alive(Duration::from_secs(10));
let app: Router = Router::new().route_agui_with("/agent", endpoint);Implementations§
Source§impl<A> AgentEndpoint<A>
impl<A> AgentEndpoint<A>
Sourcepub fn on_input_warnings<F>(self, hook: F) -> Self
pub fn on_input_warnings<F>(self, hook: F) -> Self
Hands each request’s decoding warnings to hook, with the input they
came from, before the run starts.
A warning says what decoding removed or read as omitted: an
unrecognised field or enum member, a deprecated optional null. It
quotes at most 64 characters of the body, with control characters
escaped. The hook is called only for a request that has any. Without
one the warnings are discarded; the endpoint never prints them.
use ag_ui::axum::AgentEndpoint;
let endpoint = AgentEndpoint::new(CartAgent).on_input_warnings(|input, warnings| {
for warning in warnings {
// Route it wherever the application logs.
let _ = (&input.run_id, warning);
}
});Sourcepub fn transformer<F, T>(self, factory: F) -> Self
pub fn transformer<F, T>(self, factory: F) -> Self
Appends a transformer to every run’s chain.
§Why a closure and not a transformer
A StreamTransformer takes &mut self because a useful one is a
state machine — FilterToolCalls
remembers which call ids it dropped. One instance shared across
concurrent runs would leak one run’s state into another, so the endpoint
stores the recipe and builds a fresh chain per request.
Sourcepub fn echo_input(self, echo: bool) -> Self
pub fn echo_input(self, echo: bool) -> Self
Echoes the request body back on RUN_STARTED.
See Runner::echo_input. Off by default — it is the largest payload
in the protocol.
Sourcepub fn keep_alive(self, interval: Duration) -> Self
pub fn keep_alive(self, interval: Duration) -> Self
Sends an SSE comment whenever a run produces nothing for interval.
Defaults to 15 seconds. Comments keep idle connections active without
creating AG-UI events. Set an interval below your proxy’s idle timeout.
See SseResponse::keep_alive and Self::without_keep_alive.
Sourcepub fn without_keep_alive(self) -> Self
pub fn without_keep_alive(self) -> Self
Disables the default SSE keep-alive comments.
Use this when the hosting infrastructure already sends heartbeats or
an endpoint needs to stay completely silent between protocol events.
Calling Self::keep_alive afterwards enables comments again.
Sourcepub fn event_buffer_capacity(self, capacity: NonZeroUsize) -> Self
pub fn event_buffer_capacity(self, capacity: NonZeroUsize) -> Self
Limits each run’s queued events. See
Runner::event_buffer_capacity.
Overflow produces an EVENT_BUFFER_FULL terminal error; callers using
durable execution can reconnect from their application’s saved state.
Sourcepub fn allow_missing_content_type(self) -> Self
pub fn allow_missing_content_type(self) -> Self
Reads a request that carries no Content-Type as JSON, instead of
refusing it with 415.
For clients that send no header and cannot be changed to. Off by
default, and turning it on gives up what requiring a JSON media type
buys — see AgUiInput.
A header that names something other than JSON is refused either way.