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 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 Agent
impl Sync for Agent
impl Unpin for Agent
impl UnsafeUnpin for Agent
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