Build Cache Optimized Context • AI Agent SDK
build_cache_optimized_context: Build context with cache boundary markers for prompt prefix caching optimization.
build_cache_optimized_context
Method
</div>
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
def build_cache_optimized_context(task_descr: str, user_id: Optional[str], additional: str, max_items: int, include_cache_boundary: bool, include_in_output: Optional[bool]) -> Dict[str, str]Parameters
ParamField
strTask description for memory search
ParamField
Optional[str]Optional user ID for personalized memory
ParamField
strAdditional context to include in search
ParamField
intMaximum items per memory category
ParamField
boolWhether to include cache boundary marker
ParamField
Optional[bool]Whether to include memory content in output
Returns
ResponseField
Dict[str, str]Dict with ‘stable_prefix’ and ‘cache_boundary’ keys
Uses
build_context_for_task
Used By
Source
View on GitHubpraisonaiagents/memory/memory.py at line 2117