Skip to main content

Overview

The Agno Memory Agent demonstrates how to create intelligent agents with persistent memory capabilities using the Agno framework and Nebius AI models. This example shows both agentic memory (agent-controlled memory updates) and user memories (automatic memory extraction from conversations).

Key Features

  • Persistent Memory: SQLite-based memory storage across sessions
  • Agentic Memory: Agents actively manage their own memories
  • User Memories: Automatic memory extraction from conversations
  • Chat History: Complete conversation history with configurable retention
  • Streaming Responses: Real-time agent responses with intermediate steps

Memory Architecture

Memory Storage

Agno uses a dual-storage system:
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.storage.sqlite import SqliteStorage

# Initialize memory system
memory = Memory(
    model=Nebius(id="deepseek-ai/DeepSeek-V3-0324", api_key=os.getenv("NEBIUS_API_KEY")),
    db=SqliteMemoryDb(table_name="user_memories", db_file="tmp/agent.db"),
)

# Initialize chat history storage
storage = SqliteStorage(table_name="agent_sessions", db_file="tmp/agent.db")
The memory system uses two separate tables: user_memories for extracted facts and agent_sessions for chat history.

Agent Configuration

memory_agent = Agent(
    model=Nebius(id="deepseek-ai/DeepSeek-V3-0324", api_key=os.getenv("NEBIUS_API_KEY")),
    memory=memory,
    enable_agentic_memory=True,    # Agent can update memories
    enable_user_memories=True,      # Automatic memory extraction
    storage=storage,
    add_history_to_messages=True,   # Include chat history in context
    num_history_runs=3,             # Keep last 3 conversation runs
    markdown=True,
)

Implementation Example

Basic Memory Usage

from agno.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.nebius import Nebius
from agno.storage.sqlite import SqliteStorage
import os

user_id = "user_123"
db_file = "tmp/agent.db"

# Initialize memory and storage
memory = Memory(
    model=Nebius(id="deepseek-ai/DeepSeek-V3-0324", api_key=os.getenv("NEBIUS_API_KEY")),
    db=SqliteMemoryDb(table_name="user_memories", db_file=db_file),
)
storage = SqliteStorage(table_name="agent_sessions", db_file=db_file)

# Create memory-enabled agent
memory_agent = Agent(
    model=Nebius(id="deepseek-ai/DeepSeek-V3-0324", api_key=os.getenv("NEBIUS_API_KEY")),
    memory=memory,
    enable_agentic_memory=True,
    enable_user_memories=True,
    storage=storage,
    add_history_to_messages=True,
    num_history_runs=3,
    markdown=True,
)

# First interaction - introduce yourself
memory_agent.print_response(
    "My name is Arindam and I support Mohun Bagan.",
    user_id=user_id,
    stream=True,
    stream_intermediate_steps=True,
)

# View stored memories
print("Memories about user:")
print(memory.get_user_memories(user_id=user_id))

# Second interaction - agent uses stored memories
memory_agent.print_response(
    "I live in Kolkata, where should I move within a 4 hour drive?",
    user_id=user_id,
    stream=True,
)

# Memory recall
memory_agent.print_response(
    "Tell me about Arindam",
    user_id=user_id,
    stream=True,
)

Memory Types

Agentic Memory

When enable_agentic_memory=True, the agent can:
  • Create new memories based on user information
  • Update existing memories with new details
  • Delete outdated or incorrect memories
  • Reason about what information to store

User Memories

When enable_user_memories=True, the system automatically:
  • Extracts key facts from conversations
  • Associates memories with specific users via user_id
  • Updates memories when new information is provided
  • Retrieves relevant memories for context

Memory Operations

Retrieving Memories

# Get all memories for a user
user_memories = memory.get_user_memories(user_id="user_123")

# Clear all memories (useful for testing)
memory.clear()

Chat History

# The agent automatically stores chat history when storage is configured
# History is retrieved via num_history_runs parameter
memory_agent = Agent(
    storage=storage,
    add_history_to_messages=True,
    num_history_runs=3,  # Include last 3 conversation runs
)

Database Schema

The application creates two SQLite tables:
TablePurposeKey Fields
user_memoriesStores extracted user factsuser_id, memory_text, created_at
agent_sessionsStores conversation historysession_id, user_id, messages, created_at

Configuration Options

enable_agentic_memory
bool
default:"false"
Allows the agent to actively create and manage memories
enable_user_memories
bool
default:"false"
Automatically extracts and stores user information from conversations
num_history_runs
int
default:"0"
Number of previous conversation runs to include in context
add_history_to_messages
bool
default:"false"
Whether to include chat history in the message context

Use Cases

Personal Assistants

Remember user preferences, schedules, and personal information across sessions

Customer Support

Maintain context of customer issues and previous interactions

Educational Tutors

Track student progress, learning style, and knowledge gaps

Health Coaches

Remember health goals, medical history, and progress over time

Installation

git clone https://github.com/Arindam200/awesome-ai-apps.git
cd memory_agents/agno_memory_agent
uv sync

Environment Setup

Create a .env file:
NEBIUS_API_KEY=your_nebius_api_key_here

Running the Example

uv run main.py

Expected Output

The example demonstrates a three-step conversation flow:
  1. Introduction: User shares personal information
  2. Location Query: Agent uses stored memories to provide personalized recommendations
  3. Memory Recall: Agent retrieves and summarizes stored information
After each interaction, the script displays the current memories stored about the user.

Best Practices

1

Use Unique User IDs

Always provide a unique user_id to isolate memories between different users
2

Configure History Carefully

Set num_history_runs based on your use case - higher values consume more tokens
3

Clear Memories When Needed

Use memory.clear() to reset the memory system during development or testing
4

Choose Memory Mode

Use enable_agentic_memory for more control, enable_user_memories for automatic extraction, or both for maximum flexibility

Agno Documentation

Official Agno framework documentation

Nebius AI

Nebius AI model provider

Build docs developers (and LLMs) love