Skip to main content

RunState

Struct RunState 

Source
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: Usage

Token usage of every run in this session.

§run_usage: Usage

Token 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: u64

Wall-clock time already spent, summed across resumes.

§pending: Option<Pending>§untrusted_seen: bool

The 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

Source

pub fn new( agent_id: &str, session_id: &str, input: impl Into<Message>, ) -> RunState

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

Source

pub fn with_parent(self, parent: RunId) -> RunState

Record the run whose tool call started this one.

Source

pub fn with_untrusted_context(self) -> RunState

Start the run as if it had already read untrusted content (the caller knows the input itself is someone else’s).

Source

pub fn with_user_message(self, input: impl Into<Message>) -> RunState

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.

Source

pub fn share_declines(self, declines: SharedDeclines) -> RunState

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.

Source

pub fn shared_declines(&self) -> Option<&SharedDeclines>

The decline set this run shares, if any.

Source

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.

Source

pub fn schema(&self) -> u32

The serialization format version this state was written with.

Source

pub fn run_receipts(&self) -> impl Iterator<Item = &Receipt>

Receipts produced by the current run (not earlier runs in the session).

Trait Implementations§

Source§

impl Clone for RunState

Source§

fn clone(&self) -> RunState

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 RunState

Source§

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

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

impl<'de> Deserialize<'de> for RunState

Source§

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

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

impl PartialEq for RunState

Source§

fn eq(&self, other: &RunState) -> 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 RunState

Source§

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

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

impl StructuralPartialEq for RunState

Auto Trait Implementations§

§

impl Forget for RunState

§

impl Freeze for RunState

§

impl Move for RunState

§

impl RefUnwindSafe for RunState

§

impl Send for RunState
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, BoxRaw<ApprovalCard>: Send, BoxRaw<RunState>: Send, Arc<Mutex<Vec<EffectKey>>>: Send, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Send, BoxRaw<(String, SetValZST)>: Send,

§

impl Sync for RunState
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, BoxRaw<ApprovalCard>: Sync, BoxRaw<RunState>: Sync, Arc<Mutex<Vec<EffectKey>>>: Sync, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Sync, BoxRaw<(String, SetValZST)>: Sync,

§

impl Unpin for RunState
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<ApprovalCard>: Unpin, Box<RunState>: Unpin, Arc<Mutex<Vec<EffectKey>>>: Unpin, *const LeafNode<String, SetValZST> is !null: Unpin, Box<(String, SetValZST)>: Unpin,

§

impl UnsafeUnpin for RunState

§

impl UnwindSafe for RunState

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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