核心概念
Session 是插件容器
Session 是一个插件封装,默认实现为 AgentlyMemoSession。你可以通过设置切换 Session 插件:
python
agent.settings.set("plugins.Session.activate", "AgentlyMemoSession")三个核心数据结构
- full_chat_history:完整对话记录(不裁剪)
- current_chat_history:注入 prompt 的当前窗口
- memo:稳定偏好、约束与事实的结构化摘要
关系示意
full_chat_history --(resize)--> current_chat_history
| |
| v
+-----------(memo update)--> memoresize 流程
- policy 决定是否 resize,以及是
lite还是deep - handler 执行裁剪并更新 memo
- 更新
current_chat_history/memo/last_resize等信息
mode="memo"只是启用 memo 更新,不强制 deep;具体由策略决定。
什么时候会触发 resize
every_n_turns达到阈值current_chat_history字符数超过max_messages_text_lengthcurrent_chat_history消息数超过max_keep_messages_count- 手动调用
session.resize(force="deep")
与 Agent 的关系
SessionExtension 负责把 Session 接入 Agent:
- 请求前:把
current_chat_history注入 prompt - 请求后:把最新消息写入 Session
详见:Agent 集成