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
impl Agent
pub fn builder() -> AgentBuilder
Sourcepub async fn run(
&mut self,
turn: impl Into<Turn>,
) -> Result<RunResult, RunError>
pub async fn run( &mut self, turn: impl Into<Turn>, ) -> Result<RunResult, RunError>
Run one turn: a goal, or a Turn.
Sourcepub async fn run_with_events(
&mut self,
turn: impl Into<Turn>,
on_event: impl FnMut(TurnEvent<'_>),
) -> Result<RunResult, RunError>
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.
Sourcepub fn can_continue(&self) -> bool
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.
Sourcepub async fn continue_turn(&mut self) -> Result<RunResult, RunError>
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.
Sourcepub async fn continue_turn_with_events(
&mut self,
on_event: impl FnMut(TurnEvent<'_>),
) -> Result<RunResult, RunError>
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.
Sourcepub async fn ui_action(&mut self, action: Action) -> Result<RunResult, RunError>
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.
Sourcepub async fn ui_action_with_events(
&mut self,
action: Action,
on_event: impl FnMut(TurnEvent<'_>),
) -> Result<RunResult, RunError>
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.
Sourcepub fn cancel_handle(&self) -> CancelToken
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.
Sourcepub fn conversation(&self) -> &Conversation
pub fn conversation(&self) -> &Conversation
The conversation so far, to read or to save with Conversation::to_json.
Sourcepub fn with_conversation(self, conversation: Conversation) -> Self
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.
Sourcepub fn surfaces(&self) -> Vec<AgentMessage>
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.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session’s id, under which AgentBuilder::memory saves it.
Sourcepub fn secret_names(&self) -> Vec<String>
pub fn secret_names(&self) -> Vec<String>
The names of the secrets held, never their values.
Sourcepub fn notes(&self) -> Vec<String>
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.
Sourcepub fn skills(&self) -> Vec<String>
pub fn skills(&self) -> Vec<String>
The skills Turn::skill can run, in precedence order.
Sourcepub fn specialists(&self) -> Vec<String>
pub fn specialists(&self) -> Vec<String>
The specialists Turn::specialist and delegate can run.
Sourcepub fn tool_names(&self) -> Vec<String>
pub fn tool_names(&self) -> Vec<String>
The names of the tools the model is offered.
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 Agentwhere
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 Agentwhere
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 Agentwhere
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 Agentwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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