Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

An agent: a harness and its conversation. Each Agent::run is one turn that continues the conversation.

Implementations§

Source§

impl Agent

Source

pub fn builder() -> AgentBuilder

Source

pub async fn run( &mut self, turn: impl Into<Turn>, ) -> Result<RunResult, RunError>

Run one turn: a goal, or a Turn.

Source

pub async fn run_with_events( &mut self, turn: impl Into<Turn>, on_event: impl FnMut(TurnEvent<'_>), ) -> Result<RunResult, RunError>

Agent::run, reporting each TurnEvent (text, reasoning, tool calls and their results, usage) as it happens.

Source

pub async fn ui_action(&mut self, action: Action) -> Result<RunResult, RunError>

Hand the model what the user did on a surface (a button pressed), when no render_ui call was waiting for it: it becomes the next user message, [ui action] <name> on <surfaceId>: <context as JSON> (plus the event’s userMessage on its own line), and runs a turn as Agent::run does, through the vault and the ingress guardrail like typed input. Recorded as ui_action, without its values. Call it after the turn that drew the surface has ended; actions taken during a turn wait for it, as typed input does.

Source

pub async fn ui_action_with_events( &mut self, action: Action, on_event: impl FnMut(TurnEvent<'_>), ) -> Result<RunResult, RunError>

Agent::ui_action, reporting each TurnEvent as it happens.

Source

pub fn cancel_handle(&self) -> CancelToken

A handle that stops the running turn at its next safe point (before a model call, while streaming, or between tool calls), from any thread.

Source

pub fn conversation(&self) -> &Conversation

The conversation so far, to read or to save with Conversation::to_json.

Source

pub fn with_conversation(self, conversation: Conversation) -> Self

Continue an earlier conversation instead of starting a new one. With agent86UI, the surfaces are rebuilt from its render_ui calls, as on resuming a session; Agent::surfaces gives them to draw.

Source

pub fn surfaces(&self) -> Vec<AgentMessage>

Every surface up now, each as the one createSurface message that draws it as it is (its components and data model), in surface id order. After resuming a session (AgentBuilder::session or Agent::with_conversation) the surfaces are rebuilt from the history’s render_ui calls, so a program that reopens draws these to show the user where they were. What the user typed but never submitted is the renderer’s alone, so it is not here. Empty without a renderer.

Source

pub fn session_id(&self) -> &str

The session’s id, under which AgentBuilder::memory saves it.

Source

pub fn secret_names(&self) -> Vec<String>

The names of the secrets held, never their values.

Source

pub fn notes(&self) -> Vec<String>

What is worth telling the user, oldest first: specialist files that were skipped, what the MCP servers reported (a server that dropped, reconnected, or changed its tools), and why spans could not be exported.

Source

pub fn skills(&self) -> Vec<String>

The skills Turn::skill can run, in precedence order.

Source

pub fn specialists(&self) -> Vec<String>

The specialists Turn::specialist and delegate can run.

Source

pub fn tool_names(&self) -> Vec<String>

The names of the tools the model is offered.

Source

pub fn harness(&self) -> &Harness

The harness underneath, for what this module does not cover yet. Its API makes no stability promise.

Auto Trait Implementations§

§

impl !Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Forget for Agent

§

impl Move for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

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