pub struct ToolContext { /* private fields */ }Expand description
Context passed to every tool execution.
Callers insert typed inbound values with insert. Tools read
those values with get or require, and attach
host-only result metadata with insert_result. Result
hooks inspect that metadata through result. Neither inbound
values nor result metadata are sent to the model.
Registry, server, and agent dispatch clone inbound values once per call.
Map-level mutations (inserting, replacing, or removing typed slots) affect
only that execution. Value-level isolation follows each value’s Clone
semantics, so intentionally shared values such as Arc<Mutex<_>> continue
to share their referent across dispatches. The dispatch surface returns
result metadata without replacing the caller’s inbound slots.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn insert<T>(&mut self, value: T) -> Option<T>
pub fn insert<T>(&mut self, value: T) -> Option<T>
Insert an inbound typed value, returning the displaced value if present.
Sourcepub fn get<T>(&self) -> Option<&T>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn get<T>(&self) -> Option<&T>where
T: WasmCompatSend + WasmCompatSync + 'static,
Read an inbound typed value.
Sourcepub fn require<T>(&self) -> Result<&T, MissingToolContext>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn require<T>(&self) -> Result<&T, MissingToolContext>where
T: WasmCompatSend + WasmCompatSync + 'static,
Require an inbound typed value.
Sourcepub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: WasmCompatSend + WasmCompatSync + 'static,
Mutably access an inbound typed value.
Sourcepub fn remove<T>(&mut self) -> Option<T>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn remove<T>(&mut self) -> Option<T>where
T: WasmCompatSend + WasmCompatSync + 'static,
Remove an inbound typed value.
Sourcepub fn insert_result<T>(&mut self, value: T) -> Option<T>
pub fn insert_result<T>(&mut self, value: T) -> Option<T>
Attach host-only metadata to this execution’s result.
Sourcepub fn result<T>(&self) -> Option<&T>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn result<T>(&self) -> Option<&T>where
T: WasmCompatSend + WasmCompatSync + 'static,
Read host-only result metadata.
Sourcepub fn require_result<T>(&self) -> Result<&T, MissingToolContext>where
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn require_result<T>(&self) -> Result<&T, MissingToolContext>where
T: WasmCompatSend + WasmCompatSync + 'static,
Require host-only result metadata.
Sourcepub fn contains<T>(&self) -> boolwhere
T: WasmCompatSend + WasmCompatSync + 'static,
pub fn contains<T>(&self) -> boolwhere
T: WasmCompatSend + WasmCompatSync + 'static,
Whether this context contains the inbound type T.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more