Skip to main content

AgentRun

Struct AgentRun 

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

One agent run as plain serializable data: the persona snapshot, the conversation, the state, counters, usage and the event sequence. The host calls step and saves checkpoint() after every step.

Implementations§

Source§

impl AgentRun

Source

pub async fn new( persona: &Persona, input: Vec<Message>, limits: Limits, io: &dyn AgentIo, ) -> Result<AgentRun, AgentError>

Starts a run of persona on input under limits tightened by the persona budget. Checks before any model call that every tool, eval and model it names is available in io; returns Setup naming the file.

Source

pub fn from_checkpoint(cp: &Checkpoint) -> Result<AgentRun, AgentError>

Restores a run from cp. Returns Checkpoint when the state does not parse, has unknown fields, has another RUN_FORMAT, or does not match the checkpoint’s run id and step.

Source

pub fn checkpoint(&self) -> Checkpoint

Snapshots the run for a CheckpointStore: step 0 before the first step, then one more after each step, whatever its outcome. Returns the checkpoint.

Source

pub fn retries(&self) -> u32

Returns how many steps of this run ended in Retry, over its whole life: the count is saved in every checkpoint, so a host’s retry cap holds across resumes. Checkpoints from before the field load as 0.

Source

pub fn retry_at_ms(&self) -> Option<i64>

Returns when the host may step again after a Retry, in Unix milliseconds on the io clock, as set by set_retry_at_ms. None when no wait is pending. Saved in every checkpoint, so a wait holds across resumes; checkpoints from before the field load None.

Source

pub fn set_retry_at_ms(&mut self, at_ms: Option<i64>)

Records the retry wait the host chose after a Retry outcome, or clears it with None. Input: Unix milliseconds on the io clock. Output: none. The run never reads it; the host honors it.

Source

pub fn host_failed(&self) -> bool

Whether a host model failed this run in its own callback: its model call ended in ProviderErrorKind::Host. Set from the error kind, never from its text, and saved in every checkpoint.

Source

pub fn run_id(&self) -> RunId

Returns the run’s id. Every event and checkpoint of the run carries it. It never changes.

Source

pub fn state(&self) -> &RunState

Returns the current state. Hosts read it to show progress or the final output. It changes only in step and resume.

Source

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

Returns the conversation so far: input, replies, tool results and repair requests, in order. The system prompt is not part of it.

Source

pub fn usage(&self) -> Usage

Returns tokens and cost of every model call so far. Judge calls are included; costs use the handle’s price. Compare it with the run budget.

Source

pub fn model_calls(&self) -> u32

Returns how many agent model calls ran. This is the count max_turns caps; the repair call counts, judge calls do not.

Source

pub fn persona(&self) -> &str

Returns the persona name the run was started with. Hosts compare it before resuming a checkpoint. It never changes.

Source

pub fn tighten(&mut self, limits: &Limits)

Tightens the run’s limits with limits, each layer the stricter of the two (see Limits::stricter). A period limit with a different key replaces the saved one, moving the run to the host’s current ledger, and is not a tightening. Input: the limits. Output: none.

Source

pub fn resume(&mut self, limits: Limits) -> Result<(), AgentError>

Leaves a pause with new limits (for example after an owner raised a budget), back in the state that paused. The next step checks the budget again. Returns Setup when the run is not paused.

Source

pub fn set_trace(&mut self, spec: TraceSpec)

Traces this run with spec from its next step on; the spec is kept in the checkpoint, so a resumed run keeps it. Input: the spec. Output: none.

Source

pub fn trace(&self) -> Option<TraceSpec>

Returns the trace spec set with set_trace, if any. Input: none. Output: the spec.

Source

pub async fn step(&mut self, io: &dyn AgentIo) -> StepOutcome

Runs one step: one model call, one tool batch, one output check or one repair prompt, emitting its events through io. Final and paused runs return their outcome again and change nothing. With a trace spec the step nests in the active scope, keeping content only when both the scope and the spec keep it, or writes its trace file.

Trait Implementations§

Source§

impl Clone for AgentRun

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

impl Debug for AgentRun

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentRun

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for AgentRun

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for AgentRun

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AgentRun

Auto Trait Implementations§

§

impl Forget for AgentRun

§

impl Freeze for AgentRun

§

impl Move for AgentRun

§

impl RefUnwindSafe for AgentRun

§

impl Send for AgentRun
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, BoxRaw<RunState>: Send,

§

impl Sync for AgentRun
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, BoxRaw<RunState>: Sync,

§

impl Unpin for AgentRun
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<RunState>: Unpin,

§

impl UnsafeUnpin for AgentRun

§

impl UnwindSafe for AgentRun
where RawVecInner: UnwindSafe, BTreeMap<String, Value>: UnwindSafe, BoxRaw<RunState>: UnwindSafe,

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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