Skip to main content

Module context_injector

Module context_injector 

Source
Expand description

The context-injection plugin: ContextInjector writes just-in-time text into the latest user message before each model call, as an InjectedBlock that stays in the conversation.

use strands::Agent;
use strands::testing::MockModel;
use strands::vended_plugins::context_injector::{ContextInjector, ContextInjectorConfig};

let injector = ContextInjector::new(ContextInjectorConfig::new(|_context| async {
    Ok(Some("<now>2026-11-11</now>".to_owned()))
}));
let mut agent = Agent::builder()
    .model(MockModel::new().with_turn("ok"))
    .plugins([injector])
    .printer(false)
    .build()?;
agent.invoke("What day is it?").await?;
assert_eq!(agent.messages()[0].content.len(), 2);

Re-exports§

pub use crate::injection::InjectionContext;
pub use crate::injection::InjectionTrigger;

Structs§

ContextInjector
Injects just-in-time context into the latest user message before each model call (ContextInjector).
ContextInjectorConfig
Configuration for the ContextInjector plugin (ContextInjectorConfig).