# 如何使用全局记忆 ## 如何启动自动记忆采集 - 修改全局配置文件,在config.toml中添加如何配置 ```toml [CONVERSATION_MEMORY] # Whether to activate conversation memory. activate = true # The name of the memory. instance_name = 'global_conversation_memory' # Whether to enable logging. logging = true # The language of the memory cn/en. conversation_format = 'cn' # The types you want to collection collection_types = ['llm','tool','agent','knowledge'] ``` 配置说明 | 名称 | 类型 | 说明 | |-----------------------|--------|----------------------------------------------------------------------------------| | `activate` | bool | 全局启用开关,控制是否开启记忆采集功能,默认关闭。 | | `logging` | bool | 是否在执行过程中动态打印记忆信息的日志,便于调试和监控。 | | `collection_type` | list | 要采集的记忆的内容类型列表,如`['user', 'agent', 'tool', 'llm', 'knowledge']`,用于指定哪些类型的交互需要被记录。 | | `conversation_format` | string | 指定会话记忆的格式化语言设置,影响记忆内容的表示方式。 | | `instance_name` | string | 全局记忆的存储、压缩等配置的实例对象名称,标识特定配置下的记忆库。 | - 修改智能体配置文件,一份使用全局配置的智能体配置示例如下: ```yaml info: name: 'rag_agent_case' description: 'rag agent case with conversation memory' profile: introduction: 你是智能体聊天助手。 target: 你的任务是基于我们之前的对话和我提供的新信息来帮助用户解决问题。记住,我们要确保对话是自然流畅的,并且尽可能地准确和有用。 instruction: | 背景知识: {background} 之前的对话: {chat_history} ------------------------------------- 现在请根据以上所有信息,请给出一个既符合对话上下文又利用了最新背景知识的答案。如果你不确定某些细节,坦诚告知用户你不知道,并尝试提供一个一般性的指导或者建议进一步查询的方向。 需要回答的问题是: {input} llm_model: name: 'qwen_llm' model_name: 'qwen2.5-72b-instruct' temperature: 0.1 action: tool: - 'google_search_tool' knowledge: memory: conversation_memory: 'global_conversation_memory' input_field: 'input' output_field: 'output' top_k: 10 collection_types: [ 'llm','tool','agent','knowledge' ] memory_type: [ 'agent','tool' ] auto_trace: true metadata: type: 'AGENT' module: 'demo_startup_app_with_single_agent_and_memory.intelligence.agentic.agent.agent_instance.rag_agent_case_template' class: 'RagAgentCaseTemplate' ``` 配置说明: | 名称 | 类型 | 说明 | |-----------------------|--------|------------------------------------------------| | `conversation_memory` | string | 你想要使用的记忆库名称,用户全局记忆同步到智能体记忆中。 与全局记忆配置相同时,不会触发同步 | | `input_field` | string | 需要采集的输入字段,不配置会采集所有输入 | | `output_field` | string | 需要采集的输出字段,不配置会采集所有输出 | | `top_k` | int | 记忆查询时返回的记忆条数,默认为10条 | | `collection_types` | list | 当前智能体记忆采集的内容类型,默认为采集 | | `memory_type` | list | 当前智能体需要使用的记忆类型,默认为自己的QA | | `auto_trace` | bool | 是否自动追踪记忆,默认为True | 单个智能体,不想使用全局记忆,可以将auto_trace设置为False, 此时不会自动采集任何与该智能体相关的记忆内容