---
title: "Reference: Agent.getMemory() | Agents"
description: "Documentation for the `Agent.getMemory()` method in Mastra agents, which retrieves the memory system associated with the agent."
packages:
  - "@mastra/core"
---

# Agent.getMemory()

The `.getMemory()` method retrieves the memory system associated with an agent. This method is used to access the agent's memory capabilities for storing and retrieving information across conversations.

## Usage example

```typescript
await agent.getMemory();
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "options",
      type: "{ requestContext?: RequestContext }",
      isOptional: true,
      defaultValue: "{}",
      description: "Optional configuration object containing request context.",
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "memory",
      type: "Promise<MastraMemory | undefined>",
      description:
        "A promise that resolves to the memory system configured for the agent, or undefined if no memory system is configured.",
    },
  ]}
/>

## Extended usage example

```typescript
await agent.getMemory({
  requestContext: new RequestContext(),
});
```

### Options parameters

<PropertiesTable
  content={[
    {
      name: "requestContext",
      type: "RequestContext",
      isOptional: true,
      defaultValue: "new RequestContext()",
      description:
        "Request Context for dependency injection and contextual information.",
    },
  ]}
/>

## Related

- [Agent memory](/docs/v1/agents/agent-memory)
- [Request Context](/docs/v1/server/request-context)
