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
impl AgentRun
Sourcepub async fn new(
persona: &Persona,
input: Vec<Message>,
limits: Limits,
io: &dyn AgentIo,
) -> Result<AgentRun, AgentError>
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.
Sourcepub fn from_checkpoint(cp: &Checkpoint) -> Result<AgentRun, AgentError>
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.
Sourcepub fn checkpoint(&self) -> Checkpoint
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.
Sourcepub fn retries(&self) -> u32
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.
Sourcepub fn retry_at_ms(&self) -> Option<i64>
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.
Sourcepub fn set_retry_at_ms(&mut self, at_ms: Option<i64>)
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.
Sourcepub fn host_failed(&self) -> bool
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.
Sourcepub fn run_id(&self) -> RunId
pub fn run_id(&self) -> RunId
Returns the run’s id. Every event and checkpoint of the run carries it. It never changes.
Sourcepub fn state(&self) -> &RunState
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.
Sourcepub fn messages(&self) -> &[Message]
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.
Sourcepub fn usage(&self) -> Usage
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.
Sourcepub fn model_calls(&self) -> u32
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.
Sourcepub fn persona(&self) -> &str
pub fn persona(&self) -> &str
Returns the persona name the run was started with. Hosts compare it before resuming a checkpoint. It never changes.
Sourcepub fn tighten(&mut self, limits: &Limits)
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.
Sourcepub fn resume(&mut self, limits: Limits) -> Result<(), AgentError>
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.
Sourcepub fn set_trace(&mut self, spec: TraceSpec)
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.
Sourcepub fn trace(&self) -> Option<TraceSpec>
pub fn trace(&self) -> Option<TraceSpec>
Returns the trace spec set with set_trace, if any.
Input: none. Output: the spec.
Sourcepub async fn step(&mut self, io: &dyn AgentIo) -> StepOutcome
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.