pub struct PromptCache { /* private fields */ }Expand description
Manages prompt caching for the agent turn loop.
PromptCache builds structured system prompts with cache control
breakpoints and tracks cache performance metrics.
Implementations§
Source§impl PromptCache
impl PromptCache
Sourcepub fn build_system_prompt(
&self,
identity: &str,
tools: &[ToolDefinition],
context: &str,
) -> SystemPrompt
pub fn build_system_prompt( &self, identity: &str, tools: &[ToolDefinition], context: &str, ) -> SystemPrompt
Builds a structured system prompt with cache control breakpoints.
The system prompt is organized into three cacheable sections:
- Identity — the agent’s identity and behavioral instructions
- Tool definitions — sorted alphabetically by name for stable ordering
- Context files — reference materials like AGENTS.md
A dynamic section follows the static prefix, reserved for conversation history that changes each turn.
§Arguments
identity— Agent identity and behavioral instructions.tools— List of tool definitions (will be sorted by name).context— Context file contents (e.g., AGENTS.md).
§Cache Breakpoints
Three breakpoints are inserted:
- After the identity section
- After the tool definitions section
- After the context files section
Sourcepub fn track_cache_hit_rate(&mut self, hit: bool)
pub fn track_cache_hit_rate(&mut self, hit: bool)
Records a cache hit or miss for performance tracking.
§Arguments
hit—trueif the cache was hit,falseif it was a miss.
Sourcepub fn cache_hit_rate(&self) -> f64
pub fn cache_hit_rate(&self) -> f64
Returns the cache hit rate as a percentage (0.0 to 100.0).
Returns 0.0 if no cache checks have been recorded.
Trait Implementations§
Source§impl Debug for PromptCache
impl Debug for PromptCache
Auto Trait Implementations§
impl Freeze for PromptCache
impl RefUnwindSafe for PromptCache
impl Send for PromptCache
impl Sync for PromptCache
impl Unpin for PromptCache
impl UnsafeUnpin for PromptCache
impl UnwindSafe for PromptCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more