pub struct ContextPipeline { /* private fields */ }Expand description
Runtime context pipeline that composes context from multiple sources.
The pipeline:
- Loads session history from the store
- Applies compaction filter (reorder post-compaction messages)
- Invokes registered context adapters (system prompt, RAG, etc.)
- Applies token-budget trimming as a safety net
- Produces a final
ChatRequestorContextOutput
Implementations§
Source§impl ContextPipeline
impl ContextPipeline
Sourcepub fn with_factory(factory: ContextFactory) -> Self
pub fn with_factory(factory: ContextFactory) -> Self
Creates a context pipeline with an existing context factory.
Sourcepub fn with_max_history(self, max: usize) -> Self
pub fn with_max_history(self, max: usize) -> Self
Sets the maximum number of history messages to include as a fallback limit.
This limit applies before token-based trimming. Default: 50.
Sourcepub fn with_max_history_tokens(self, max: usize) -> Self
pub fn with_max_history_tokens(self, max: usize) -> Self
Sets the maximum token budget for historical messages before trimming.
Older messages are dropped first when the budget is exceeded. Default: 64,000 tokens.
Sourcepub fn with_compaction_filter(self, enable: bool) -> Self
pub fn with_compaction_filter(self, enable: bool) -> Self
Enables or disables the compaction message filter.
When enabled, compacted message pairs are replaced with a synthetic checkpoint system message. Enabled by default.
Sourcepub fn with_cache_strategy(self, config: PromptCacheConfig) -> Self
pub fn with_cache_strategy(self, config: PromptCacheConfig) -> Self
Sets the prompt cache strategy used to auto-place cache breakpoints.
When cache_strategy.enabled is true and
cache_strategy.auto_breakpoints is true, the pipeline places up
to three cache markers on each ChatRequest:
- The end of the last system message (if it has at least
min_system_tokenstokens). - The end of the conversation tail (the last message before the current user turn).
- Each tool definition in the request.
Sourcepub fn register<A>(&mut self, adapter: A)where
A: ContextAdapter + 'static,
pub fn register<A>(&mut self, adapter: A)where
A: ContextAdapter + 'static,
Registers a context adapter.
Sourcepub fn register_arc(&mut self, adapter: Arc<dyn ContextAdapter>)
pub fn register_arc(&mut self, adapter: Arc<dyn ContextAdapter>)
Registers an already shared context adapter.
Sourcepub fn adapter_names(&self) -> impl Iterator<Item = &str>
pub fn adapter_names(&self) -> impl Iterator<Item = &str>
Returns adapter names in registration order.
Sourcepub async fn build(
&self,
store: &RuntimeStore,
session_id: Uuid,
model: ModelName,
user_message: Option<&str>,
tools: Option<&[ToolSpec]>,
) -> RuntimeResult<ChatRequest>
pub async fn build( &self, store: &RuntimeStore, session_id: Uuid, model: ModelName, user_message: Option<&str>, tools: Option<&[ToolSpec]>, ) -> RuntimeResult<ChatRequest>
Builds a ChatRequest from session history, registered adapters,
and the current user message.
The pipeline loads session messages, applies compaction filtering, token-budget trimming, runs registered adapters, and assembles the final request with optional tool specs.
§Errors
Returns RuntimeError on adapter failure or storage errors.
Sourcepub async fn build_context(
&self,
store: &RuntimeStore,
session_id: Uuid,
user_message: Option<&str>,
) -> RuntimeResult<ContextOutput>
pub async fn build_context( &self, store: &RuntimeStore, session_id: Uuid, user_message: Option<&str>, ) -> RuntimeResult<ContextOutput>
Builds context output without creating a chat request.
Equivalent to build but returns the raw
ContextOutput instead of wrapping it in a ChatRequest.
Useful when the caller needs access to the composed message list
without binding to a specific model or tools.
§Errors
Returns RuntimeError on adapter failure or storage errors.