Skip to main content

RunContext

Struct RunContext 

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

Run-scoped workspace that holds mutable state for a single agent run.

RunContext is constructed from a Thread’s persisted data at the start of a run and accumulates messages, patches, and overlay ops as the run progresses. It owns the DocCell (live document) and provides delta extraction via take_delta().

It does not hold the Thread itself — only the data needed for execution. Run identity lives in RunIdentity; this workspace only owns live execution data.

Implementations§

Source§

impl RunContext

Source

pub fn new( thread_id: impl Into<String>, state: Value, messages: Vec<Arc<Message>>, run_policy: RunPolicy, ) -> Self

Build a run workspace from thread data.

  • thread_id: thread identifier (owned)
  • state: already-rebuilt state (base + patches)
  • messages: initial messages (cursor set to end — no delta)
  • run_policy: typed per-run run policy
Source

pub fn with_registry( thread_id: impl Into<String>, state: Value, messages: Vec<Arc<Message>>, run_policy: RunPolicy, lattice_registry: Arc<LatticeRegistry>, ) -> Self

Build a run workspace with a pre-populated lattice registry.

Source

pub fn with_registry_and_identity( state: Value, messages: Vec<Arc<Message>>, run_policy: RunPolicy, run_identity: RunIdentity, lattice_registry: Arc<LatticeRegistry>, ) -> Self

Source

pub fn thread_id(&self) -> &str

Thread identifier.

Source

pub fn run_policy(&self) -> &RunPolicy

Source

pub fn run_identity(&self) -> &RunIdentity

Source

pub fn set_run_identity(&mut self, run_identity: RunIdentity)

Source

pub fn version(&self) -> u64

Current committed version (0 if never committed).

Source

pub fn set_version(&mut self, version: u64, timestamp: Option<u64>)

Update version after a successful state commit.

Source

pub fn version_timestamp(&self) -> Option<u64>

Timestamp of the last committed version.

Source

pub fn suspended_calls(&self) -> HashMap<String, SuspendedCall>

Read all suspended calls from durable control state.

Source

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

All messages (initial + accumulated during run).

Source

pub fn initial_message_count(&self) -> usize

Number of messages that existed before this run started.

Source

pub fn add_message(&mut self, msg: Arc<Message>)

Add a single message to the run.

Source

pub fn add_messages(&mut self, msgs: Vec<Arc<Message>>)

Add multiple messages to the run.

Source

pub fn thread_base(&self) -> &Value

The initial rebuilt state (base + thread patches).

Source

pub fn add_thread_patch(&mut self, patch: TrackedPatch)

Add a tracked patch from this run.

Source

pub fn add_thread_patches(&mut self, patches: Vec<TrackedPatch>)

Add multiple tracked patches from this run.

Source

pub fn thread_patches(&self) -> &[TrackedPatch]

All patches accumulated during this run.

Source

pub fn add_serialized_state_actions( &mut self, state_actions: Vec<SerializedStateAction>, )

Add serialized state actions captured during tool/phase execution.

Source

pub fn snapshot(&self) -> TireaResult<Value>

Rebuild the current run-visible state (thread_base + thread_patches).

This is a pure computation that returns a new Value without touching the DocCell.

Source

pub fn snapshot_of<T: State>(&self) -> TireaResult<T>

Typed snapshot at the type’s canonical path.

Rebuilds state and deserializes the value at T::PATH.

Source

pub fn snapshot_at<T: State>(&self, path: &str) -> TireaResult<T>

Typed snapshot at an explicit path.

Rebuilds state and deserializes the value at the given path.

Source

pub fn take_delta(&mut self) -> RunDelta

Extract the incremental delta (new messages + patches + serialized state actions) since the last take_delta() call.

Source

pub fn has_delta(&self) -> bool

Whether there are un-consumed messages, patches, or serialized state actions.

Source

pub fn tool_call_context<'ctx>( &'ctx self, ops: &'ctx Mutex<Vec<Op>>, call_id: impl Into<String>, source: impl Into<String>, pending_messages: &'ctx Mutex<Vec<Arc<Message>>>, activity_manager: Arc<dyn ActivityManager>, ) -> ToolCallContext<'ctx>

Create a ToolCallContext scoped to a specific tool call.

Source§

impl RunContext

Source

pub fn from_thread( thread: &Thread, run_policy: RunPolicy, ) -> Result<Self, TireaError>

Convenience constructor from a Thread.

Rebuilds state from the thread’s base state + patches, then wraps the thread’s messages and the given run_policy into a RunContext. Version metadata is carried over from thread metadata.

Source

pub fn from_thread_with_registry( thread: &Thread, run_policy: RunPolicy, lattice_registry: Arc<LatticeRegistry>, ) -> Result<Self, TireaError>

Convenience constructor from a Thread with a lattice registry.

Source

pub fn from_thread_with_registry_and_identity( thread: &Thread, run_policy: RunPolicy, run_identity: RunIdentity, lattice_registry: Arc<LatticeRegistry>, ) -> Result<Self, TireaError>

Source

pub fn lattice_registry(&self) -> &Arc<LatticeRegistry>

The lattice registry used by this context for CRDT-aware operations.

Trait Implementations§

Source§

impl Debug for RunContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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: 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: 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, 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<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