Skip to main content

Memory Tools

Prebuilt tools that give an agent access to long-term memory — the ability to store, search, update, and delete facts across conversations.

Import path: agentflow.prebuilt.tools

There are three tools, each for a different memory integration path:

ToolPathOperations
memory_toolManual / MemoryIntegration wiringsearch, store, update, delete
user_memory_toolAgent(memory=MemoryConfig(...))search, remember
agent_memory_toolAgent(memory=MemoryConfig(...))search (read-only)

All three tools require a configured BaseStore (e.g. a Qdrant-backed store) injected through the DI container or passed explicitly.


memory_tool

The general-purpose LLM-callable memory tool. Use this when wiring memory manually or through MemoryIntegration.

Operations

actionRequired fieldsDescription
searchquerySemantic search across all memories for the current user
storecontent, memory_keySave a new memory (auto-updates if memory_key already exists)
updatememory_id, contentOverwrite a specific memory by ID
deletememory_idRemove a specific memory by ID

Parameters

ParameterTypeDefaultDescription
actionstr"search"One of search, store, update, delete
contentstr""Text to store or update
memory_keystr""Short snake_case key used for dedup (e.g. "user_name")
memory_idstr""ID of the memory to update or delete
querystr""Search query
memory_typestrNoneMemory type ("episodic", "semantic", etc.)
categorystrNoneCategory label for filtering
limitint5Maximum number of search results
score_thresholdfloatNoneMinimum similarity score for search
write_modestr"merge""merge" or "replace" on update

Notes

  • Write operations (store, update, delete) are scheduled as background tasks and return {"status": "scheduled"} immediately.
  • Search flushes pending writes first so results are always up to date.
  • The memory_key field enables automatic deduplication: if a memory with the same key exists it is updated rather than duplicated.

Usage

from agentflow.prebuilt.tools.memory import memory_tool
from agentflow.core.graph import Agent, ToolNode
from agentflow.storage import QdrantStore # or any BaseStore subclass

store = QdrantStore(...)

agent = Agent(
model="gpt-4o-mini",
tool_node=ToolNode([memory_tool]),
system_prompt=[{
"role": "system",
"content": (
"You have long-term memory. "
"Always search memory at the start of a conversation. "
"Store important facts about the user after each interaction."
),
}],
)
app = agent.compile(store=store)

user_memory_tool (factory)

Created via make_user_memory_tool(memory_config). Used automatically by Agent(memory=MemoryConfig(...)) — you do not normally need to instantiate it yourself.

Operations

actionRequired fieldsDescription
searchtextSemantic search over user-scoped memories
remembertextSave a user fact or preference

Parameters

ParameterTypeDefaultDescription
actionstr"search""search" or "remember"
textstrrequiredQuery text or text to remember
memory_typestrNoneOverride the configured memory type
categorystrNoneOverride the configured category
limitintNoneOverride the configured result limit

Usage via MemoryConfig

from agentflow.core.graph import Agent
from agentflow.storage.store.memory_config import MemoryConfig, UserMemoryConfig

agent = Agent(
model="gpt-4o-mini",
memory=MemoryConfig(
store=store,
user_memory=UserMemoryConfig(enabled=True),
),
)
# The user_memory_tool is registered automatically.
app = agent.compile(store=store)

agent_memory_tool (factory)

Created via make_agent_memory_tool(memory_config). Read-only — the LLM can search agent-scoped or app-scoped memories but cannot write them.

Operations

ParameterRequiredDescription
queryrequiredSemantic search query
memory_typeNoneOverride configured memory type
categoryNoneOverride configured category
limitNoneOverride result limit

Usage via MemoryConfig

from agentflow.storage.store.memory_config import MemoryConfig, AgentMemoryConfig

agent = Agent(
model="gpt-4o-mini",
memory=MemoryConfig(
store=store,
agent_memory=AgentMemoryConfig(
enabled=True,
agent_id="my-agent-v1",
),
),
)
app = agent.compile(store=store)

Example: manual wiring with memory_tool

from agentflow.prebuilt.tools.memory import memory_tool
from agentflow.prebuilt.agent import ReactAgent
from agentflow.storage import create_local_qdrant_store
from agentflow.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",
tools=[memory_tool],
system_prompt=[{
"role": "system",
"content": (
"You have persistent memory. At the start of every conversation, "
"call memory_tool with action='search' to recall relevant context. "
"After the conversation, store important new facts with action='store'."
),
}],
)
app = agent.compile(store=store)

result = await app.ainvoke(
{"message": "My name is Alice and I prefer Python."},
config={"thread_id": "t1", "user_id": "alice"},
)