> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-redirect-agent-platform-overview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# What is Memory?

> Give your agents the ability to remember user preferences, context, and past interactions for truly personalized experiences.

Imagine a customer support agent that remembers your product preferences from last week, or a personal assistant that knows you prefer morning meetings, but only after you've had coffee. This is the power of Memory in Agno.

## How Memory Works

When relevant information appears in a conversation, like a user's name, preferences, or habits, an Agent with Memory automatically stores it in your database. Later, when that information becomes relevant again, the agent retrieves and uses it naturally in the conversation. The agent is effectively **learning about each user** across interactions.

<Tip>
  **Memory ≠ Session History:** Memory stores learned user facts ("Sarah prefers email"), [session history](/history/overview) stores conversation messages for continuity ("what did we just discuss?").
</Tip>

## Getting Started with Memory

Setting up memory is straightforward: just connect a database and enable the memory feature. Here's a basic setup:

```python theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Agent with Memory
agent = Agent(
    db=db,
    update_memory_on_run=True, # This enables Memory for the Agent
)
```

With `update_memory_on_run=True`, your agent automatically creates and updates memories after each conversation. It extracts relevant information, stores it, and recalls it when needed, with no manual intervention required.

## Two Approaches: Automatic vs Agentic Memory

Agno gives you two ways to manage memories, depending on how much control you want the agent to have:

### Automatic Memory (`update_memory_on_run=True`)

Memories are automatically created and updated after each agent run. Agno handles the extraction, storage, and retrieval behind the scenes. This is the recommended approach for most use cases. It's reliable and predictable.

```python theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Agent with Automatic User Memory
agent = Agent(
    db=db,
    update_memory_on_run=True, # Automatic memory management
)

# Memories are automatically created from this conversation
agent.print_response("My name is Sarah and I prefer email over phone calls.")

# And automatically recalled here
agent.print_response("What's the best way to reach me?")
```

**Best for:** Customer support, personal assistants, conversational apps where you want consistent memory behavior.

### Agentic Memory (`enable_agentic_memory=True`)

The agent gets full control over memory management through built-in tools. It decides when to create, update, or delete memories based on the conversation context.

```python theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Agent with Agentic Memory
agent = Agent(
    db=db,
    enable_agentic_memory=True, # This enables Agentic Memory for the Agent
)
```

With agentic memory, the agent is equipped with tools to manage memories when it deems relevant. This gives more flexibility but requires the agent to make intelligent decisions about what to remember.

**Best for:** Complex workflows, multi-turn interactions where the agent needs to decide what's worth remembering based on context.

<Note>
  **Important:** Don't enable both `update_memory_on_run` and `enable_agentic_memory` at the same time, as they're mutually exclusive. While nothing will break if you set both, `enable_agentic_memory` will always take precedence and `update_memory_on_run` will be ignored.
</Note>

## Storage: Where Memories Live

Memories are stored in the database you connect to your agent. Agno supports all major database systems: Postgres, SQLite, MongoDB, and more. Check the [Storage documentation](/database/overview) for the full list of supported databases and setup instructions.

By default, memories are stored in the `agno_memories` table (or collection, for document databases). If this table doesn't exist when your agent first tries to store a memory, Agno creates it automatically with no manual schema setup required.

### Custom Table Names

You can specify a custom table name for storing memories:

```python theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb

# Setup your database
db = PostgresDb(
    db_url="postgresql://user:password@localhost:5432/my_database",
    memory_table="my_memory_table", # Specify the table to store memories
)

# Setup your Agent with the database
agent = Agent(db=db, update_memory_on_run=True)

# Run the Agent. This will store a session in our "my_memory_table"
agent.print_response("Hi! My name is John Doe and I like to play basketball on the weekends.")

agent.print_response("What are my hobbies?")
```

### Manual Memory Retrieval

While memories are automatically recalled during conversations, you can also manually retrieve them using the `get_user_memories` method. This is useful for debugging, displaying user profiles, or building custom memory interfaces:

```python theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb

# Setup your database
db = PostgresDb(
    db_url="postgresql://user:password@localhost:5432/my_database",
    memory_table="my_memory_table", # Specify the table to store memories
)

# Setup your Agent with the database
agent = Agent(db=db)

# Run the Agent. This will store a memory in our "my_memory_table"
agent.print_response("I love sushi!", user_id="123")

# Retrieve the memories about the user
memories = agent.get_user_memories(user_id="123")
print(memories)
```

## Memory Data Model

Each memory stored in your database contains the following fields:

| Field        | Type   | Description                                     |
| ------------ | ------ | ----------------------------------------------- |
| `memory_id`  | `str`  | The unique identifier for the memory.           |
| `memory`     | `str`  | The memory content, stored as a string.         |
| `topics`     | `list` | The topics of the memory.                       |
| `input`      | `str`  | The input that generated the memory.            |
| `user_id`    | `str`  | The user ID of the memory.                      |
| `agent_id`   | `str`  | The agent ID of the memory.                     |
| `team_id`    | `str`  | The team ID of the memory.                      |
| `updated_at` | `int`  | The timestamp when the memory was last updated. |

<Tip>
  View and manage all your memories visually through the [Memories page in AgentOS](https://os.agno.com/memory)/
</Tip>

## Learn more

<CardGroup cols={3}>
  <Card title="Agent Memory" icon="robot" iconType="duotone" href="/memory/agent/overview">
    Store and recall user facts in single agents.
  </Card>

  <Card title="Team Memory" icon="users" iconType="duotone" href="/memory/team/overview">
    Share memories across team members.
  </Card>

  <Card title="Working with Memories" icon="file-lines" iconType="duotone" href="/memory/working-with-memories/overview">
    Retrieve, update, and delete stored memories.
  </Card>

  <Card title="Production Best Practices" icon="shield-check" iconType="duotone" href="/memory/best-practices">
    Optimize memory for scale and reliability.
  </Card>
</CardGroup>
