# Membase x Dify: How to Add Long-Term Memory to Dify Agents and Workflows

Published: 2026-11-11 · Author: Membase Team  
Source: https://membase.com/blog/dify-agent-memory

A customer tells your Dify support bot that their team wants reports every Monday, sent to the finance channel. A week later they open a new conversation, and the bot asks the same questions again. Dify keeps the current conversation in context, but nothing carries over to the next one.

The Membase plugin fixes that. It brings long-term memory to Dify agents and workflows, so what a user said last week is there today, with the source of every memory cited. The plugin is live on Dify Marketplace and Verified by Dify.

> **Quick answer**
>
> 1. Create a Memory and a developer key in the [Membase app](https://app.membase.com).
> 2. Install **Membase** from Dify Marketplace.
> 3. Authorize the plugin with your key.
> 4. Add **Search memory** before your LLM, and **Save memory** for when the user asks to remember something.
> 5. Test it in a new conversation: the answer should cite the Memory it came from.

![Membase x Dify: a chatflow searches Membase before the LLM answers, saves only when the user asks, and other AI tools read the same memory over MCP](https://dmc2j1nsu0tnv.cloudfront.net/1794389425991-TMCP-membase-dify-diagram.png)

## What memory does Dify have today?

Dify gives you three ways to keep context. Each is good at one job:

| | Built-in memory | Conversation variables | Knowledge base |
|---|---|---|---|
| What it keeps | Recent messages of the current conversation | Values your flow sets during a conversation | Documents you upload |
| How long it lasts | The current conversation | The current conversation | Until you change the documents |
| Learns from users | No | Only what your flow writes | No |
| Good for | Follow-up questions | Form state, counters, flags | Product docs, policies, FAQs |

None of them remembers what a user told your app in an earlier conversation. That is the gap long-term memory fills: preferences, decisions and facts about a user that should still be known next week, in any conversation or app.

## Why Membase for Dify agents?

1. **Memory that outlasts the conversation.** What a user says today is there next week, in a new conversation or another Dify app.
1. **Saves only what the user asks to keep.** The save tool tells the model to save only when the user asks to remember something, so memory does not fill with guesses.
1. **Every recalled passage cites its source.** Each passage names the Memory it came from, so the answer can tell the user where it learned a fact.
1. **Control over what each app 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.
1. **One memory across Dify and your other AI tools.** ChatGPT, Claude, Claude Code, Cursor and Codex read the same memory over MCP.

## How the Membase plugin works

The plugin adds three tools to Dify. They work like any other tool node, with no code:

| Tool | What it does |
|---|---|
| **Search memory** | Finds the passages that answer a question, across every Memory the key reaches, most relevant first. Each passage names the Memory it came from. |
| **Save memory** | Saves one fact, in the user's words, to the key's Memory. Only when the user asks. |
| **Get user profile** | Reads the profile facts: standing statements about who the user is, newest first. |

Each tool returns a readable text output and a json output. In the text output, every passage looks like [Memory name] content, so an LLM node can quote the source directly.

There is no delete tool. Deleting memory is done by the account owner in the Membase app.

## How to add long-term memory to a Dify agent

### Prerequisites

- A Dify workspace that can install plugins, on Dify Cloud or self-hosted.
- A free Membase account at [app.membase.com](https://app.membase.com), with a working model under AI Setup.
- For self-hosted Dify: outbound HTTPS to api.app.membase.com on port 443.

## Step 1: Create a Memory and a key

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

- Choose **Read & write** if the app should save memories, or **Read** if it should only search.
- Choose which Memories the key may reach. A key that should save must reach exactly one Memory, which becomes its write target.
- Tick the profile if the app should read it.

## Step 2: Install the plugin

In Dify, open **Plugins › Marketplace**, search for **Membase** and install it. The plugin carries the Verified by Dify badge.

## Step 3: Authorize it

Open **Plugins › Membase › Authorize** (or **Tools › Membase**) and enter:

| Field | Required | Value |
|---|---|---|
| Membase API key | Yes | The key from Step 1, starting with `mbk_` |
| Base URL | No | Leave empty for the Membase cloud |

Dify checks the key against the Membase API when you save. A mistyped, expired or revoked key is rejected at this step.

## Step 4: Add memory to an agent

In an Agent app, add **Search memory**, **Get user profile** and, if the key can write, **Save memory** to the agent’s tools.

The tool descriptions already tell the model when to use each one: read the profile once near the start, search before answering anything that depends on what the user said before, and save only when the user asks to remember something. Add one line to the instructions:

```text
Cite the Memory name when you use a memory.
```

## Step 5: Or build a memory loop in a chatflow

For more control, build the loop yourself:

1. A **Search memory** tool node, with the user’s message as query. You can set limit from 1 to 50 passages.
1. An **LLM** node that receives the search node’s text output as context.
1. Optionally, a **Save memory** node on a branch that runs only when the user asks to remember something, with the fact as content.

Keep Dify’s built-in memory switched on in the LLM node for the current conversation. Membase adds what came before it.

## Verify that memory is working

1. Start a conversation and say:

   ```text
   Remember that Acme wants weekly reports on Mondays, sent to the finance channel.
   ```

2. Wait a short while. Membase accepts the note at once and learns it in the background.

3. Open a **new** conversation and ask:

   ```text
   When and where should I send Acme's report?
   ```

4. The answer should say Monday, in the finance channel, and cite [Customer notes].

5. Open Claude or Cursor connected to the same Memory and ask the same question. The answer is the same, because the fact lives in Membase, not in Dify.

## What you can build

- **Customer support assistant.** Save each customer’s preferences and past resolutions when the agent is asked to. Search them before drafting a reply, so customers never repeat themselves.
- **Account notes for sales and success teams.** Save decisions from each call. Before the next call, the agent recalls what was agreed and who asked for what.
- **Personal research assistant.** Save the sources, conclusions and open questions you ask it to keep. Pick up next week where you left off, in Dify or in Claude.

## Multi-user apps: One key per user with Dify’s MCP tool

Dify stores plugin credentials per workspace. So every end user of an app that uses the plugin reads, and can write, the same Membase account: the one that owns the key. That suits a personal assistant or an internal tool. It does not suit an app with many end users, who would all see each other’s memory.

For a multi-user app, give each end user their own Membase key and use Dify’s built-in MCP tool instead of the plugin:

1. In Dify, open **Tools › MCP** and add an MCP server (HTTP).
1. Server URL: [https://api.app.membase.com/mcp-http](https://api.app.membase.com/mcp-http)
1. Under the advanced options, add this header:

   ```text
   Authorization: Bearer {{request.headers.X-Membase-Key}}
   ```

4. Your backend calls the Dify app API with each user’s own key in an X-Membase-Key header. Dify fills in the placeholder at call time, so each run reaches only that user's memory.

The placeholder is filled only for runs started by an HTTP request to the app. The console’s debug preview has no such header.

## 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 memory works but Save memory reports that there is no write target. Give writer apps 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

The plugin uses one key per workspace, so all end users share one memory. For an app with many users, use the MCP setup above.

### No working model in the Membase account

Membase needs a model under AI Setup in the Membase app. Without one, searches report the Memory as unavailable, which is different from “no memory found”.

### The first search is slow

The first search after a quiet spell can take up to a minute while the account’s memory wakes. Later calls are faster.

## Key takeaways

1. Dify’s built-in memory keeps the current conversation. Membase keeps what should be known next week.
1. Search before the LLM, and save only when the user asks.
1. Every recalled passage names the Memory it came from, so answers can cite their source.
1. Use a Read key for apps that should only search, and a Read & write key with one Memory for apps that save.
1. For apps with many end users, give each user their own key through Dify’s MCP tool.

## Next steps

1. Create a free key in the [Membase app](https://app.membase.com) under Connect › Developer keys.
1. Install **Membase** from Dify Marketplace (**Plugins › Marketplace**).
1. Follow the steps above, then run the test in “Verify that memory is working”.

The plugin source, its README and privacy policy are on [GitHub](https://github.com/unibaseio/membase/tree/main/integrations/dify).

## Resources

- [Membase plugin source on GitHub](https://github.com/unibaseio/membase/tree/main/integrations/dify): README, privacy policy and examples
- [Dify Marketplace](https://marketplace.dify.ai): search for Membase
- [How to Share Memory Between Multiple AI Agents](https://membase.com/blog/how-to-share-memory-between-ai-agents): per-agent keys and one shared memory
- [Membase x LangGraph: Shared Long-Term Memory for Multi-Agent Systems](https://membase.com/blog/langgraph-multi-agent-memory): the same memory in LangGraph agents
- [Membase x Microsoft Agent Framework: Long-Term Memory for AI Agents](https://membase.com/blog/microsoft-agent-framework-memory): long-term memory for Microsoft Agent Framework agents
- [Membase x Agno: Long-Term Memory for AI Agents](https://membase.com/blog/agno-memory): long-term memory for Agno agents

## Quick links

**Get started**

- [Get started with Membase](https://app.membase.com): create a Memory and connect your first AI. Free during the beta; paid plans are coming soon.
- [Membase Chrome Extension](https://membase.com/chrome-extension): save and reuse context in ChatGPT, Claude, Gemini, Grok, DeepSeek and Kimi
- [Connect your AI](https://docs.membase.com/connect/): setup guides for ChatGPT, Claude, Claude Code, Cursor, Codex and Grok
- MCP server: [setup guide](https://docs.membase.com/connect/clients/membase-mcp/) · endpoint [https://api.app.membase.com/mcp-http](https://api.app.membase.com/mcp-http)
- [Your first Memory](https://docs.membase.com/use/getting-started/quickstart/): the app quickstart
- [What Is Cross-AI Memory?](https://unibase.com/blog/what-is-cross-ai-memory): the idea behind one memory across AI assistants

**For developers**

- Get an API key: [Membase Web App](https://app.membase.com) → Connect › Developer keys
- Python SDK: [unibaseio-membase on PyPI](https://pypi.org/project/unibaseio-membase/) · pip install unibaseio-membase
- TypeScript SDK: [@unibaseio/membase on npm](https://www.npmjs.com/package/@unibaseio/membase) · npm install @unibaseio/membase
- CLI: [@unibaseio/membase-cli on npm](https://www.npmjs.com/package/@unibaseio/membase-cli) · npm install -g @unibaseio/membase-cli
- [API quickstart](https://docs.membase.com/build/getting-started/api-quickstart/) · [SDK reference](https://docs.membase.com/build/reference/sdk-quickstart/): methods, REST routes and MCP tools
- Source and examples: [github.com/unibaseio/membase](https://github.com/unibaseio/membase) · [Membase use cases on GitHub](https://github.com/unibaseio/membase-use-cases)
- [Membase Research](https://membase.com/research): benchmarking long-term memory for agents

**Videos**

- [How to Add Long-Term Memory to an AI Agent with the Membase SDK in 1 Minute](https://www.youtube.com/watch?v=iN60c5j0vFY)
- [Give Claude Code Permanent Memory in 60 Seconds (MCP)](https://www.youtube.com/watch?v=G6mH6uziDuM)

**Help**

- [Discord](https://discord.gg/nB9EfPGsSf) · [Telegram](https://t.me/unibase_ai) · [Feedback form](https://forms.gle/mXtMLqe4MrRcHyGT9)
- [Privacy policy](https://membase.com/privacy)

## Frequently Asked Questions

### Does Dify have long-term memory?

Dify's built-in memory keeps the recent messages of the current conversation, and conversation variables last for the conversation too. For memory that lasts across conversations and apps, add a memory plugin such as Membase.

### What is the difference between Dify's built-in memory and Membase?

Built-in memory keeps recent messages within one conversation. Membase keeps long-term memory that lasts until you delete it, and is shared across conversations, Dify apps and other AI tools.

### Do I need to write code?

No. The plugin adds tools you drop into an agent or a chatflow. Code is only needed on your backend for the multi-user MCP setup.

### Can each user of my Dify app have their own memory?

Yes. Give each user their own Membase key and connect Membase through Dify's MCP tool, passing the key in a request header. The plugin alone shares one memory per workspace.

### Can the agent forget something?

There is no delete tool in Dify. The account owner deletes memories in the Membase app.

### Is the Membase plugin free?

Membase is free during the beta. Paid plans are coming soon.
