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

<div className="flex items-center gap-2">
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**Memory**](../classes/Memory) class in the [**memory**](../modules/memory) 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

<ParamField query="query" type="Optional[str]" required={false}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="str">
  The result of the operation.
</ResponseField>

## Uses

* `build_context_for_task`

## Used By

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

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/memory/memory.py#L2081">
  `praisonaiagents/memory/memory.py` at line 2081
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Context Concept" icon="layer-group" href="/docs/docs/concepts/context" />

  <Card title="Context Management" icon="sliders" href="/docs/docs/features/context-management" />

  <Card title="Context Strategies" icon="diagram-project" href="/docs/docs/features/context-strategies" />
</CardGroup>
