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 one dispatch published beside its answer, passed back beside the sink rather than on the wire. A tool’s adapter fills it with the tool’s whole context (a second publish replaces the first); any other layer, such as a stream rewrite (ErasedHandler::map_stream), adds single facts with insert.
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.

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.