Skip to content
Membase
Membase x Agno: Long-Term Memory for AI Agents

Membase x Agno: Long-Term Memory for AI Agents

Research
MembaseMembase Team
View the original post on Medium

A user tells your Agno agent their name, their city and their plans. Next week they come back through a different app, or ask Claude Code instead, and nothing they said is there. Agno can keep user memories in your own database, but that memory stays inside one Agno app.

Membase gives Agno agents long-term memory that every tool can share. The agent recalls what the user said before it answers, cites the Memory each fact came from, and saves only when the user asks. Membase is one of the memory integrations in Agno’s official cookbook, added in PR #11552 and listed next to Mem0, Zep and Memori.

Quick answer

  1. Create a Memory and a developer key in the Membase app.
  2. pip install agno openai unibaseio-membase
  3. Search Membase before the run and pass the cited passages to the agent as context.
  4. Give the agent save_memory and search_memory tools for the rest.
  5. Run it in a new session, or ask Claude Code: the memory is the same.

Membase x Agno: an Agno agent recalls cited memories before it answers, saves when the user asks, and other AI tools read the same memory over MCP

Why Membase for AI agents?

  1. Memory that outlasts the app. What a user tells one Agno agent is there for every other agent, app and AI tool that reaches the same Memory.
  2. Every recalled passage cites its source. Each search result names the Memory it came from, so the agent can tell the user where it learned a fact.
  3. Saves only what the user asks to keep. Saving is a tool the model calls when the user asks to remember something, so memory does not fill with guesses.
  4. Control over what each agent can do. A Read key can only search. A Read & write key can also save. You choose which Memories each key reaches, and you can revoke a key at any time.
  5. Hosted or local. Use the hosted service, or keep memory on your own machine with local mode.

How Membase works with Agno

The integration uses the Membase Python SDK directly, with two building blocks:

Building blockWhat it does
Recall before the runclient.search() returns the passages that answer a question, each tagged with the Memory it came from. Pass them to the agent through dependencies, so they are in context from the first token.
Memory toolsTwo plain Python functions, save_memory and search_memory, that Agno turns into tools. The model saves when the user asks and searches when it needs more than the recall gave it.

This is the same pattern as the example in Agno’s cookbook at cookbook/11_memory/integrations/membase_integration.py.

Memory in practice: Building an Agno agent that remembers

What you will build:

  • An agent that recalls cited memories before it answers.
  • Tools that save only when the user asks, and search when the agent needs more.
  • Claude Code connected to the same memory.

Step 1: Create a Memory and a key

In the Membase app, create a Memory, for example “Personal”. Then open Connect › Developer keys and create a key:

  • Choose Read & write if the agent should save memories, or Read if it should only search.
  • A key that should save must reach exactly one Memory, which becomes its write target. A key that reaches several Memories can search them all but cannot save.

Step 2: Install

pip install agno openai unibaseio-membase
export MEMBASE_API_KEY=mbk_...
export OPENAI_API_KEY=sk-...

Step 3: Add some memories

from membase import Membase

client = Membase()  # reads MEMBASE_API_KEY from the environment

for note in [
    "My name is John Billings.",
    "I live in NYC.",
    "I'm going to a concert tomorrow.",
]:
    client.memories.add(note)

Membase accepts each note at once and learns it in the background, so give it a short while before you search.

Step 4: Recall before the run

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from membase import Membase

client = Membase()

results = client.search("What do you know about the user?", limit=10)
memory = [f"[{item['memory_name']}] {item['content']}" for item in results["items"]]

agent = Agent(
    model=OpenAIChat(),
    instructions="When you use a fact from memory, say which Memory it came from.",
    dependencies={"memory": memory},
    add_dependencies_to_context=True,
)

agent.print_response("What do you know about me?")

The agent answers with John’s name, city and plans, and cites the Memory each fact came from, for example [Personal].

Step 5: Give the agent memory tools

Recall covers what you searched for before the run. For everything else, give the agent two tools:

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from membase import Membase

client = Membase()

def save_memory(fact: str) -> str:
    """Save one fact about the user to long-term memory. Only call this when the user asks you to remember something."""
    client.memories.add(fact)
    return "Saved."

