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>

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

python
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 str

Task description for memory search

ParamField Optional[str]

Optional user ID for personalized memory

ParamField str

Additional context to include in search

ParamField int

Maximum items per memory category

ParamField bool

Whether 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 GitHub

praisonaiagents/memory/memory.py at line 2117


Related Documentation