pub struct RunState {Show 15 fields
pub run_id: RunId,
pub agent_id: String,
pub session_id: String,
pub messages: Vec<Message>,
pub receipts: Vec<Receipt>,
pub usage: Usage,
pub run_usage: Usage,
pub turn: u32,
pub tool_calls: u32,
pub elapsed_ms: u64,
pub pending: Option<Pending>,
pub untrusted_seen: bool,
pub declined: Vec<EffectKey>,
pub unmet: Vec<String>,
pub parent_run: Option<RunId>,
/* private fields */
}Expand description
Everything needed to continue a run, as plain serializable data.
Persist it anywhere (a database row, a file, a queue message) and hand it
to crate::Agent::resume later. Agents are matched by their stable
agent_id, never by position or display name.
Fields§
§run_id: RunId§agent_id: String§session_id: String§messages: Vec<Message>Transcript without the agent’s instructions (those are re-sent on every request).
receipts: Vec<Receipt>Receipts of every run in this session. Each carries its run_id;
use RunState::run_receipts for the current run only.
usage: UsageToken usage of every run in this session.
run_usage: UsageToken usage of the current run only. Budgets in crate::Limits
are checked against this, like turn and tool_calls.
turn: u32§tool_calls: u32§elapsed_ms: u64Wall-clock time already spent, summed across resumes.
pending: Option<Pending>§untrusted_seen: boolThe run has seen untrusted content (a dispatched call whose result was authored by someone else, whatever its status), or was seeded that way. Never cleared within a run.
declined: Vec<EffectKey>Effects the owner declined in this run (deduplicated). The kernel
records a denied InterruptKind::OwnerApproval request’s effects
here; hooks read them through crate::HookContext::declined. A new
run (RunState::with_user_message) starts with none.
unmet: Vec<String>Requirements stop hooks reported as unmet when the run stopped
(crate::StopDecision::AcceptUnmet), deduplicated, in hook order.
Set only when the run ends Completed; a new run
(RunState::with_user_message) starts with none.
parent_run: Option<RunId>The run whose tool call started this one, if any.
Implementations§
Source§impl RunState
impl RunState
Sourcepub fn new(agent_id: &str, session_id: &str, input: impl Into<Message>) -> Self
pub fn new(agent_id: &str, session_id: &str, input: impl Into<Message>) -> Self
A fresh state for a new run, so callers know the run id before it
starts. Run it with crate::Agent::run_from.
input is text or a user Message (for example one with images).
Sourcepub fn with_parent(self, parent: RunId) -> Self
pub fn with_parent(self, parent: RunId) -> Self
Record the run whose tool call started this one.
Sourcepub fn with_untrusted_context(self) -> Self
pub fn with_untrusted_context(self) -> Self
Start the run as if it had already read untrusted content (the caller knows the input itself is someone else’s).
Sourcepub fn with_user_message(self, input: impl Into<Message>) -> Self
pub fn with_user_message(self, input: impl Into<Message>) -> Self
Continue an earlier, finished run with a new user message (same
session, new run). Session receipts and usage keep accumulating;
per-run counters and budgets (turn, tool_calls, run_usage,
elapsed time) start again from zero, and the run’s
RunState::declined effects and RunState::unmet requirements
are forgotten, as is any SharedDeclines set: the new run shares
only a set attached to it.
Share this run’s declines with the other runs holding declines
(see SharedDeclines): each is refused the others’ declined
effects from its next call on. The run’s own declines are published
at once and the set’s are taken in. Attach it again after resuming
saved state: the handle is not serialized.
The decline set this run shares, if any.
Sourcepub fn waiting_run(&self) -> Option<&RunState>
pub fn waiting_run(&self) -> Option<&RunState>
The run actually waiting for an answer: this one, or the child it is
paused for, at any depth. None when this run is not interrupted.
Sourcepub fn run_receipts(&self) -> impl Iterator<Item = &Receipt>
pub fn run_receipts(&self) -> impl Iterator<Item = &Receipt>
Receipts produced by the current run (not earlier runs in the session).