Founders BetaFounder price: US$ 9.90/month locked for as long as you subscribe.→
HomeBlogDicasMem0: How to Give Persistent Memory to AI Agents
Cover of the mem0ai/mem0 repository on GitHub, a persistent memory project for AI agents
Image: mem0ai/mem0
Dicas6 min

Mem0: How to Give Persistent Memory to AI Agents

Mem0 is an open source memory layer for AI agents. See how to install it, save facts and retrieve context in Python.

Marcelo Santiago

Marcelo Santiago

Criador do bridgecode

Mem0 is an open source Python library that works as a memory layer for AI agents. Instead of restarting each conversation from zero, it stores facts, preferences and long term context and retrieves what matters at the right time.

The biggest AI newsletter in the World

Get AI articles in your inbox

Technical curation on models, agents and coding tools. No spam, unsubscribe anytime.

Daily at 8:00 and 16:00 Brasília time. No spam.

If you have already built an agent that forgets the user's name in the middle of a task, Mem0 solves exactly that problem. It does not replace the language model, nor the orchestration framework. It adds a memory layer that can be plugged into LangChain, CrewAI, AutoGen or your own code.

The project is active and has Apache 2.0 license. On GitHub, the repository mem0ai/mem0 passed 68 thousand stars and received update on November 6, 2026. This indicates maturity and community, not just an experiment.

In this article you will see:

  • What Mem0 does and how it organizes memory
  • How to install and save the first fact in Python
  • How to retrieve context before answering
  • When to use Mem0 and when the model's own memory is enough
  • Known limits and best practices

What is Mem0 and how agent memory works

An AI agent without memory treats each request as independent. It can be excellent at reasoning, but it does not know that the user prefers short answers, that the project uses PostgreSQL or that the last decision was to postpone the deploy. Persistent memory changes that.

Mem0 organizes memory in three levels. The first is user memory, with facts linked to a person or account. The second is session memory, valid while the conversation lasts. The third is agent memory, with knowledge that the agent itself accumulates about the domain.

Under the hood, Mem0 uses a language model to extract relevant facts from each interaction and a vector database to retrieve them later. You do not need to write extraction rules. It decides what is worth keeping and discards the noise.

This is different from storing the full conversation history. History grows without control and fills the context window. Extracted memory is compact and focused on what matters.

How to install Mem0 and save the first fact

Installation is straightforward. The main package is mem0ai.

Mem0 documentation screen showing the memory platform for agents
Imagem: Mem0
Terminal
pip install mem0ai

Then, configure the model key that will extract and retrieve the facts. Mem0 supports OpenAI, Anthropic, Groq and other providers compatible with the OpenAI API.

Python
from mem0 import Memory

m = Memory()

# Salva um fato ligado ao usuário
m.add("O usuário prefere respostas em português e usa PostgreSQL no projeto.", user_id="marcelo")

# Recupera contexto relevante para uma nova pergunta
memories = m.search("qual banco de dados o projeto usa?", user_id="marcelo")
print(memories)

The add method extracts facts from the sentence and stores them. The search method finds the most relevant ones for the current question. You can call search before building the agent prompt and inject the result as context.

If you prefer not to depend on an external provider for extraction, Mem0 allows configuring a local model compatible with the OpenAI API, such as a server running Ollama or vLLM. The official documentation brings examples for each provider.

When to use Mem0 and when model memory is enough

Not every agent needs persistent memory. If the task lasts a few minutes and the context fits in the model's window, keeping conversation history is enough and simpler.

Mem0 makes sense when three conditions appear. First, the agent serves the same user in different sessions. Second, the volume of important facts is too large to fit in the prompt. Third, you want the agent to learn over time, not just within a conversation.

A typical case is a code assistant that remembers the user's repository conventions. Another is a support agent that knows the order history without needing to query the database on every question.

