Skip to main content

ToolContext

Struct ToolContext 

Source
pub struct ToolContext {
    pub cancel: CancellationToken,
    /* private fields */
}
Expand description

Per-job dispatch context.

Fields§

§cancel: CancellationToken

Cooperative cancellation token. Handlers MUST poll this.

Implementations§

Source§

impl ToolContext

Source

pub const fn correlation_id(&self) -> &MessageId

The id of the originating tool.invoke.

Source

pub const fn job_id(&self) -> &JobId

The job id the runtime assigned.

Source

pub const fn budget(&self) -> &BudgetTracker

Reference to this job’s cost.budget tracker (ARCP v1.1 §9.6).

The tracker is empty if no cost_budget was supplied on tool.invoke. Use Self::charge to report cost and have the runtime decrement the counter; use BudgetTracker::remaining to query.

Source

pub const fn lease(&self) -> Option<&LeaseRequest>

Accepted lease request for this job, if one was supplied.

Source

pub fn enforce_model_use(&self, model: &str) -> Result<(), ARCPError>

Enforce this job’s model.use lease capability.

§Errors

Returns ARCPError::PermissionDenied when the lease declares model.use and model matches none of the allowed patterns.

Source

pub fn translate_upstream_budget_exhausted( &self, detail: impl Into<String>, ) -> ARCPError

Translate an upstream credential budget signal into ARCP’s canonical BUDGET_EXHAUSTED error.

Source

pub async fn charge( &self, name: &str, amount: f64, currency: &str, ) -> Result<(), ARCPError>

Charge amount against the currency counter and emit a matching metric event (ARCP v1.1 §9.6).

The metric is named name (which SHOULD begin with cost. per §9.6) and carries unit: currency, matching what a downstream runtime would observe on the wire. After the charge, a cost.budget.remaining metric is emitted with the new counter so clients can render gauges without re-summing.

§Errors

Returns ARCPError::BudgetExhausted when the counter is at or below zero before the charge — the canonical signal per §9.6 that the agent should stop incurring cost.

Source

pub async fn emit_result_chunk( &self, result_id: impl Into<String>, chunk_seq: u64, data: impl Into<String>, encoding: ResultChunkEncoding, more: bool, ) -> Result<(), ARCPError>

Emit one job.result_chunk fragment (ARCP v1.1 §8.4).

chunk_seq is the caller’s responsibility — start at 0 and increment per chunk for the same result_id. The terminal chunk MUST set more: false; the job’s terminal job.completed SHOULD then carry the same result_id.

§Errors

Returns ARCPError::Unavailable if the outbound channel is closed.

Trait Implementations§

Source§

impl Debug for ToolContext

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

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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