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

# 记忆 V2

从 Agno 版本 1.4.0 开始，**记忆 V2** 已成为 Agno Agent 的默认记忆。它取代了先前已弃用但仍可用的 `AgentMemory` 和 `TeamMemory` 类。

记忆 V2 是一个更强大、更灵活的记忆系统，可让您管理消息历史记录、会话摘要和长期用户记忆。

## 如何继续使用 AgentMemory (记忆 V1)

如果您希望继续使用 `AgentMemory` 并避免破坏性更改，可以通过更新导入来实现。默认情况下，Agent 现在使用 `Memory` 类：

```python theme={null}
from agno.memory.v2 import Memory
```

要改用旧版 AgentMemory 类，请按以下方式导入：

```python theme={null}
from agno.memory import AgentMemory

agent = Agent(
    memory=AgentMemory()
)
```

## 记忆 V2 主要更改

* **访问消息：**

  * **之前：**
    ```python theme={null}
    agent.memory.messages
    ```
  * **现在：**
    ```python theme={null}
    [run.messages for run in agent.memory.runs]
    # 或者
    agent.get_messages_for_session()
    ```

* **用户记忆：**

  * **之前：**

    ```python theme={null}
    from agno.memory import AgentMemory

    memory = AgentMemory(create_user_memories=True)
    agent = Agent(memory=memory)
    ```

  * **现在：**

    ```python theme={null}
    from agno.memory.v2 import Memory

    memory = Memory()
    agent = Agent(create_user_memories=True, memory=memory) or team = Team(create_user_memories=True, memory=memory)
    ```

* **会话摘要：**

  * **之前：**

    ```python theme={null}
    from agno.memory import AgentMemory

    memory = AgentMemory(create_session_summary=True)
    agent = Agent(memory=memory)
    ```

  * **现在：**

    ```python theme={null}
    from agno.memory.v2 import Memory

    memory = Memory()
    agent = Agent(enable_session_summaries=True, memory=memory) or team = Team(enable_session_summaries=True, memory=memory)
    ```
