Skip to main content

build_cache_optimized_context

Method
This is a method of the Memory class in the memory module.
Build context with cache boundary markers for prompt prefix caching optimization. Returns a dictionary with ‘stable_prefix’ and ‘cache_boundary’ keys. The stable prefix contains deterministically ordered content that should remain constant between turns for effective prompt caching.

Signature

Parameters

str
required
Task description for memory search
Optional[str]
Optional user ID for personalized memory
str
default:"''"
Additional context to include in search
int
default:"3"
Maximum items per memory category
bool
default:"True"
Whether to include cache boundary marker
Optional[bool]
Whether to include memory content in output

Returns

Dict[str, str]
Dict with ‘stable_prefix’ and ‘cache_boundary’ keys

Uses

  • build_context_for_task

Used By

Source

View on GitHub

praisonaiagents/memory/memory.py at line 1869

Context Concept

Context Management

Context Strategies

Caching Concept