Expand description
消息压缩模块:压缩来自其他 agent 的 tool call 消息
在 teammate/subagent 调用 LLM 前,对消息列表进行压缩:
- 保留最近 N 条完整的 tool call 消息
- 较早的消息压缩为摘要,减少上下文占用
§上下文注入机制(Feature,非 Bug)
SubAgent/Teammate 通过各自推送逻辑写入双通道:
display_messages:干净文本 + sender_name 字段 → UI 渲染context_messages:XML 包裹(如<AgentName>text</AgentName>) → LLM context
数据流:
display_messages→ UI 渲染数据源context_messages→build_api_messages(LLM context 数据源)
本模块的压缩功能用于减少这些消息对上下文的占用,而非完全过滤它们。
参见 agent/tool_processor.rs 中 push_both 函数的文档注释。
§压缩策略
广播消息格式:<Type: AgentName> [调用工具 ToolName]
- 按 agent 来源分组
- 保留最近 threshold 条完整消息
- 较早的合并为摘要:
<Type: AgentName> [早期工具调用摘要: ToolA×5, ToolB×3, 共 8 次]
Constants§
- DEFAULT_
OTHER_ AGENT_ TOOLCALL_ THRESHOLD - 默认压缩阈值:保留最近 5 条完整消息
Functions§
- compress_
other_ agent_ toolcalls - 压缩来自其他 agent 的 tool call 消息