Skip to main content

Module context

Module context 

Source
Expand description

Context construction and multi-adapter composition.

The ContextAdapter trait defines pluggable context sources such as system prompts, conversation history, memory, or RAG retrieval. The ContextFactory composes multiple adapters in order to produce a complete Vec<Message> for chat requests.

§Example

use behest::context::{ContextAdapter, ContextFactory, ContextInput, StaticAdapter};
use behest::provider::Message;

#[tokio::main]
async fn main() {
    let mut factory = ContextFactory::new();

    factory.register(StaticAdapter::system("You are a helpful assistant."));
    factory.register(StaticAdapter::user("Hello, how are you?"));

    let input = ContextInput::default();
    let output = factory.build(&input).await.unwrap();

    assert_eq!(output.messages().len(), 2);
}

Structs§

ContextFactory
Multi-adapter context factory.
ContextInput
Input provided to context adapters.
ContextOutput
Output produced by context construction.
FunctionAdapter
Function-based context adapter.
StaticAdapter
Static context adapter that returns fixed messages.

Traits§

ContextAdapter
Pluggable context source that produces message fragments.

Type Aliases§

ContextResult
Result type for context operations.