ToolCallContext

Struct ToolCallContext 

Source
pub struct ToolCallContext<'a> { /* private fields */ }
Expand description

Execution context for tool invocations.

Provides typed state access (read/write), run policy access, identity, message queuing, and activity tracking. Tools receive &ToolCallContext instead of &Thread.

Implementations§

Source§

impl<'a> ToolCallContext<'a>

Source

pub fn new( doc: &'a DocCell, ops: &'a Mutex<Vec<Op>>, call_id: impl Into<String>, source: impl Into<String>, run_policy: &'a RunPolicy, pending_messages: &'a Mutex<Vec<Arc<Message>>>, activity_manager: Arc<dyn ActivityManager>, ) -> Self

Create a new tool call context.

Source

pub fn as_read_only(self) -> Self

Mark this context as read-only; state writes via apply_op are rejected.

Source

pub fn with_cancellation_token(self, token: &'a CancellationToken) -> Self

Attach cancellation token.

Source

pub fn with_run_identity(self, run_identity: RunIdentity) -> Self

Source

pub fn with_caller_context(self, caller_context: CallerContext) -> Self

Source

pub fn with_tool_call_progress_sink( self, sink: Arc<dyn ToolCallProgressSink>, ) -> Self

Override the sink used for tool-call progress payload forwarding.

This allows runtime integrations to decouple progress collection from activity transport details.

Source

pub fn doc(&self) -> &DocCell

Borrow the underlying document cell.

Source

pub fn call_id(&self) -> &str

Current call id (typically the tool_call_id).

Source

pub fn idempotency_key(&self) -> &str

Stable idempotency key for the current tool invocation.

Tools should use this value when implementing idempotent side effects.

Source

pub fn source(&self) -> &str

Source identifier used for tracked patches.

Source

pub fn is_cancelled(&self) -> bool

Whether the run cancellation token has already been cancelled.

Source

pub async fn cancelled(&self)

Await cancellation for this context.

If no cancellation token is available, this future never resolves.

Source

pub fn cancellation_token(&self) -> Option<&CancellationToken>

Borrow the cancellation token when present.

Source

pub fn run_policy(&self) -> &RunPolicy

Borrow the run policy.

Source

pub fn run_identity(&self) -> &RunIdentity

Source

pub fn caller_context(&self) -> &CallerContext

Source

pub fn state<T: State>(&self, path: &str) -> T::Ref<'_>

Typed state reference at path.

Source

pub fn state_of<T: State>(&self) -> T::Ref<'_>

Typed state reference at the type’s canonical path.

Panics if T::PATH is empty (no bound path via #[tirea(path = "...")]).

Source

pub fn call_state<T: State>(&self) -> T::Ref<'_>

Typed state reference for current call (tool_calls.<call_id>).

Source

pub fn tool_call_state_for( &self, call_id: &str, ) -> TireaResult<Option<ToolCallState>>

Read persisted runtime state for a specific tool call.

Source

pub fn tool_call_state(&self) -> TireaResult<Option<ToolCallState>>

Read persisted runtime state for current call_id.

Source

pub fn set_tool_call_state_for( &self, call_id: &str, state: ToolCallState, ) -> TireaResult<()>

Upsert persisted runtime state for a specific tool call.

Source

pub fn set_tool_call_state(&self, state: ToolCallState) -> TireaResult<()>

Upsert persisted runtime state for current call_id.

Source

pub fn clear_tool_call_state_for(&self, call_id: &str) -> TireaResult<()>

Remove persisted runtime state for a specific tool call.

Source

pub fn clear_tool_call_state(&self) -> TireaResult<()>

Remove persisted runtime state for current call_id.

Source

pub fn resume_input_for( &self, call_id: &str, ) -> TireaResult<Option<ToolCallResume>>

Read resume payload for a specific tool call.

Source

pub fn resume_input(&self) -> TireaResult<Option<ToolCallResume>>

Read resume payload for current call_id.

Source

pub fn add_message(&self, message: Message)

Queue a message addition in this operation.

Source

pub fn add_messages(&self, messages: impl IntoIterator<Item = Message>)

Queue multiple messages in this operation.

Source

pub fn activity( &self, stream_id: impl Into<String>, activity_type: impl Into<String>, ) -> ActivityContext

Create an activity context for a stream/type pair.

Source

pub fn progress_stream_id(&self) -> String

Stable stream id used by default for this tool call’s progress activity.

Source

pub fn report_tool_call_progress( &self, update: ToolCallProgressUpdate, ) -> TireaResult<()>

Publish a typed tool-call progress node update.

The update is written to activity(progress_stream_id(), "tool-call-progress") with payload schema tool-call-progress.v1.

Source

pub fn snapshot(&self) -> Value

Snapshot the current document state.

Returns the current state including all write-through updates. Equivalent to Thread::rebuild_state() in transient contexts.

Source

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

Typed snapshot at the type’s canonical path.

Reads current doc 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.

Reads current doc state and deserializes the value at the given path.

Source

pub fn take_patch(&self) -> TrackedPatch

Extract accumulated patch with context source metadata.

Source

pub fn has_changes(&self) -> bool

Whether state has pending transient changes.

Source

pub fn ops_count(&self) -> usize

Number of queued transient operations.

Auto Trait Implementations§

§

impl<'a> Freeze for ToolCallContext<'a>

§

impl<'a> !RefUnwindSafe for ToolCallContext<'a>

§

impl<'a> Send for ToolCallContext<'a>

§

impl<'a> Sync for ToolCallContext<'a>

§

impl<'a> Unpin for ToolCallContext<'a>

§

impl<'a> !UnwindSafe for ToolCallContext<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more