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.