Skip to main content

AgentEndpoint

Struct AgentEndpoint 

Source
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>

Source

pub fn new(agent: A) -> Self

Wraps an agent with the default settings.

Source

pub fn on_input_warnings<F>(self, hook: F) -> Self
where F: Fn(&RunAgentInput, &[String]) + Send + Sync + 'static,

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);
    }
});
Source

pub fn transformer<F, T>(self, factory: F) -> Self
where F: Fn() -> T + Send + Sync + 'static, T: StreamTransformer + 'static,

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<A> Debug for AgentEndpoint<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Describes the settings, not the agent: an agent holds an LLM client and a database handle, and neither is Debug.

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for AgentEndpoint<A>

§

impl<A> !UnwindSafe for AgentEndpoint<A>

§

impl<A> Freeze for AgentEndpoint<A>

§

impl<A> Send for AgentEndpoint<A>
where A: Sync + Send,

§

impl<A> Sync for AgentEndpoint<A>
where A: Sync + Send,

§

impl<A> Unpin for AgentEndpoint<A>

§

impl<A> UnsafeUnpin for AgentEndpoint<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more