Skip to main content

ToolCtx

Struct ToolCtx 

Source
#[non_exhaustive]
pub struct ToolCtx { pub pubsub: Arc<dyn Pubsub>, pub kv: Arc<dyn KvStore>, pub jobs: Arc<dyn JobQueue>, pub progress: Option<Sender<AgentEvent>>, pub cancel: CancellationToken, pub server_outbound: Option<Arc<dyn ServerOutbound>>, pub caller_principal: Option<CallerPrincipal>, pub parent_anchor: Option<ParentAnchor>, }
Expand description

Narrowed slice of AgentContext (see agent.rs) passed to tools.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§pubsub: Arc<dyn Pubsub>

Pub/sub bus.

§kv: Arc<dyn KvStore>

KV store.

§jobs: Arc<dyn JobQueue>

Job queue.

§progress: Option<Sender<AgentEvent>>

Optional progress sender. Tools that wrap an crate::Agent (e.g. AgentAsToolInvoker in klieo-mcp-server) overlay this onto the minted AgentContext. Non-agent invokers ignore the field.

§cancel: CancellationToken

Cooperative cancellation token. HTTP/SSE transports pass a request-scoped child token derived from the server’s parent cancel; tools should select! against cancel.cancelled() to honor client disconnects mid-call.

§server_outbound: Option<Arc<dyn ServerOutbound>>

Optional outbound channel for server-initiated JSON-RPC (e.g. MCP sampling/createMessage). Tools requiring the outbound surface return Err(Unsupported) when None. Default: None.

§caller_principal: Option<CallerPrincipal>

Verified caller principal for server-side authorisation (e.g. binding a klieo/run/resume ticket to its issuer). Server-side metadata ONLY: implementations MUST NOT append this value to short-term/episodic memory, conversation history, or any LLM-visible message — those surfaces are operator- reviewed and PII-redacted on their own contract. None when no authenticator is wired, when the transport carries no principal (stdio, unauthenticated HTTP), or when the request is anonymous.

§parent_anchor: Option<ParentAnchor>

Opaque cross-hop provenance anchor supplied by an authenticated caller — by convention the caller’s own provenance chain-entry id (or its run’s episodic-root hash). When set, the run records it as its origin so klieo→klieo composition can be stitched across deployment boundaries in the audit trail. Audit metadata ONLY: implementations MUST NOT append it to short-term/episodic memory, conversation history, or any LLM-visible message. The value is recorded verbatim (stitching requires it to equal the caller’s chain-entry id), is a caller-ASSERTED, UNVERIFIED claim, and must be treated as such downstream. None when no anchor was supplied or the caller is unauthenticated.

Implementations§

Source§

impl ToolCtx

Source

pub fn new( pubsub: Arc<dyn Pubsub>, kv: Arc<dyn KvStore>, jobs: Arc<dyn JobQueue>, ) -> Self

Construct a ToolCtx with default progress = None, no outbound channel, and a fresh uncancelled CancellationToken. Builders below override.

Source

pub fn with_cancel(self, cancel: CancellationToken) -> Self

Override the cancellation token (HTTP/SSE callers pass a request-scoped child token).

Source

pub fn with_progress(self, progress: Sender<AgentEvent>) -> Self

Override the progress sender (HTTP/SSE callers pass the per-request broadcast for AgentEvent forwarding).

Source

pub fn with_server_outbound(self, outbound: Arc<dyn ServerOutbound>) -> Self

Attach a server-initiated outbound channel so tools can issue reverse-direction JSON-RPC requests to the connected peer.

Source

pub fn with_caller_principal(self, principal: String) -> Self

Stamp the verified caller principal so server-side authorisation helpers (e.g. resume-ticket issuance) can bind follow-up requests to the original caller. See the field docstring for the prohibition on leaking this value into LLM-visible memory.

Source

pub fn with_parent_anchor(self, anchor: String) -> Self

Stamp the cross-hop provenance anchor (the caller’s chain-entry id) so the run can record its origin. See the field docstring for the verbatim-record / unverified-claim / no-LLM-leak contract.

Trait Implementations§

Source§

impl Clone for ToolCtx

Source§

fn clone(&self) -> ToolCtx

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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