pub struct Agent { /* private fields */ }Expand description
An agent is configuration: a stable id, a model, instructions, tools and hooks. It holds no per-run state, is cheap to clone, and can run many sessions concurrently.
Implementations§
Source§impl Agent
impl Agent
pub fn builder(id: impl Into<String>) -> AgentBuilder
pub fn id(&self) -> &str
pub fn tool_specs(&self) -> &[ToolSpec]
pub fn limits(&self) -> &Limits
Sourcepub fn redaction_scope(&self) -> &RedactionScope
pub fn redaction_scope(&self) -> &RedactionScope
The registered secrets this agent’s runs redact
(AgentBuilder::redaction_scope).
Sourcepub fn with_limits(&self, limits: Limits) -> Agent
pub fn with_limits(&self, limits: Limits) -> Agent
A copy of this agent with different limits (same id, tools, hooks). Used to give a child agent its own budget.
Sourcepub fn with_hook(&self, hook: impl Hook + 'static) -> Agent
pub fn with_hook(&self, hook: impl Hook + 'static) -> Agent
A copy of this agent with one more hook, run after the existing ones.
Sourcepub async fn run(
&self,
session_id: &str,
input: impl Into<Message>,
) -> Result<RunOutcome, CoreError>
pub async fn run( &self, session_id: &str, input: impl Into<Message>, ) -> Result<RunOutcome, CoreError>
Start a new run in session_id with one user message: text, or a
crate::Message built with Message::user(..).with_images(..).
pub async fn run_with_cancel( &self, session_id: &str, input: impl Into<Message>, cancel: CancellationToken, ) -> Result<RunOutcome, CoreError>
Sourcepub async fn run_from(
&self,
state: RunState,
cancel: CancellationToken,
) -> Result<RunOutcome, CoreError>
pub async fn run_from( &self, state: RunState, cancel: CancellationToken, ) -> Result<RunOutcome, CoreError>
Continue from saved state that is not interrupted, typically
previous.state.with_user_message("next question").
Sourcepub async fn run_resolving(
&self,
state: RunState,
cancel: CancellationToken,
resolver: &dyn InterruptResolver,
) -> Result<RunOutcome, CoreError>
pub async fn run_resolving( &self, state: RunState, cancel: CancellationToken, resolver: &dyn InterruptResolver, ) -> Result<RunOutcome, CoreError>
Like Agent::run_from, but settles each interruption with
resolver and continues, until the run ends or the resolver returns
None (the interrupted outcome is then returned as is). It has no
iteration cap of its own: a resolver that keeps resolving is bounded
by the run’s limits (turns, tool calls, tokens).
Hooks see one run end (Hook::on_run_end), for the final outcome;
the interruptions settled on the way are not run ends.
Sourcepub async fn end_in_flight(
&self,
state: RunState,
) -> Result<RunOutcome, CoreError>
pub async fn end_in_flight( &self, state: RunState, ) -> Result<RunOutcome, CoreError>
End a run a crash or restart left mid tool batch without running
anything more: unlike Agent::run_from, no call is re-run and no
model call is made. A call that had started gets an
crate::ReceiptStatus::Indeterminate receipt, one that never
started a crate::ReceiptStatus::Cancelled one, and the run ends
RunStatus::Cancelled. A state that is not in flight just ends.
Sourcepub async fn resume_resolving(
&self,
state: RunState,
resolution: Resolution,
cancel: CancellationToken,
resolver: &dyn InterruptResolver,
) -> Result<RunOutcome, CoreError>
pub async fn resume_resolving( &self, state: RunState, resolution: Resolution, cancel: CancellationToken, resolver: &dyn InterruptResolver, ) -> Result<RunOutcome, CoreError>
Like Agent::resume_with_cancel, but settles each later
interruption with resolver, as Agent::run_resolving does.
Sourcepub async fn resume(
&self,
state: RunState,
resolution: Resolution,
) -> Result<RunOutcome, CoreError>
pub async fn resume( &self, state: RunState, resolution: Resolution, ) -> Result<RunOutcome, CoreError>
Settle the interruption in state and keep going. state may come
from another process: it is plain data. A run paused for a child
(crate::Pending::child) passes the answer down to the run that is
waiting, at any depth; RunState::waiting_run says which that is.
pub async fn resume_with_cancel( &self, state: RunState, resolution: Resolution, cancel: CancellationToken, ) -> Result<RunOutcome, CoreError>
Trait Implementations§
Source§impl AgentStructuredExt for Agent
impl AgentStructuredExt for Agent
Source§async fn run_typed<T>(
&self,
session_id: &str,
input: impl Into<Message> + Send,
) -> Result<TypedOutcome<T>, StructuredError>
async fn run_typed<T>( &self, session_id: &str, input: impl Into<Message> + Send, ) -> Result<TypedOutcome<T>, StructuredError>
Agent::run, with the final answer read as T (one repair
attempt). Tools still run as usual; only the final answer must match.Source§async fn run_typed_from<T>(
&self,
state: RunState,
cancel: CancellationToken,
) -> Result<TypedOutcome<T>, StructuredError>
async fn run_typed_from<T>( &self, state: RunState, cancel: CancellationToken, ) -> Result<TypedOutcome<T>, StructuredError>
Agent::run_from (a saved, not interrupted state), typed.Source§async fn resume_typed<T>(
&self,
state: RunState,
resolution: Resolution,
) -> Result<TypedOutcome<T>, StructuredError>
async fn resume_typed<T>( &self, state: RunState, resolution: Resolution, ) -> Result<TypedOutcome<T>, StructuredError>
Agent::resume for a run started with
AgentStructuredExt::run_typed, typed. May end
StructuredError::NotFinished again at the next interruption.Source§async fn finish_typed<T>(
&self,
outcome: RunOutcome,
) -> Result<TypedOutcome<T>, StructuredError>
async fn finish_typed<T>( &self, outcome: RunOutcome, ) -> Result<TypedOutcome<T>, StructuredError>
T, with one repair attempt.Auto Trait Implementations§
impl !RefUnwindSafe for Agent
impl !UnwindSafe for Agent
impl Forget for Agent
impl Freeze for Agent
impl Move for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl UnsafeUnpin for Agentwhere
*const ArcInner<AgentInner> is !null: UnsafeUnpin,
PhantomData<ArcInner<AgentInner>>: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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