Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

Running or persisted agent managed by a crate::Runtime.

Implementations§

Source§

impl Agent

Source

pub async fn send( &mut self, content: impl Into<Vec<ContentBlock>>, ) -> Result<Message, RuntimeError>

Sends a user turn using default run options.

Source

pub async fn resume(&mut self) -> Result<Message, RuntimeError>

Replays the most recent failed or interrupted user turn using default run options.

Source

pub async fn resume_with_options( &mut self, options: RunOptions, ) -> Result<Message, RuntimeError>

Replays the most recent failed or interrupted user turn with explicit execution options.

Source

pub async fn run( &mut self, content: impl Into<Vec<ContentBlock>>, options: RunOptions, ) -> Result<Message, RuntimeError>

Runs a user turn with explicit execution limits and cancellation settings.

Source§

impl Agent

Source

pub fn steering_handle(&self) -> SteeringHandle

Returns an agent-scoped handle suitable for use while run(&mut self) holds the mutable agent borrow.

Source

pub fn steer(&self, content: impl Into<Vec<ContentBlock>>)

Idle convenience for enqueueing a steer on this agent.

Source

pub fn follow_up(&self, content: impl Into<Vec<ContentBlock>>)

Idle convenience for enqueueing a would-stop follow-up on this agent.

Source

pub async fn run_queued( &mut self, options: RunOptions, ) -> Result<Message, RuntimeError>

Starts an idle run from the next queued steer.

This is the only automatic consumption point for a steer while no run is active. Follow-ups remain reserved for a running turn’s would-stop boundary. A failed run prepends the consumed entry back onto the queue.

Source§

impl Agent

Source

pub fn task_board(&self) -> TaskBoard

Returns a task-board view with this agent’s own access identity.

Lead agents retain lead privileges. Teammates remain constrained to their own tasks and cannot edit dependency edges. Task-board mutations update the shared store immediately; this agent’s cached snapshot is refreshed at the next normal task refresh/run boundary.

Source§

impl Agent

Source

pub async fn spawn_teammate( &mut self, name: impl Into<String>, role: impl Into<String>, prompt: Option<String>, ) -> Result<TeamMemberSummary, RuntimeError>

Source

pub fn send_team_message( &self, to: &str, content: impl Into<String>, ) -> Result<TeamDispatch, RuntimeError>

Source

pub fn broadcast_team_message( &self, content: impl Into<String>, ) -> Result<Vec<TeamDispatch>, RuntimeError>

Source

pub fn read_team_inbox(&self) -> Result<Vec<TeamMessage>, RuntimeError>

Source

pub fn request_team_protocol( &self, to: &str, protocol: impl Into<String>, content: impl Into<String>, ) -> Result<TeamProtocolRequestSummary, RuntimeError>

Source

pub fn respond_team_protocol( &self, request_id: &str, approve: bool, reason: Option<String>, ) -> Result<TeamProtocolRequestSummary, RuntimeError>

Source§

impl Agent

Source

pub async fn run_to_output<T: DeserializeOwned>( &mut self, content: impl Into<Vec<ContentBlock>>, options: RunOptions, spec: TerminalOutputSpec, ) -> Result<FinalOutput<T>, RuntimeError>

Runs until a generated, agent-scoped terminal tool returns a typed value.

The helper does not use provider-level response_format. It exposes only one forced terminal tool during this run, preserves the tool input as transcript details, and extracts it by the exact tool_use_id from the newly committed final transcript item. Internally a terminal run commits successfully but Agent::run reports RuntimeError::EmptyAssistantResponse because the final message is a user-role tool result; this helper accepts that error only when the expected new detail is present.

Source§

impl Agent

Source

pub fn wait_handle(&self) -> AgentWaitHandle

Returns a cloneable observation handle that does not borrow this agent.

Source

pub fn wait_for_snapshot<P>( &self, predicate: P, ) -> AgentWaitFuture<AgentSnapshot>
where P: Fn(&AgentSnapshot) -> bool + Send + 'static,

Owned-future convenience for AgentWaitHandle::wait_for_snapshot.

Source

pub fn wait_until_idle(&self) -> AgentWaitFuture<AgentSnapshot>

Owned-future convenience for AgentWaitHandle::wait_until_idle.

Source

pub fn wait_for_teammate_reply( &self, ) -> AgentWaitFuture<Result<Vec<TeamMessage>, RuntimeError>>

Owned-future convenience for AgentWaitHandle::wait_for_teammate_reply.

Source§

impl Agent

Source

pub fn name(&self) -> &str

Returns the agent’s display name.

Source

pub fn id(&self) -> &str

Returns the stable persisted agent identifier.

Source

pub fn model(&self) -> &str

Returns the model identifier used by the agent.

Source

pub fn set_model(&mut self, model: ModelInfo) -> Result<(), RuntimeError>

Updates the model and provider used for future turns, then persists the new agent record so resumed sessions continue with the same setting.

Source

pub fn set_reasoning( &mut self, reasoning: Option<ReasoningOptions>, ) -> Result<(), RuntimeError>

Updates the reasoning options requested on future turns, then persists the agent record so resumed sessions continue with the same setting.

Mirrors set_model: a stateful override threaded into every subsequent model request (the runner reads config.provider_request_options.reasoning live). It composes with set_model for per-phase tiering — e.g. run the gather rounds at a low reasoning effort, then raise the effort (and switch to a stronger model) for a final synthesis turn on the same agent, without re-spawning and losing the gathered context. None clears any configured reasoning, restoring the provider’s default effort.

Source

pub fn config(&self) -> &AgentConfig

Returns the effective agent configuration.

Source

pub fn history(&self) -> &[Message]

Returns the committed transcript history.

Source

pub fn transcript(&self) -> &AgentTranscript

Returns the canonical transcript items stored for this agent.

Source

pub fn leaf(&self) -> Option<&EntryId>

The transcript entry the next turn will continue from.

Source

pub fn branch_from(&mut self, entry: &EntryId) -> Result<usize, RuntimeError>

Returns to an earlier entry, so the next turn explores a new path from there.

The abandoned entries stay in the transcript, reachable through children — nothing is deleted, so the path just left can be returned to the same way. Returns how many entries left the active path.

Source

pub fn children(&self, entry: &EntryId) -> Vec<&TranscriptItem>

The entries recorded as continuing from entry. More than one means the conversation branched there.

Source

pub fn is_teammate(&self) -> bool

Returns whether this agent is a persistent teammate rather than the lead agent.

Source

pub fn last_message(&self) -> Option<&Message>

Returns the most recent committed message, if any.

Source

pub fn subscribe_events(&self) -> Receiver<AgentEvent>

Subscribes to the agent’s transient event stream.

Source

pub fn watch_snapshot(&self) -> Receiver<AgentSnapshot>

Watches the current agent snapshot for state updates.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Freeze 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more