pub struct ToolContext {
pub cancel: CancellationToken,
/* private fields */
}Expand description
Per-job dispatch context.
Fields§
§cancel: CancellationTokenCooperative cancellation token. Handlers MUST poll this.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub const fn correlation_id(&self) -> &MessageId
pub const fn correlation_id(&self) -> &MessageId
The id of the originating tool.invoke.
Sourcepub const fn budget(&self) -> &BudgetTracker
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.
Sourcepub const fn lease(&self) -> Option<&LeaseRequest>
pub const fn lease(&self) -> Option<&LeaseRequest>
Accepted lease request for this job, if one was supplied.
Sourcepub fn enforce_model_use(&self, model: &str) -> Result<(), ARCPError>
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.
Sourcepub fn translate_upstream_budget_exhausted(
&self,
detail: impl Into<String>,
) -> ARCPError
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.
Sourcepub async fn charge(
&self,
name: &str,
amount: f64,
currency: &str,
) -> Result<(), ARCPError>
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.
Sourcepub async fn emit_result_chunk(
&self,
result_id: impl Into<String>,
chunk_seq: u64,
data: impl Into<String>,
encoding: ResultChunkEncoding,
more: bool,
) -> Result<(), ARCPError>
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.