zeph-agent-context
Agent context-assembly service for the Zeph AI agent.
Provides ContextService — a stateless façade for all context operations: system prompt rebuilds, memory injection, conversation compaction, and summarization. Previously this logic lived directly on Agent<C> inside zeph-core; extracting it means editing context assembly does not trigger recompilation of the tool dispatcher (zeph-agent-tools) or the persistence layer (zeph-agent-persistence).
Installation
[]
= { = "0.20", = true }
[!IMPORTANT] Requires Rust 1.95 or later (Edition 2024). This crate does not depend on
zeph-core— only on lower-level crates (zeph-memory,zeph-llm,zeph-skills,zeph-context,zeph-sanitizer,zeph-config,zeph-common).
Usage
All methods on ContextService are stateless. State flows exclusively through explicit borrow-lens view parameters — structs of &/&mut references that zeph-core's shim layer constructs from disjoint Agent<C> fields. The borrow checker proves field disjointness at the literal struct expressions in the shim.
Rebuild system prompt
use ;
let svc = new;
// `window` and `view` are constructed by zeph-core's shim from Agent<C> fields.
svc.rebuild_system_prompt.await;
Prepare context (memory injection)
svc.prepare_context
.await
.map_err?;
Compaction
svc.maybe_compact.await?;
Key Types
| Type | Purpose |
|---|---|
ContextService |
Stateless façade; zero-sized, all methods take &self |
ContextError |
Typed error enum (thiserror) for all fallible context operations |
MessageWindowView<'a> |
Borrow-lens over the conversation message buffer and deferred queues |
ContextAssemblyView<'a> |
Borrow-lens over all fields needed for prepare_context and rebuild_system_prompt |
ContextSummarizationView<'a> |
Borrow-lens over fields needed for compaction, scheduling, and pruning |
ProviderHandles |
Arc-cloned primary and embedding LLM provider handles |
Borrow-Lens Pattern
Views hold &/&mut references to field types from lower-level crates. No view embeds a whole *State aggregator from zeph-core — each field maps directly to a concrete type from zeph-memory, zeph-skills, zeph-config, etc.
// Constructed once per call site in zeph-core's shim; all borrows are disjoint.
let window = MessageWindowView ;
[!NOTE] External callers cannot meaningfully construct views without access to
Agent<C>internals, which acts as a soft seal without requiring a sealed trait.
Features
| Feature | Default | Description |
|---|---|---|
self-check |
off | Retrieved-memory mirror types for the MARCH self-check pipeline |
index |
off | zeph-index integration via IndexAccess in assembly views |
Both features must be enabled explicitly. zeph-core enables them where needed.
= { = "0.20", = true, = ["self-check", "index"] }
License
MIT — see LICENSE.