Memory Tools
In shortuser_memory_tool and agent_memory_tool give an Agent long-term memory to search and remember facts across conversations, enabled with MemoryConfig.
- 6 min read
- 7 sections
- Updated
- v1.0.0
- Markdown
10xGraph memory tools give agents long-term memory: facts and preferences that persist across conversations and threads. Your agent can search what it has learned about users and save new observations. Both tools use semantic search, so the agent finds relevant information by meaning, not by keyword.
There is one way to turn memory on: pass memory=MemoryConfig(...) to the Agent (or ReactAgent). The Agent creates the tools for you. The older general-purpose memory_tool and the graph-level MemoryIntegration were removed.
Import path: tenxgraph.storage.store for MemoryConfig, UserMemoryConfig and AgentMemoryConfig.
Which tool to use
| Tool | When to use | Enabled by | Operations |
|---|---|---|---|
user_memory_tool |
Memory scoped to individual users | MemoryConfig(user_memory=...); on by default |
search, remember, forget |
agent_memory_tool |
Read-only, application-wide memory (for example a knowledge base or policies) | MemoryConfig(agent_memory=AgentMemoryConfig(enabled=True, ...)) |
search only |
Both tools need a store (for example PgVectorStore or Qdrant) that supports semantic search. Pass it to MemoryConfig(store=...) or to compile(store=...). The Agent registers the tools on its ToolNode only when MemoryConfig.retrieval_mode is postload (the default for MemoryConfig). With preload, the Agent searches once per invocation and adds the memories to the latest user message as a fenced block (see Why memories are not system text); the model still gets user_memory_tool, with remember and forget only, and no agent_memory_tool. With no_retrieval, the model has no memory tools and nothing is injected.
How memory works
Writes run asynchronously in the background. When the agent calls remember, the tool returns {"status": "scheduled", "action": "remember"} immediately, and the write happens later without blocking the conversation. Searches flush any pending writes first, so results reflect the latest data.
Deduplication is by similarity: if the new text is nearly identical to an existing memory (score 0.95 or higher), the write is skipped. The model never provides memory ids. For a fact that can change (an editor, a package manager), it may pass a short memory_key (at most 128 characters): remembering again with the same key replaces the old fact, and forget with that key deletes it under every memory type.
Both tools return JSON. A search returns a list of results, for example [{"id": "...", "content": "...", "score": 0.95, "memory_type": "episodic", "metadata": {}}]. Errors look like {"error": "..."}, for example “user memory is disabled”, “no user memory store configured” or “text is required”.
user_memory_tool, user-scoped memory via Agent config
When you enable user memory in an Agent, the user_memory_tool is registered automatically. You do not need to instantiate it yourself. The tool enforces one scope (one user) and one permission model: the LLM can search, remember and forget by memory_key, but never edits a memory by id. User memory is enabled by default in MemoryConfig.
Operations
| Action | Required parameters | Description |
|---|---|---|
search |
text |
Search for user-scoped memories. Returns up to limit results. |
remember |
text, optional memory_key |
Save a user fact or preference. With a memory_key, replaces the fact saved earlier under that key. Near-identical text is skipped. |
forget |
memory_key |
Delete the facts saved under that key. |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
action |
str |
"search" |
One of search, remember or forget. |
text |
str |
"" (required in practice) |
For search, the query text. For remember, the text to save. Supports natural language. |
memory_key |
str |
None |
Stable key for a fact that can change; required for forget. |
memory_type |
str |
inherited | Override the configured memory type (e.g. "episodic", "semantic"). If not set, uses the type from UserMemoryConfig. |
category |
str |
inherited | Override the configured category. If not set, uses the category from UserMemoryConfig. |
limit |
int |
inherited | Override the configured result limit. If not set, uses the limit from UserMemoryConfig. |
Setup
Enable user memory in an Agent by passing a MemoryConfig with user_memory enabled:
# pip install "10xgraph[openai,qdrant]"
from tenxgraph.prebuilt.agent import ReactAgent
from tenxgraph.storage.store.memory_config import MemoryConfig, UserMemoryConfig
from tenxgraph.storage import create_local_qdrant_store
from tenxgraph.storage.store.embedding import OpenAIEmbedding
from tenxgraph.core.state import Message
store = create_local_qdrant_store(
path="./memory_db",
embedding=OpenAIEmbedding(model="text-embedding-3-small"),
)
agent = ReactAgent(
model="gpt-4o-mini",
memory=MemoryConfig(
store=store,
user_memory=UserMemoryConfig(
enabled=True,
memory_type="semantic", # e.g. facts and preferences
category="user_profile",
limit=10, # return up to 10 results per search
),
),
system_prompt=[{
"role": "system",
"content": "You remember details about each user. Use user_memory_tool to search and remember key facts.",
}],
)
app = agent.compile(store=store)The user_memory_tool is now available to the LLM. It is scoped to the caller. With an authenticated identity (config["user"], which the API server sets from the verified token), the identity’s user_id always wins, and a UserMemoryConfig(user_id=...) value is ignored, so a fixed id never shares one user’s memory with every caller. Without an identity (direct SDK use), UserMemoryConfig(user_id=...) replaces config["user_id"], and otherwise the run config’s user_id is used. User memory is always the caller’s own, whatever their reach:
result = await app.ainvoke(
{"messages": [Message.text_message("What do you know about my preferences?")]},
config={"thread_id": "t1", "user_id": "alice"}, # user_id determines memory scope
)agent_memory_tool, read-only application-wide memory
Agent memory is read-only and scoped to the agent or the entire application. Use it for policies, knowledge bases, or shared context that many users should be able to read but not modify.
Operations
| Action | Parameters | Description |
|---|---|---|
search |
query, optional overrides |
Semantic search over agent-scoped or app-scoped memories. Read-only; the LLM cannot write, update, or delete. |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
query |
str |
required | The search query. Supports natural language. |
memory_type |
str |
inherited | Override the configured memory type. |
category |
str |
inherited | Override the configured category. |
limit |
int |
inherited | Override the configured result limit. |
Setup
Agent memory is disabled by default. Enable it in an Agent by passing a MemoryConfig with agent_memory=AgentMemoryConfig(enabled=True, ...). Specify either agent_id (memories shared across all instances of this agent) or app_id (memories shared across the entire application):
# pip install "10xgraph[openai,qdrant]"
from tenxgraph.prebuilt.agent import ReactAgent
from tenxgraph.storage.store.memory_config import MemoryConfig, AgentMemoryConfig
from tenxgraph.storage import create_local_qdrant_store
from tenxgraph.storage.store.embedding import OpenAIEmbedding
store = create_local_qdrant_store(
path="./memory_db",
embedding=OpenAIEmbedding(model="text-embedding-3-small"),
)
agent = ReactAgent(
model="gpt-4o-mini",
memory=MemoryConfig(
store=store,
agent_memory=AgentMemoryConfig(
enabled=True,
agent_id="customer-support-v2", # all instances of this agent share this memory
memory_type="semantic",
category="policies",
limit=5,
),
),
system_prompt=[{
"role": "system",
"content": "You have access to company policies. Use agent_memory_tool to look them up when answering customer questions.",
}],
)
app = agent.compile(store=store)The agent_memory_tool is now available to the LLM in read-only form. It searches shared memory, not a per-user scope. It always runs as the reserved owner system_user_id(agent_id) (here "__system__:customer-support-v2"; with no agent_id it uses the app_id), whichever user is chatting, so every user finds the same records and other agents do not.
Your own code writes that shared memory under the same owner:
from tenxgraph.storage import system_user_id
await store.astore(
config={"user_id": system_user_id("customer-support-v2"), "agent_id": "customer-support-v2", "thread_id": "customer-support-v2"},
content="Refunds are accepted within 30 days with a receipt.",
category="policies",
)Records written under a real user’s id are not found by agent_memory_tool. With QdrantStore, search filters by owner, memory_type and category. Each agent has its own owner, so agents with different agent_id values stay apart even in one collection. See the Memory stores reference for the full user_id rule.
result = await app.ainvoke(
{"messages": [Message.text_message("What is your return policy?")]},
config={"thread_id": "t1", "user_id": "alice"},
)
# The agent can search agent memory (policies) but cannot modify it.
# "alice" does not matter here: agent memory is read as system_user_id("customer-support-v2").Vector store
Both tools need a store that supports semantic search. Setup for Qdrant and PgVectorStore is in Use a memory store.
Run it in production
Memory is scoped to the authenticated user_id that the server supplies. Configure the store through the store key in 10xgraph.json. See Configure the server and the Security model.
Related pages
- Concept: Long-term memory and how it complements thread checkpoints, see
/docs/concepts/memory-and-store - Setup guide: Choose and configure a vector store, see
/docs/guides/use-memory-store - Reference: Full API for
MemoryConfigand store classes, see/docs/reference/python/memory-stores