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 fn can_continue(&self) -> bool

Whether Agent::continue_turn can continue the conversation’s last turn: it stopped before it finished (a provider failure, a tripped limit, a cancel, or a process that ended mid-turn, for a conversation saved with Conversation::to_json or in Memory), nothing was added since, and the skill it ran under is still there.

Source

pub async fn continue_turn(&mut self) -> Result<RunResult, RunError>

Continue the conversation’s unfinished last turn from its last step, with no new message. The turn’s step count, cost, and tool-error streak carry over, so a limit it tripped trips again unless it was raised (with AgentBuilder::on_limit, or a larger budget when the agent is built again). Every side-effecting call goes through the approval gate again, and the model is told that time has passed, so it checks before relying on what it saw. RunError::NotContinuable says why when there is nothing to continue, without calling the model.

Source

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

Agent::continue_turn, reporting each TurnEvent 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
where Arc<dyn Provider>: Send, RawVecInner: Send, BoxRaw<dyn Fn(&str) -> Result<RoutedModel, String> + Sync + Send>: Send, Mutex<HashMap<String, RoutedModel>>: Send, Mutex<Option<RoutedModel>>: Send, Mutex<Option<Worker>>: Send, Mutex<Option<(String, String)>>: Send, Arc<Mutex<Option<String>>>: Send, Arc<RwLock<RegistryInner>>: Send, Arc<Mutex<Connection>>: Send, Arc<dyn Embedder>: Send, Arc<IndexMap<String, Arc<Skill>>>: Send, Arc<Mutex<Option<Arc<Skill>>>>: Send, Arc<Inner>: Send, Arc<dyn EditorFiles>: Send, Arc<Specialties>: Send, Arc<ToolScope>: Send, Arc<FanOut>: Send, Arc<Worktree>: Send, Arc<Card>: Send, Arc<SubagentRun>: Send, Arc<Mutex<Option<Arc<Box<dyn Fn(&Form) -> Reply + Sync + Send>>>>>: Send, Arc<Atomic<bool>>: Send, Arc<Atomic<u64>>: Send, Arc<UiSession>: Send, RawTable<usize>: Send, Mutex<LimitOverrides>: Send, BoxRaw<dyn Fn(&LimitHit) -> Option<u32> + Sync + Send>: Send, Mutex<ApprovalMode>: Send, BoxRaw<dyn Fn(&str, &ApprovalPreview) -> bool + Sync + Send>: Send, BoxRaw<dyn Fn(&ToolCall, &ApprovalPreview) -> bool + Sync + Send>: Send, Arc<QueueInner>: Send, Mutex<Option<Writer>>: Send, RwLock<Option<Arc<dyn Fn(&str, &Map<String, Value>) + Sync + Send>>>: Send, Arc<McpManager>: Send, Arc<CancelInner>: Send, Mutex<Vec<String>>: Send, Mutex<Option<(String, Vec<Arc<Skill>>, Option<f32>, String)>>: Send, Atomic<u64>: Send, Mutex<Option<Arc<dyn Fn(&SubagentEvent<'_>) + Sync + Send>>>: Send, Mutex<HashMap<String, f64>>: Send, Mutex<Option<Verification>>: Send,

§

impl Sync for Agent
where Arc<dyn Provider>: Sync, RawVecInner: Sync, BoxRaw<dyn Fn(&str) -> Result<RoutedModel, String> + Sync + Send>: Sync, Mutex<HashMap<String, RoutedModel>>: Sync, Mutex<Option<RoutedModel>>: Sync, Mutex<Option<Worker>>: Sync, Mutex<Option<(String, String)>>: Sync, Arc<Mutex<Option<String>>>: Sync, Arc<RwLock<RegistryInner>>: Sync, Arc<Mutex<Connection>>: Sync, Arc<dyn Embedder>: Sync, Arc<IndexMap<String, Arc<Skill>>>: Sync, Arc<Mutex<Option<Arc<Skill>>>>: Sync, Arc<Inner>: Sync, Arc<dyn EditorFiles>: Sync, Arc<Specialties>: Sync, Arc<ToolScope>: Sync, Arc<FanOut>: Sync, Arc<Worktree>: Sync, Arc<Card>: Sync, Arc<SubagentRun>: Sync, Arc<Mutex<Option<Arc<Box<dyn Fn(&Form) -> Reply + Sync + Send>>>>>: Sync, Arc<Atomic<bool>>: Sync, Arc<Atomic<u64>>: Sync, Arc<UiSession>: Sync, RawTable<usize>: Sync, Mutex<LimitOverrides>: Sync, BoxRaw<dyn Fn(&LimitHit) -> Option<u32> + Sync + Send>: Sync, Mutex<ApprovalMode>: Sync, BoxRaw<dyn Fn(&str, &ApprovalPreview) -> bool + Sync + Send>: Sync, BoxRaw<dyn Fn(&ToolCall, &ApprovalPreview) -> bool + Sync + Send>: Sync, Arc<QueueInner>: Sync, Mutex<Option<Writer>>: Sync, RwLock<Option<Arc<dyn Fn(&str, &Map<String, Value>) + Sync + Send>>>: Sync, Arc<McpManager>: Sync, Arc<CancelInner>: Sync, Mutex<Vec<String>>: Sync, Mutex<Option<(String, Vec<Arc<Skill>>, Option<f32>, String)>>: Sync, Atomic<u64>: Sync, Mutex<Option<Arc<dyn Fn(&SubagentEvent<'_>) + Sync + Send>>>: Sync, Mutex<HashMap<String, f64>>: Sync, Mutex<Option<Verification>>: Sync,

§

impl Unpin for Agent
where Arc<dyn Provider>: Unpin, *const u8 is !null: Unpin, Box<dyn Fn(&str) -> Result<RoutedModel, String> + Sync + Send>: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, *mut Counter<Channel<Message>>: Unpin, *mut Counter<Channel<Message>>: Unpin, *mut Counter<Channel<Message>>: Unpin, *mut Counter<Channel<()>>: Unpin, *mut Counter<Channel<()>>: Unpin, *mut Counter<Channel<()>>: Unpin, Arc<Mutex<Option<String>>>: Unpin, Arc<RwLock<RegistryInner>>: Unpin, Arc<Mutex<Connection>>: Unpin, Arc<dyn Embedder>: Unpin, Arc<IndexMap<String, Arc<Skill>>>: Unpin, Arc<Mutex<Option<Arc<Skill>>>>: Unpin, Arc<Inner>: Unpin, Arc<dyn EditorFiles>: Unpin, Arc<Specialties>: Unpin, Arc<ToolScope>: Unpin, Arc<FanOut>: Unpin, Arc<Worktree>: Unpin, Arc<Card>: Unpin, Arc<SubagentRun>: Unpin, Arc<Mutex<Option<Arc<Box<dyn Fn(&Form) -> Reply + Sync + Send>>>>>: Unpin, Arc<Atomic<bool>>: Unpin, Arc<Atomic<u64>>: Unpin, Arc<UiSession>: Unpin, Box<dyn Fn(&LimitHit) -> Option<u32> + Sync + Send>: Unpin, Box<dyn Fn(&str, &ApprovalPreview) -> bool + Sync + Send>: Unpin, Box<dyn Fn(&ToolCall, &ApprovalPreview) -> bool + Sync + Send>: Unpin, Arc<QueueInner>: Unpin, I32NotAllOnes: Unpin, Arc<dyn Fn(&str, &Map<String, Value>) + Sync + Send>: Unpin, Arc<McpManager>: Unpin, Arc<CancelInner>: Unpin, Arc<Skill>: Unpin, Align8<u64>: Unpin, Arc<dyn Fn(&SubagentEvent<'_>) + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Agent
where *const ArcInner<dyn Provider> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Provider>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const dyn Fn(&str) -> Result<RoutedModel, String> + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Fn(&str) -> Result<RoutedModel, String> + Sync + Send>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<(String, RoutedModel)>: UnsafeUnpin, *mut Counter<Channel<Message>>: UnsafeUnpin, *mut Counter<Channel<Message>>: UnsafeUnpin, *mut Counter<Channel<Message>>: UnsafeUnpin, *mut Counter<Channel<()>>: UnsafeUnpin, *mut Counter<Channel<()>>: UnsafeUnpin, *mut Counter<Channel<()>>: UnsafeUnpin, *const ArcInner<Mutex<Option<String>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<String>>>>: UnsafeUnpin, *const ArcInner<RwLock<RegistryInner>> is !null: UnsafeUnpin, PhantomData<ArcInner<RwLock<RegistryInner>>>: UnsafeUnpin, PhantomData<PathBuf>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const ArcInner<Mutex<Connection>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Connection>>>: UnsafeUnpin, *const ArcInner<dyn Embedder> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Embedder>>: UnsafeUnpin, *const ArcInner<IndexMap<String, Arc<Skill>>> is !null: UnsafeUnpin, PhantomData<ArcInner<IndexMap<String, Arc<Skill>>>>: UnsafeUnpin, *const ArcInner<Mutex<Option<Arc<Skill>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<Arc<Skill>>>>>: UnsafeUnpin, *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin, *const ArcInner<dyn EditorFiles> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn EditorFiles>>: UnsafeUnpin, *const ArcInner<Specialties> is !null: UnsafeUnpin, PhantomData<ArcInner<Specialties>>: UnsafeUnpin, *const ArcInner<ToolScope> is !null: UnsafeUnpin, PhantomData<ArcInner<ToolScope>>: UnsafeUnpin, *const ArcInner<FanOut> is !null: UnsafeUnpin, PhantomData<ArcInner<FanOut>>: UnsafeUnpin, *const ArcInner<Worktree> is !null: UnsafeUnpin, PhantomData<ArcInner<Worktree>>: UnsafeUnpin, *const ArcInner<Card> is !null: UnsafeUnpin, PhantomData<ArcInner<Card>>: UnsafeUnpin, *const ArcInner<SubagentRun> is !null: UnsafeUnpin, PhantomData<ArcInner<SubagentRun>>: UnsafeUnpin, *const ArcInner<Mutex<Option<Arc<Box<dyn Fn(&Form) -> Reply + Sync + Send>>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<Arc<Box<dyn Fn(&Form) -> Reply + Sync + Send>>>>>>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin, *const ArcInner<Atomic<u64>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<u64>>>: UnsafeUnpin, *const ArcInner<UiSession> is !null: UnsafeUnpin, PhantomData<ArcInner<UiSession>>: UnsafeUnpin, PhantomData<ToolCall>: UnsafeUnpin, *const dyn Fn(&LimitHit) -> Option<u32> + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Fn(&LimitHit) -> Option<u32> + Sync + Send>: UnsafeUnpin, *const dyn Fn(&str, &ApprovalPreview) -> bool + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Fn(&str, &ApprovalPreview) -> bool + Sync + Send>: UnsafeUnpin, *const dyn Fn(&ToolCall, &ApprovalPreview) -> bool + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Fn(&ToolCall, &ApprovalPreview) -> bool + Sync + Send>: UnsafeUnpin, *const ArcInner<QueueInner> is !null: UnsafeUnpin, PhantomData<ArcInner<QueueInner>>: UnsafeUnpin, I32NotAllOnes: UnsafeUnpin, *const ArcInner<dyn Fn(&str, &Map<String, Value>) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&str, &Map<String, Value>) + Sync + Send>>: UnsafeUnpin, *const ArcInner<McpManager> is !null: UnsafeUnpin, PhantomData<ArcInner<McpManager>>: UnsafeUnpin, *const ArcInner<CancelInner> is !null: UnsafeUnpin, PhantomData<ArcInner<CancelInner>>: UnsafeUnpin, PhantomData<Arc<Skill>>: UnsafeUnpin, Align8<u64>: UnsafeUnpin, *const ArcInner<dyn Fn(&SubagentEvent<'_>) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&SubagentEvent<'_>) + Sync + Send>>: UnsafeUnpin, PhantomData<(String, f64)>: UnsafeUnpin, PhantomData<Message>: UnsafeUnpin, PhantomData<Step>: UnsafeUnpin,

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