Skip to main content

Module context

Module context 

Source
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§

PublishedContext
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.
ToolContext
Context passed to every tool execution.
ToolResultContext
Explicitly published, durable tool-result metadata. Unlike ToolContext, this contains no inbound credentials or live runtime scopes. Values are keyed by ContextValue::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§

ToolContextError
A ToolContext slot could not be read or written.

Traits§

ContextValue
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.