> ## 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.

# Get Context • AI Agent SDK

> get_context: Return retrieved memory as a prompt-ready context string.

# get\_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.

Return retrieved memory as a prompt-ready context string.

Satisfies `AgentMemoryProtocol` (used by `Agent.get_memory_context()`)
so the non-prompt-caching code path can inject memory into the system
prompt. Without this, `hasattr(memory, 'get_context')` was False and the
fallback branch always returned "".

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def get_context(query: Optional[str]) -> str
```

## Parameters

**query** `Optional[str]`

No description available.

### Returns

**Returns** `str`

The result of the operation.

## Uses

* `build_context_for_task`

## Used By

* [`Agent.get_memory_context`](../functions/Agent-get_memory_context)

## Source

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

***

## 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)


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