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(15));

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

See SseResponse::keep_alive. Off by default.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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