Skip to main content

Module context

Module context 

Source
Expand description

Context assembly — token-budgeted context building for LLM prompts.

The context assembler retrieves facts via hybrid search, ranks them by tier priority, fills a token budget greedily, and formats the output for injection into system prompts, messages, or raw JSON.

Structs§

CharTokenEstimator
Character-based token estimator (~4 chars per token). Accurate to within ~10% for English text across GPT/Claude models.
ContextBlock
The assembled context block returned by ContextBuilder::build().
ContextBuilder
Token-budgeted context assembler.
ContextConfig
Configuration for context assembly.

Enums§

OutputFormat
Format for the assembled context block.

Traits§

TokenEstimator
Pluggable token estimation. Implementations convert text to an approximate token count without requiring a full tokenizer dependency.

Functions§

format_markdown
Format facts as human-readable Markdown.
format_raw
Format facts as raw JSON (array of objects with text, tier, category, confidence).
format_system_prompt
Format facts as an XML-tagged block for system prompt injection.
sort_by_tier_priority
Sort facts by tier priority (Working first, then Conversation, then Knowledge). Within the same tier, preserve the original order (which is by retrieval score).