1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
18 small wins to finish your pathNext lesson →
Memory tools: manage and search
create_manage_memory_tool and create_search_memory_tool give an agent memory as tools: it decides during the conversation what to save and when to look.
save = create_manage_memory_tool(namespace=("memories", "{user_id}"), store=store)
print(save.name, "|", save.description.splitlines()[0])
print(list(save.args))
asha = {"configurable": {"user_id": "asha"}}
print(save.invoke({"content": "Order A-1001 arrived broken", "action": "create"}, config=asha)[:15])A tool is what a model sees: a name, a description and arguments. manage_memory takes content, an action of create, update or delete, and an id for the last two. Invoking it directly, as here, does what an agent's call would do, and returns the text the agent reads back, with the new memory's id.
find = create_search_memory_tool(namespace=("memories", "{user_id}"), store=store)
results = json.loads(find.invoke({"query": "broken order"}, config=asha))
for row in results:
print(row["value"], round(row["score"], 3))search_memory returns JSON the model reads: each item with its namespace, key, value, timestamps and score, best match first.
Hot path or background
| Memory tools | Store manager | |
|---|---|---|
| Who decides | The agent, during the chat | A separate call after the chat |
| Latency | Adds tool calls to the reply | None for the user, if run in the background |
| Good for | "Remember this" requests | Picking up what the user did not ask to save |
Try it yourself
- Update the saved memory with
action="update"and its id. - Create the tool with
actions_permitted=("create",)and print itsargs. - Search with a query that shares no words with either memory.
You understood something today that you didn't yesterday.