.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/task_memory.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_task_memory.py: .. _memory: 记忆 ======================== 在 AgentScope 中,记忆(memory)用于存储智能体的上下文,并在需要时检索它。 具体而言,AgentScope 在 ``agentscope.memory`` 模块下提供了记忆基类 ``MemoryBase`` 和一个可直接使用的基于内存实现 ``InMemoryMemory``。 自定义记忆 ~~~~~~~~~~~~~~~~~~~~~~~~ 要自定义您自己的记忆,只需继承 ``MemoryBase`` 并实现以下方法: .. list-table:: :header-rows: 1 * - 方法 - 描述 * - ``add`` - 向记忆中添加 ``Msg`` 对象 * - ``delete`` - 从记忆中删除项目 * - ``size`` - 记忆的大小 * - ``clear`` - 清空记忆内容 * - ``get_memory`` - 以 ``Msg`` 对象列表的形式获取记忆内容 * - ``state_dict`` - 获取记忆的状态字典 * - ``load_state_dict`` - 加载记忆的状态字典 进一步阅读 ~~~~~~~~~~~~~~~~~~~~~~~~ - :ref:`long-term-memory` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_tutorial_task_memory.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: task_memory.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: task_memory.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: task_memory.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_