Memory Concept
Memory is how an AI agent stores and recalls information during a task or across tasks. Without memory, agents cannot maintain context over long multi-step processes.
8 min•By Priygop Team•Updated 2026
Types of Memory in AI Agents
- Short-term memory (within a task): the agent's working memory during the current task, stored in the context window
- Long-term memory (across tasks): information stored externally (in a file, database, or vector store) and retrieved when needed
- Working notes: the agent writes down intermediate results so they are available for later steps
- Conversation history: the full history of the current interaction, kept in the context
- External storage: for information too large to fit in the context window, stored in files or databases
Practical Memory Management
Practical Memory Management
# Simple agent memory management concept
class AgentMemory:
"""Simple agent working memory implementation."""
def __init__(self):
self.short_term = [] # Current task steps and observations
self.notes = {} # Key findings the agent wants to remember
def add_observation(self, step, observation):
"""Record what happened at each step."""
self.short_term.append({
"step": step,
"observation": observation
})
print(f"Memory: Recorded step {step} -> {observation[:60]}...")
def save_note(self, key, value):
"""Save a key finding for later use in the task."""
self.notes[key] = value
print(f"Memory: Saved '{key}'")
def recall(self, key):
"""Retrieve a previously saved note."""
return self.notes.get(key, "Not found in memory")
def get_context_summary(self):
"""Get a summary of everything done so far."""
summary = f"Steps completed: {len(self.short_term)}\n"
summary += f"Key notes: {list(self.notes.keys())}\n"
return summary
# Simulate an agent using memory during a research task
memory = AgentMemory()
memory.add_observation("Step 1", "Found 10 Python visualization libraries via web search")
memory.save_note("top_libraries", ["Matplotlib", "Seaborn", "Plotly", "Bokeh", "Altair"])
memory.add_observation("Step 2", "Retrieved GitHub star counts for all 5 libraries")
memory.save_note("stars", {"Matplotlib": 18000, "Plotly": 14000, "Seaborn": 12000})
print()
print("Agent memory summary:")
print(memory.get_context_summary())
print()
print("Recalling top libraries:", memory.recall("top_libraries"))Diagram
Loading diagram…
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Key Takeaways
- Memory is how an AI agent stores and recalls information during a task or across tasks.
- Short-term memory (within a task): the agent's working memory during the current task, stored in the context window
- Long-term memory (across tasks): information stored externally (in a file, database, or vector store) and retrieved when needed
- Working notes: the agent writes down intermediate results so they are available for later steps