Expand description
Typed inbound context and explicitly published host-only tool-result metadata.
use rig_core::tool::{ContextValue, ToolContext};
#[derive(serde::Serialize, serde::Deserialize)]
struct Session(String);
impl ContextValue for Session { const KEY: &'static str = "session"; }
let mut context = ToolContext::new();
context.insert(Session("example".into()))?;
assert_eq!(context.require::<Session>()?.0, "example");Structs§
- Published
Context - What a tool published into its dispatch context, handed back beside the
sink rather than on the wire: the driver attaches an empty one to the
sink’s scope (
Dispatch::with_scope), the adapter fills it once the tool ran, the driver reads it after the outcome. One per dispatch; a second publish replaces the first. - Tool
Context - Context passed to every tool execution.
- Tool
Result Context - Explicitly published, durable tool-result metadata. Unlike
ToolContext, this contains no inbound credentials or live runtime scopes. Values are keyed byContextValue::KEY; applications own their schema versions. - TypeMap
- A clone-on-dispatch map of live values keyed by type. Not the storage
behind
ToolContext(which is serde data); runtimes use it for in-process per-run state that never crosses a wire (rig-agent’s hook state does).
Enums§
- Tool
Context Error - A
ToolContextslot could not be read or written.
Traits§
- Context
Value - Serializable context data with a stable slot key. Distinct value types must
use distinct keys, and persisted keys must remain stable across schema changes.
The derive macro defaults to the type name;
#[context(key = "…")]overrides it.