Expand description
Memory-aware prompt construction engine (T8)
Assembles retrieved memories into structured LLM prompts with configurable token budgets, section priorities, and fill strategies.
§Example
ⓘ
use engram::intelligence::context_builder::{
ContextBuilder, PromptTemplate, Section, SimpleTokenCounter, Strategy,
};
let counter = SimpleTokenCounter;
let builder = ContextBuilder::new(Box::new(counter));
let template = PromptTemplate {
sections: vec![
Section { name: "System".into(), content: "You are helpful.".into(), max_tokens: 100, priority: 0 },
Section { name: "Memories".into(), content: String::new(), max_tokens: 500, priority: 1 },
],
total_budget: 600,
separator: "\n\n---\n\n".into(),
};
let result = builder.build(&template, &memories, Strategy::Greedy);Structs§
- Context
Builder - Context builder that assembles memories into structured prompts.
- Memory
Entry - Minimal memory representation used by the builder.
- Prompt
Template - Template defining prompt structure.
- Section
- A section in the prompt with its own token budget and priority.
- Simple
Token Counter - Simple token estimator that assumes ~4 characters per token.
Enums§
- Strategy
- Strategy for filling sections with memories.
Traits§
- Token
Counter - Abstraction for counting tokens in a string.