|
| 1 | +--- |
| 2 | +title: Memory V2 |
| 3 | +sidebarTitle: Memory V2 |
| 4 | +--- |
| 5 | + |
| 6 | +## Memory V2 |
| 7 | + |
| 8 | +Starting with Agno version 1.4.0, **Memory V2** is now the default memory for the Agno Agent. This replaces the previous `AgentMemory` and `TeamMemory` classes which is now deprecated but still available to use. |
| 9 | + |
| 10 | +Memory V2 is a more powerful and flexible memory system that allows you to manage message history, session summaries, and long-term user memories. |
| 11 | + |
| 12 | +## How to Continue Using AgentMemory (Memory V1) |
| 13 | + |
| 14 | +If you want to continue using `AgentMemory` and avoid breaking changes, you can do so by updating your imports. By default, the Agent now uses the `Memory` class: |
| 15 | + |
| 16 | +```python |
| 17 | +from agno.memory.v2 import Memory |
| 18 | +``` |
| 19 | + |
| 20 | +To use the legacy AgentMemory class instead, import it like this: |
| 21 | + |
| 22 | +```python |
| 23 | +from agno.memory import AgentMemory |
| 24 | + |
| 25 | +agent = Agent( |
| 26 | + memory=AgentMemory() |
| 27 | +) |
| 28 | +``` |
| 29 | + |
| 30 | +## Key Memory V2 Changes |
| 31 | + |
| 32 | +- **Accessing Messages:** |
| 33 | + |
| 34 | + - **Before:** |
| 35 | + ```python |
| 36 | + agent.memory.messages |
| 37 | + ``` |
| 38 | + - **Now:** |
| 39 | + ```python |
| 40 | + [run.messages for run in agent.memory.runs] |
| 41 | + # or |
| 42 | + agent.get_messages_for_session() |
| 43 | + ``` |
| 44 | + |
| 45 | +- **User Memories:** |
| 46 | + |
| 47 | + - **Before:** |
| 48 | + |
| 49 | + ```python |
| 50 | + from agno.memory import AgentMemory |
| 51 | + |
| 52 | + memory = AgentMemory(create_user_memories=True) |
| 53 | + agent = Agent(memory=memory) |
| 54 | + ``` |
| 55 | + |
| 56 | + - **Now:** |
| 57 | + |
| 58 | + ```python |
| 59 | + from agno.memory.v2 import Memory |
| 60 | + |
| 61 | + memory = Memory() |
| 62 | + agent = Agent(create_user_memories=True, memory=memory) or team = Team(create_user_memories=True, memory=memory) |
| 63 | + ``` |
| 64 | + |
| 65 | +- **Session Summaries:** |
| 66 | + |
| 67 | + - **Before:** |
| 68 | + |
| 69 | + ```python |
| 70 | + from agno.memory import AgentMemory |
| 71 | + |
| 72 | + memory = AgentMemory(create_session_summary=True) |
| 73 | + agent = Agent(memory=memory) |
| 74 | + ``` |
| 75 | + |
| 76 | + - **Now:** |
| 77 | + |
| 78 | + ```python |
| 79 | + from agno.memory.v2 import Memory |
| 80 | + |
| 81 | + memory = Memory() |
| 82 | + agent = Agent(enable_session_summaries=True, memory=memory) or team = Team(enable_session_summaries=True, memory=memory) |
| 83 | + ``` |
0 commit comments