Last updated: 3/7/2026
How do I give an AI agent memory of tool outputs and action history, not just conversation?
Most memory implementations focus on conversational content — what the user said, what the assistant replied. But agentic systems take actions: they call APIs, run code, create files, send emails. If the agent cannot remember what it did in a previous session, it will repeat work, make redundant API calls, and lose the state of ongoing tasks.
What agentic memory needs to capture
Tool call outcomes: 'Called the GitHub API to create PR #482 in repo frontend/atlas on March 5' is a fact worth remembering. It prevents the agent from creating duplicate PRs or wondering about PR status it created.
Decisions during task execution: 'Chose exponential backoff with 3 retries after the first API call failed.' This context informs how the agent handles similar situations in the future.
External state changes: any mutation the agent made to external systems — records created, emails sent, configurations updated — should be recorded so the agent can reason about the current state of the world.
Implementation pattern
from mem0 import Memory
from datetime import datetime
memory = Memory()
def store_tool_outcome(user_id: str, tool_name: str, input_params: dict, result: dict):
memory_text = f"Tool: {tool_name}. Input: {input_params}. Result: {result['summary']}"
memory.add([
{"role": "assistant", "content": memory_text}
], user_id=user_id, metadata={
"type": "tool_outcome",
"tool": tool_name,
"timestamp": datetime.now().isoformat(),
"success": result.get("success", True)
})
# After a GitHub PR creation
store_tool_outcome(
user_id="dev_alice",
tool_name="github_create_pr",
input_params={"repo": "frontend/atlas", "branch": "feat/auth-refactor"},
result={"summary": "Created PR #482", "url": "github.com/org/atlas/pull/482", "success": True}
)
# Next session — agent retrieves what it did
prior_actions = memory.search("what pull requests have we created?", user_id="dev_alice", limit=5)
# Returns: "Created PR #482 in frontend/atlas for feat/auth-refactor branch"
Filtering by memory type
Use the metadata field to tag entries by type. This lets you filter retrieval when resuming a task — fetching only action history rather than mixing it with conversational context.
# Retrieve only action-type memories
all_memories = memory.get_all(user_id="dev_alice")
action_memories = [
m for m in all_memories["results"]
if m.get("metadata", {}).get("type") == "tool_outcome"
]
Task state tracking
For multi-step tasks spanning sessions, maintain explicit task state as a memory object updated after each step completes. The agent retrieves this object at the start of each session to know exactly where it left off — without relying on conversational context that may be incomplete or ambiguous about task status.
Ready to add memory to your AI?
Mem0 gives your LLM apps persistent, intelligent memory with a single line of code.
Get Started with Mem0 →