Skip to main content
Works with: Mem0 Platform (@mastra/mem0)
In this example you’ll learn how to use Mem0 to add long-term memory capabilities to Mastra’s agent via tool-use. This memory integration can work alongside Mastra’s agent memory features. The complete example code, from installing the integration to wiring it into a Mastra agent, is shown below. Mem0’s integration is published on npm as @mastra/mem0.

Overview

This guide will show you how to integrate Mem0 with Mastra to add long-term memory capabilities to your agents. We’ll create tools that allow agents to save and retrieve memories using Mem0’s API.

Installation

Install the Integration Package To install the Mem0 integration, run:
Add the Integration to Your Project Create a new file for your integrations and import the integration:
integrations/index.ts
Use the Integration in Tools or Workflows You can now use the integration when defining tools for your agents or in workflows.
tools/index.ts
Create a New Agent
agents/index.ts
Run the Agent
index.ts
In the example above:
  • We import the @mastra/mem0 integration
  • We define two tools that use the Mem0 API client to create new memories and recall previously saved memories
  • The tool accepts question as an input and returns the memory as a string

Partition Memories by Entity

Separate user, agent, and app memories to keep multi-agent flows clean.

Agents SDK Tool with Mem0

Explore tool-calling patterns with the OpenAI Agents SDK.
Using Mem0? Star us on GitHub to help more developers discover memory for AI apps.