Files
smartmate/backend/newAgent/prompt/compact_msg2.go
LoveLosita 8bde981592 Version: 0.9.20.dev.260415
后端:
1. 修复 query_available_slots section_from/section_to 错误覆盖 duration 并使用精确匹配而非范围包含
- 更新backend/newAgent/tools/schedule/read_filter_tools.go:移除 span = exactTo - exactFrom + 1 对 duration 的覆盖;matchSectionRange
  从精确匹配改为范围包含语义(slotStart < exactFrom || slotEnd > exactTo)
2. Execute 上下文窗口从硬编码裁剪改造为 80k token 动态预算 + LLM滚动压缩
- 基础设施层:AgentChat 新增 compaction 三个持久化字段,dao 新增 CRUD,Redis 新增缓存;pkg 新增 ExecuteTokenBudget常量、ExecuteTokenBreakdown 结构体、CheckExecuteTokenBudget 预算检查函数
- prompt 层:新建 compact_msg1.go / compact_msg2.go 分别实现msg1(历史对话)和 msg2(ReAct Loop)的 LLM 压缩;execute_context.go 移除 msg1 的 1400 字符/30 轮/120 字符三重裁剪和 msg2 的 8 条窗口限制,改为全量加载
- node 层:新建 execute_compact.go(compactExecuteMessagesIfNeeded:预算检查 → msg1 优先压缩 → msg2 兜底 → SSE 通知 → token 分布持久化);execute.go ReAct 循环插入 compact 调用 - 服务/API 层:AgentGraphDeps / AgentService 新增 CompactionStore 注入链路;新增 GET /api/v1/agent/context-stats 查询接口
- 启动层:cmd/start.go 注入 agentRepo 为 CompactionStore
3. 新增 Execute Context Compaction 决策报告
- 新建docs/功能决策记录/Execute_Context_Compaction_决策记录.md

前端:无 仓库:无
2026-04-15 22:01:37 +08:00

50 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package newagentprompt
import (
"context"
"fmt"
infrallm "github.com/LoveLosita/smartflow/backend/infra/llm"
"github.com/cloudwego/eino/schema"
)
const compactMsg2SystemPrompt = `你是一个执行记录压缩助手。你的任务是将以下 ReAct 执行循环记录压缩为简洁摘要。
要求:
1. 保留每个工具调用的关键返回值尤其是包含排程数据的JSON
2. 保留执行路径(哪些操作成功了,哪些失败了)
3. 保留当前执行进度(正在做什么,下一步要做什么)
4. 去除重复的工具调用结果
5. 按时间顺序组织,每条一行
直接输出压缩后的摘要,不要输出其他内容。`
// CompactMsg2 将 msg2ReAct Loop 记录)的早期部分压缩为摘要。
// recentText 是保留的近期记录原文,不参与压缩。
func CompactMsg2(
ctx context.Context,
client *infrallm.Client,
earlyLoopText string,
) (string, error) {
userContent := fmt.Sprintf(`早期的 ReAct 执行记录:
%s
请压缩以上执行记录,保留关键信息。`, earlyLoopText)
messages := []*schema.Message{
schema.SystemMessage(compactMsg2SystemPrompt),
schema.UserMessage(userContent),
}
result, err := client.GenerateText(ctx, messages, infrallm.GenerateOptions{
MaxTokens: 4000,
})
if err != nil {
return "", fmt.Errorf("compact msg2 LLM call failed: %w", err)
}
if result == nil || result.Text == "" {
return "", fmt.Errorf("compact msg2 LLM returned empty result")
}
return result.Text, nil
}