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
impl RunContext
Sourcepub fn new(
thread_id: impl Into<String>,
state: Value,
messages: Vec<Arc<Message>>,
run_policy: RunPolicy,
) -> Self
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
Sourcepub fn with_registry(
thread_id: impl Into<String>,
state: Value,
messages: Vec<Arc<Message>>,
run_policy: RunPolicy,
lattice_registry: Arc<LatticeRegistry>,
) -> Self
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.
pub fn with_registry_and_identity( state: Value, messages: Vec<Arc<Message>>, run_policy: RunPolicy, run_identity: RunIdentity, lattice_registry: Arc<LatticeRegistry>, ) -> Self
pub fn run_policy(&self) -> &RunPolicy
pub fn run_identity(&self) -> &RunIdentity
pub fn set_run_identity(&mut self, run_identity: RunIdentity)
Sourcepub fn set_version(&mut self, version: u64, timestamp: Option<u64>)
pub fn set_version(&mut self, version: u64, timestamp: Option<u64>)
Update version after a successful state commit.
Sourcepub fn version_timestamp(&self) -> Option<u64>
pub fn version_timestamp(&self) -> Option<u64>
Timestamp of the last committed version.
Sourcepub fn suspended_calls(&self) -> HashMap<String, SuspendedCall>
pub fn suspended_calls(&self) -> HashMap<String, SuspendedCall>
Read all suspended calls from durable control state.
Sourcepub fn initial_message_count(&self) -> usize
pub fn initial_message_count(&self) -> usize
Number of messages that existed before this run started.
Sourcepub fn add_message(&mut self, msg: Arc<Message>)
pub fn add_message(&mut self, msg: Arc<Message>)
Add a single message to the run.
Sourcepub fn add_messages(&mut self, msgs: Vec<Arc<Message>>)
pub fn add_messages(&mut self, msgs: Vec<Arc<Message>>)
Add multiple messages to the run.
Sourcepub fn thread_base(&self) -> &Value
pub fn thread_base(&self) -> &Value
The initial rebuilt state (base + thread patches).
Sourcepub fn add_thread_patch(&mut self, patch: TrackedPatch)
pub fn add_thread_patch(&mut self, patch: TrackedPatch)
Add a tracked patch from this run.
Sourcepub fn add_thread_patches(&mut self, patches: Vec<TrackedPatch>)
pub fn add_thread_patches(&mut self, patches: Vec<TrackedPatch>)
Add multiple tracked patches from this run.
Sourcepub fn thread_patches(&self) -> &[TrackedPatch]
pub fn thread_patches(&self) -> &[TrackedPatch]
All patches accumulated during this run.
Sourcepub fn add_serialized_state_actions(
&mut self,
state_actions: Vec<SerializedStateAction>,
)
pub fn add_serialized_state_actions( &mut self, state_actions: Vec<SerializedStateAction>, )
Add serialized state actions captured during tool/phase execution.
Sourcepub fn snapshot(&self) -> TireaResult<Value>
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.
Sourcepub fn snapshot_of<T: State>(&self) -> TireaResult<T>
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.
Sourcepub fn snapshot_at<T: State>(&self, path: &str) -> TireaResult<T>
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.
Sourcepub fn take_delta(&mut self) -> RunDelta
pub fn take_delta(&mut self) -> RunDelta
Extract the incremental delta (new messages + patches + serialized state actions) since
the last take_delta() call.
Sourcepub fn has_delta(&self) -> bool
pub fn has_delta(&self) -> bool
Whether there are un-consumed messages, patches, or serialized state actions.
Sourcepub 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>
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
impl RunContext
Sourcepub fn from_thread(
thread: &Thread,
run_policy: RunPolicy,
) -> Result<Self, TireaError>
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.
Sourcepub fn from_thread_with_registry(
thread: &Thread,
run_policy: RunPolicy,
lattice_registry: Arc<LatticeRegistry>,
) -> Result<Self, TireaError>
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.
pub fn from_thread_with_registry_and_identity( thread: &Thread, run_policy: RunPolicy, run_identity: RunIdentity, lattice_registry: Arc<LatticeRegistry>, ) -> Result<Self, TireaError>
Sourcepub fn lattice_registry(&self) -> &Arc<LatticeRegistry>
pub fn lattice_registry(&self) -> &Arc<LatticeRegistry>
The lattice registry used by this context for CRDT-aware operations.