Skip to main content

Agent

Struct Agent 

Source
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

Source

pub fn builder(id: impl Into<String>) -> AgentBuilder

Source

pub fn id(&self) -> &str

Source

pub fn tool_specs(&self) -> &[ToolSpec]

Source

pub fn limits(&self) -> &Limits

Source

pub fn redaction_scope(&self) -> &RedactionScope

The registered secrets this agent’s runs redact (AgentBuilder::redaction_scope).

Source

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.

Source

pub fn with_hook(&self, hook: impl Hook + 'static) -> Agent

A copy of this agent with one more hook, run after the existing ones.

Source

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(..).

Source

pub async fn run_with_cancel( &self, session_id: &str, input: impl Into<Message>, cancel: CancellationToken, ) -> Result<RunOutcome, CoreError>

Source

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").

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn resume_with_cancel( &self, state: RunState, resolution: Resolution, cancel: CancellationToken, ) -> Result<RunOutcome, CoreError>

Trait Implementations§

Source§

impl Clone for Agent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.