def search_memory(query: str) -> str:
    """Search the user's long-term memory. Each result names the Memory it came from."""
    results = client.search(query, limit=5)
    return "\n".join(f"[{item['memory_name']}] {item['content']}" for item in results["items"]) or "Nothing found."

agent = Agent(
    model=OpenAIChat(),
    instructions="Search memory before answering anything about the user. Cite the Memory each fact came from.",
    tools=[save_memory, search_memory],
)
agent.print_response("Remember that I prefer window seats when I fly.")

Agno reads each function’s docstring as the tool description, so the model knows to save only when asked.

Step 6: Give Claude Code the same memory

claude mcp add --transport http membase https://api.app.membase.com/mcp-http

Claude Code opens your browser to approve access. Tick “Personal” and approve. This connection is read-only, so Claude Code can search the memory but not change it. Setup for Cursor, Codex, ChatGPT and other clients is in Connect your AI.

Step 7: Verify that memory is working

  1. Run Step 5 and confirm the agent says it saved the window seat preference.
  2. Wait a short while for Membase to learn it.
  3. Start a new agent and ask: “Where do I like to sit when I fly?”
  4. The answer should say window seats and cite the Memory it came from.
  5. Ask Claude Code, connected in Step 6, the same question. The answer is the same, because the fact lives in Membase, not in the agent.

Memory types in Agno: Sessions, user memories and Membase

Session historyAgno user memoriesMembase
What it keepsThe messages of one sessionFacts about a user, stored in your databaseLong-term memory learned from what users save
How long it lastsThe sessionUntil you delete itUntil the user deletes it
Shared acrossOne sessionAgents that use the same databaseAgents, apps, frameworks and AI tools
Shared with other AI toolsNoNoYes: ChatGPT, Claude, Claude Code, Cursor and Codex over MCP
Good forFollow-up questionsPersonalization inside one Agno appMemory that every tool should know

Keep Agno’s session history for the current conversation, and its user memories if one app is enough. Add Membase when the memory should reach every agent and tool the user works with.

Common mistakes

The key reaches several Memories, so nothing is saved

A key can save only when it reaches exactly one Memory. If it reaches several, search works but saving does not. Give writer agents a key with one Memory in reach.

Searching right after saving

Membase learns new notes in the background. A search a second after a save may not find the note yet. Wait a short while, then search.

Sharing one key across all users

One key is one person’s memory. For an app with many users, give each user their own Membase key and create the client per user, for example Membase(api_key=user_key).

Saving every message

Saving everything fills memory with noise. Keep save_memory for facts the user asks you to remember, as the docstring says.

Building better agents with long-term memory

Agents feel forgetful when every app starts from zero. With Membase, a fact is saved once and every Agno agent, every app and every AI tool the user works with starts from the same context, with the source of each fact cited. Agno keeps orchestrating the agent, sessions keep the conversation, and Membase keeps what your users told you.

What teams build with it:

  • Personal assistant. Save the user’s preferences and plans when they ask. Every agent knows them, and so does Claude.
  • Customer support agent. Save each customer’s preferences with one key per customer. Recall them before every reply, so customers never repeat themselves.
  • Research agent. Save sources and conclusions as you go. Pick up next week where you left off, in Agno or in Claude Code.

Getting started

  1. Create a free key in the Membase app under Connect › Developer keys.
  2. pip install agno openai unibaseio-membase
  3. Follow the steps above, then run the test in Step 7.

The full example is in Agno’s cookbook: membase_integration.py.

Resources

Get started

For developers

Videos

Help

Frequently Asked Questions

Does Agno have long-term memory?
Yes. Agno can store user memories in your own database, shared by the agents that use it. For memory that also reaches other apps, frameworks and AI tools, add a memory layer such as Membase.
What is the difference between Agno's memory and Membase?
Agno's user memories live in your app's database. Membase keeps long-term memory that the user controls and that every connected agent and AI tool can read, with the source of each fact cited.
Is Membase an official Agno integration?
Membase is one of the memory integrations in Agno's official cookbook, added in PR #11552 and listed next to Mem0, Zep and Memori.
Can each user have their own memory?
Yes. One Membase key is one person's memory. Give each user their own key and create the client with it.
Can I keep memory on my own machine?
Yes. Install unibaseio-membase[local] and create the client with a local directory instead of a key. Memory stays on your machine.
Is Membase free?
Membase is free during the beta. Paid plans are coming soon.
Back to all posts