Memory
Let an agent remember facts about each user across runs, stored locally or in Supermemory or Zep.
Give an agent a memory provider and it can save facts in one run and recall them in later runs. Each user's memories are kept apart, and you decide whether the agent may write without asking.
import { agent, localMemory } from "@threads/core";
const assistant = agent({
name: "assistant",
instructions: "Remember what users tell you about themselves.",
model,
memory: localMemory(),
memoryWrite: "allow",
});Providers
| Provider | TypeScript | Python | Stored in |
|---|---|---|---|
| Local | localMemory() from @threads/core | local_memory() from threads | The run's own SQLite store. Full-text search, no extra service. |
| Supermemory | supermemory() from @threads/supermemory | supermemory() from threads.supermemory | Supermemory. Reads SUPERMEMORY_API_KEY unless you pass apiKey / api_key. |
| Zep | zep() from @threads/zep | zep() from threads.zep | Zep Cloud. Reads ZEP_API_KEY unless you pass apiKey / api_key. |
import { supermemory } from "@threads/supermemory";
import { zep } from "@threads/zep";
memory: supermemory(), // SUPERMEMORY_API_KEY
memory: zep(), // ZEP_API_KEYBoth hosted providers also take a base URL (baseUrl / base_url) for a proxy or self-hosted endpoint. The key is resolved on the host at setup, so agent.check() reports a missing key as missing_secret before anything runs, and the run keeps what setup resolved.
A mem0() factory exists in both languages, but it is refused when the agent is set up (transport_fence_unsupported): the mem0 SDK sends requests threads can't safely wrap. Use Supermemory or Zep instead.
What the agent gets
| Tool | What it does |
|---|---|
save_memory | Save a self-contained fact for later runs. |
search_memory | Search saved facts. Returns up to 5 hits by default (at most 20). |
forget_memory | Delete one saved fact by the id search_memory returned. |
Recalled memories are shown to the model as reference material, never as instructions. A saved line like "ignore your rules" can't take over the agent.
Who may write: memoryWrite
Saving and forgetting change stored data, so they go through the agent's permissions like any other action. memoryWrite (Python memory_write) adds a memory-specific rule on top:
| Value | Writes |
|---|---|
"ask" (default) | Always ask for approval. |
"allow_principal" | Allowed only when the user wrote the turn themselves and nothing untrusted (tool output, fetched pages, other people's messages) is in the conversation. Otherwise ask. |
"allow" | Follow the permission rules. |
"deny" | Never. |
memoryWrite can only make things stricter. To let writes run without approval, also allow the tools in your permission rules, for example permissions: { allow: ["save_memory", "forget_memory"] }. Otherwise the run parks for approval.
Scopes and tenants
You never pass a scope. threads picks it from who is talking:
- Per tenant. Memories never cross tenants.
- Per agent. Each agent name has its own memories.
- Per user. Within a tenant and agent, each user (the verified principal that sent the message) has their own memories. In a shared thread, such as a Slack channel, each message is answered from its sender's memory.
Without a host, runs use a single local operator user, so all local runs of an agent share one memory. The model can't choose or change the scope: it isn't a tool argument.
Crash safety
localMemory() writes are safe to retry: saving the same fact twice stores it once. Supermemory and Zep have no way to spot a repeated write, so if the host crashes during one, threads doesn't retry it on its own. The run parks and waits for you. See Durability.
Your own provider
Implement the MemoryProvider interface (remember, recall, forget) to plug in any other store.