> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

> This is a method of the [**Memory**](https://praison.ai/docs/sdk/reference/praisonaiagents/classes/Memory.md) class in the [**memory**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/memory.md) 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

**task\_descr** `str` *required*

Task description for memory search

**user\_id** `Optional[str]`

Optional user ID for personalized memory

**additional** `str` (default: '')

Additional context to include in search

**max\_items** `int` (default: 3)

Maximum items per memory category

**include\_cache\_boundary** `bool` (default: True)

Whether to include cache boundary marker

**include\_in\_output** `Optional[bool]`

Whether to include memory content in output

### Returns

**Returns** `Dict[str, str]`

Dict with 'stable\_prefix' and 'cache\_boundary' keys

## Uses

* `build_context_for_task`

## Used By

* [`Task.execute_callback`](../functions/Task-execute_callback)

## Source

> [card] [View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/memory/memory.py#L2117)
>
> `praisonaiagents/memory/memory.py` at line 2117

***

## Related Documentation

> [card] [Context Concept](https://praison.ai/docs/docs/concepts/context)

> [card] [Context Management](https://praison.ai/docs/docs/features/context-management)

> [card] [Context Strategies](https://praison.ai/docs/docs/features/context-strategies)

> [card] [Caching Concept](https://praison.ai/docs/docs/concepts/caching)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.