If your flow already uses a database to store state, compare the cost of maintaining that layer with the cost of calling Mem0. In many cases, Mem0 reduces boilerplate code and centralizes extraction logic.

Known limits and best practices

Extracted memory can be wrong. The model can store an inaccurate fact or forget something important. For that reason, treat memory as context, not as a source of truth. For critical data, confirm in the database or in the code.

Another point is privacy. Persistent memory stores user data. If you operate in a corporate environment, configure retention, deletion and tenant isolation before going to production. Mem0 offers configuration options, but the final responsibility is yours.

Best practices that apply to any memory layer:

  • Define a stable user_id and do not reuse ambiguous identifiers
  • Limit the number of memories retrieved so you do not pollute the prompt
  • Periodically review what was saved and remove noise
  • Test with real cases, not just example phrases

If you coordinate several agents in parallel, shared memory can become a bottleneck. In that case, it is worth separating memory per agent and synchronizing only what is common. Also see How to run agents in parallel in VS Code and Multi-agent workflows on bridgecode to keep each agent in its isolated space.

Frequently asked questions about Mem0

Is Mem0 free?

Mem0 is open source with Apache 2.0 license. You can run it locally at no cost. If you use a paid provider for fact extraction, the cost comes from that provider, not from the library.

Do I need a separate vector database to use Mem0?

No. Mem0 comes with a default configuration to get started. In production, you can point to an external vector database, such as Qdrant, Pinecone or Weaviate, according to the official documentation.

Does Mem0 replace LangChain or CrewAI?

No. It complements them. LangChain and CrewAI orchestrate agents and tools. Mem0 handles long term memory. You can use both together.

How does Mem0 decide what to store?

It uses a language model to extract relevant facts from each interaction. You do not write manual rules. If you want more control, the documentation shows how to customize the extraction prompt.

Does Mem0 work with local models?

Yes, as long as the model is accessible via an API compatible with OpenAI. Servers like Ollama and vLLM work. Check the supported version in the documentation before adopting in production.

Frequently asked questions about Mem0

Is Mem0 free?

Mem0 is open source under the Apache 2.0 license. You can run it locally at no cost. If you use a paid provider for fact extraction, the cost comes from that provider, not the library.

Do I need a separate vector database to use Mem0?

No. Mem0 comes with a default setup to get started. In production, you can point it to an external vector database, such as Qdrant, Pinecone or Weaviate, as described in the official documentation.

Does Mem0 replace LangChain or CrewAI?

No. It complements them. LangChain and CrewAI orchestrate agents and tools. Mem0 handles long term memory. You can use them together.

How does Mem0 decide what to store?

It uses a language model to extract relevant facts from each interaction. You do not write manual rules. If you want more control, the documentation shows how to customize the extraction prompt.

Does Mem0 work with local models?

Yes, as long as the model is accessible via an OpenAI compatible API. Servers like Ollama and vLLM work. Check the supported version in the documentation before adopting in production.

Conclusion

Persistent memory is what separates a demo agent from an agent that really works. Mem0 delivers this layer with a few lines of code and a permissive license. Start small, with one user and one use case, and expand after measuring the quality of the retrieved memories.

If you coordinate several agents, each in its role and in its isolated space, long term memory becomes a shared asset. On bridgecode you assemble this squad and follow each step, from planning to delivery.

Source: mem0ai/mem0

Share this article

Add bridgecode as a source on Google
Tags:#mem0#agentes de IA#memória#Python#open source
Marcelo Santiago
Marcelo Santiago·Creator of bridgecode

Developer and creator of bridgecode, an agentic development environment for orchestrating squads of AI agents. Helps people going from vibe coding to professional development move from idea to shipped product.

The biggest AI newsletter in the World

Enjoyed this content? Stay ahead in AI engineering.

Code analysis, multi-agent architecture, token benchmarks and tools selected by developers for developers.

Daily at 8:00 and 16:00 Brasília time. No spam.