本节汇总全文的核心设计决策,方便实现前快速对齐。详细说明见各章节。
action)| 值 | 含义 | 后端处理 |
|---|---|---|
confirm |
同意 Agent 评估 | 对应计数 +1,history 追加 action="confirm" |
override |
重新评估,覆盖 Agent 结果 | 按新 eval_status 计数 +1,history 追加 action="override" |
skip |
跳过,不确定 | 不做任何操作 |
source)| 值 | 含义 |
|---|---|
agent |
由 Agent 自动评估 |
user |
由人工在 Trace 前端提交 |
verification.status)| 值 | 含义 |
|---|---|
approved |
经去重审核自动通过,等待人工验证 |
checked |
人工已验证通过 |
| 优先级 | 内容 |
|---|---|
| P0 | Knowledge Log 反馈弹窗(Trace 前端)、知识验证界面(知识库前端)、API 接口、数据模型扩展 |
| P1 | Goal 反馈创建知识、Message 反馈创建知识、批量验证 |
| P2 | 反馈统计可视化、知识质量趋势分析、反馈提醒通知 |
knowledge_log.json 中approved 状态提升为 checked当前 Trace 前端采用 React + TypeScript,主要组件结构:
┌─────────────────────────────────────────────────────────────────────┐
│ TopBar (顶部工具栏) │
│ [Trace选择器▼] trace-20260324-abc [📚知识反馈] [刷新] [其他] │
├──────────────────────────────────────┬──────────────────────────────┤
│ MainContent (主内容区) │ DetailPanel (详情面板) │
│ ┌────────────────────────────────┐ │ ┌──────────────────────────┐ │
│ │ FlowChart (流程图可视化) │ │ │ 节点详情 [×] │ │
│ │ │ │ ├──────────────────────────┤ │
│ │ ┌──┐ Goal节点 │ │ │ Goal ID: 2.1 │ │
│ │ │G1│ │ │ │ 状态: completed │ │
│ │ └┬─┘ │ │ │ 描述: 定位导出按钮 │ │
│ │ │ │ │ │ │ │
│ │ ┌▼──┐ Message节点 │ │ │ 💬 反馈 (新增按钮) │ │
│ │ │M42│ │ │ │ │ │
│ │ └───┘ │ │ │ 注入知识: 3条 │ │
│ │ │ │ │ [知识列表显示...] │ │
│ │ │ │ │ │ │
│ │ │ │ │ 消息历史: │ │
│ │ │ │ │ [消息列表...] │ │
│ └────────────────────────────────┘ │ └──────────────────────────┘ │
└──────────────────────────────────────┴──────────────────────────────┘
组件说明:
在 TopBar 右侧按钮组添加「📚 知识反馈」按钮:
┌─────────────────────────────────────────────────────────────────────┐
│ [Trace选择器 ▼] trace-20260324-abc123 │
│ [📚 知识反馈] [刷新] [其他按钮] │
└─────────────────────────────────────────────────────────────────────┘
↑
新增按钮
实现文件:frontend/react-template/src/components/TopBar/TopBar.tsx
按钮状态:
触发:点击 TopBar 的「📚 知识反馈」按钮
弹窗结构(实际效果):
┌────────────────────────────────────────────────────────────────────────┐
│ 知识使用反馈 - trace-20260324-abc123 [×] │
├────────────────────────────────────────────────────────────────────────┤
│ 💡 提示:只需对有信心的知识做反馈,不确定的可以跳过 │
│ 本次执行共注入 5 条知识,Agent 已评估 5 条,待您确认 5 条 │
│ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ 📚 知识 1/5 │ │
│ │ ──────────────────────────────────────────────────────────────── │ │
│ │ ID: knowledge-20260320-a1b2 ⭐ 评分: 4 │ │
│ │ │ │
│ │ 📍 注入位置: Goal 2.1 "定位导出按钮" (sequence 42) │ │
│ │ │ │
│ │ 🎯 任务场景: 如何使用 selenium 处理登录验证 │ │
│ │ 📖 知识内容: 使用 WebDriverWait 等待元素加载... [展开] │ │
│ │ │ │
│ │ 🤖 Agent 评估: ✅ helpful │ │
│ │ 理由: "成功应用于登录流程,等待逻辑有效" │ │
│ │ │ │
│ │ ─────────────────────────────────────────────────────────────── │ │
│ │ 👤 您的反馈: │ │
│ │ ○ 同意 Agent 评估 (一键确认) │ │
│ │ ○ 不同意,我要重新评估 │ │
│ │ ● 跳过此条 (不确定) ← 默认选中 │ │
│ └──────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ 📚 知识 2/5 │ │
│ │ ──────────────────────────────────────────────────────────────── │ │
│ │ ID: knowledge-20260318-c3d4 ⭐ 评分: 3 │ │
│ │ 📍 注入位置: Goal 2.1 (sequence 42) │ │
│ │ 🎯 任务场景: 如何处理 CAPTCHA 验证码 │ │
│ │ 📖 知识内容: 使用第三方打码平台... │ │
│ │ 🤖 Agent 评估: ⚠️ unused - "未在执行中使用" │ │
│ │ │ │
│ │ 👤 您的反馈: │ │
│ │ ○ 同意 ● 不同意,重新评估 ○ 跳过 ← 用户选了重新评估 │ │
│ │ │ │
│ │ ┌────────────────────────────────────────────────────────────┐ │ │
│ │ │ 📝 重新评估 (展开) │ │ │
│ │ │ 选择评估结果: │ │ │
│ │ │ ○ helpful ● harmful ○ unused │ │ │
│ │ │ ○ irrelevant ○ neutral │ │ │
│ │ │ │ │ │
│ │ │ 反馈说明 (可选): │ │ │
│ │ │ ┌────────────────────────────────────────────────────────┐ │ │ │
│ │ │ │ 这条知识误导了我,该网站实际没有验证码 │ │ │ │
│ │ │ └────────────────────────────────────────────────────────┘ │ │ │
│ │ └────────────────────────────────────────────────────────────┘ │ │
│ └──────────────────────────────────────────────────────────────────┘ │
│ │
│ ... (其他 3 条知识,折叠显示) │
│ │
├────────────────────────────────────────────────────────────────────────┤
│ [取消] [提交反馈 (已反馈 2/5 条)] │
└────────────────────────────────────────────────────────────────────────┘
交互细节:
实现文件:新建 frontend/react-template/src/components/KnowledgeFeedbackModal/
API 请求:POST /api/trace/{trace_id}/knowledge_feedback
{
"feedback_list": [
{
"knowledge_id": "knowledge-20260320-a1b2",
"action": "confirm", // confirm | override | skip
"eval_status": "helpful", // 仅 action=override 时需要
"feedback_text": "这条知识确实有用,但参数版本有点旧", // 可选
"source": {
"trace_id": "trace-20260324-abc123",
"goal_id": "2.1",
"sequence": 42,
"feedback_by": "user@example.com",
"feedback_at": "2026-03-24T10:30:00Z"
}
}
]
}
后端处理:
action=confirm:knowledge.eval.helpful += 1,记录到 helpful_historyaction=override:根据新的 eval_status 更新 helpful/harmful,记录到对应 historyaction=skip:不做任何操作当用户在 FlowChart 中点击 Goal 节点后,DetailPanel 显示该 Goal 的详情。在详情面板顶部添加「💬 反馈」按钮:
┌──────────────────────────────────────┐
│ DetailPanel (右侧详情面板) │
│ ┌────────────────────────────────┐ │
│ │ 节点详情 [×] │ │
│ ├────────────────────────────────┤ │
│ │ Goal ID: 2.1 │ │
│ │ 状态: completed │ │
│ │ 描述: 定位导出按钮 │ │
│ │ │ │
│ │ [💬 为此 Goal 创建知识] ← 新增 │ │
│ │ │ │
│ │ 注入知识: 3 条 │ │
│ │ [知识列表...] │ │
│ │ │ │
│ │ 消息历史: 5 条 │ │
│ │ [消息列表...] │ │
│ └────────────────────────────────┘ │
└──────────────────────────────────────┘
实现文件:frontend/react-template/src/components/DetailPanel/DetailPanel.tsx
按钮位置:在 Goal 描述下方、知识列表上方
触发:点击 Goal 右侧的 💬 按钮
弹窗结构:
┌──────────────────────────────────────────────────────────────────┐
│ 为 Goal 创建知识反馈 [×] │
├──────────────────────────────────────────────────────────────────┤
│ │
│ Goal 2.1 "定位导出按钮" 状态: completed │
│ 执行摘要: 使用 XPath 定位到导出按钮并点击 (来自 goal.summary) │
│ │
│ ───────────────────────────────────────────────────────────── │
│ 📝 创建知识 │
│ │
│ 知识类型 (至少选一个): │
│ ☑ strategy ☐ tool ☐ usecase ☐ definition ☐ plan │
│ │
│ 任务场景 (Task): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ 在阿里巴巴后台定位导出按钮 ← 预填 goal.description │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ 知识内容 (Content): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ (请填写有价值的经验) │ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ 初始评分: ○ 1 ○ 2 ● 3 ○ 4 ○ 5 │
│ │
│ 标签 (可选,如 platform:alibaba action:export): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
├──────────────────────────────────────────────────────────────────┤
│ [取消] [创建知识] │
└──────────────────────────────────────────────────────────────────┘
数据结构:
API 请求:POST /api/knowledge(复用现有接口,增加 source 信息)
{
"task": "在阿里巴巴后台定位导出按钮",
"content": "导出按钮的 XPath 为 //button[@data-action='export']...",
"types": ["strategy"],
"tags": {"platform": "alibaba", "action": "export"},
"score": 3,
"source": {
"name": "user_feedback",
"category": "exp",
"trace_id": "trace-20260324-abc123",
"goal_id": "2.1",
"submitted_by": "user@example.com",
"timestamp": "2026-03-24T10:30:00Z"
}
}
后端处理:
pending,进入去重队列当用户点击 Goal 节点后,DetailPanel 显示该 Goal 下的所有 messages。在每条 message 右上角添加「💬」按钮:
┌──────────────────────────────────────┐
│ DetailPanel │
│ ┌────────────────────────────────┐ │
│ │ 节点详情 - Goal 2.1 [×] │ │
│ ├────────────────────────────────┤ │
│ │ ... Goal 信息 ... │ │
│ │ │ │
│ │ 消息历史: 5 条 │ │
│ │ ┌──────────────────────────┐ │ │
│ │ │ [user] #41 💬 │ │ │
│ │ │ 请定位导出按钮 │ │ │
│ │ └──────────────────────────┘ │ │
│ │ │ │
│ │ ┌──────────────────────────┐ │ │
│ │ │ [assistant] #42 💬 │ │ │
│ │ │ 我将使用 XPath 定位... │ │ │
│ │ │ Tool: browser_find(...) │ │ │
│ │ └──────────────────────────┘ │ │
│ │ │ │
│ │ ┌──────────────────────────┐ │ │
│ │ │ [tool] #43 💬 │ │ │
│ │ │ 找到元素: button[@data...│ │ │
│ │ └──────────────────────────┘ │ │
│ └────────────────────────────────┘ │
└──────────────────────────────────────┘
实现文件:frontend/react-template/src/components/DetailPanel/DetailPanel.tsx
按钮位置:每条 message 卡片右上角
触发:点击消息右上角的 💬 按钮
弹窗结构:
┌──────────────────────────────────────────────────────────────────┐
│ 为执行步骤创建知识反馈 - #42 (Goal 2.1) [×] │
├──────────────────────────────────────────────────────────────────┤
│ │
│ [assistant] #42 │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ 我将使用 XPath 定位导出按钮... │ │
│ │ Tool: browser_find(xpath="//button[@data-action='export']") │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ ───────────────────────────────────────────────────────────── │
│ 反馈类型: │
│ ● 创建新知识(记录有价值的经验) │
│ ○ 报告问题(此步骤有误或可改进,不创建知识) │
│ │
│ ── 创建新知识 ──────────────────────────────────────────────── │
│ 知识类型: ☑ tool ☐ strategy ☐ usecase ☐ definition │
│ │
│ 任务场景 (Task): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ 在后台页面定位导出按钮 │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ 知识内容 (Content): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ 导出按钮 XPath: //button[@data-action='export'] │ │
│ │ 需在页面 DOMContentLoaded 后再查找 │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ 初始评分: ○ 1 ○ 2 ● 3 ○ 4 ○ 5 │
│ │
├──────────────────────────────────────────────────────────────────┤
│ [取消] [创建知识] │
└──────────────────────────────────────────────────────────────────┘
数据结构:
message_id、sequence、role注:知识库前端为独立系统(KnowHub 管理页面),与 Trace 前端分开部署
┌──────────────────────────────────────────────────────────────────────┐
│ KnowHub 知识库管理 │
├──────────────────────────────────────────────────────────────────────┤
│ [全部] [待验证 (12)] [已验证] 筛选: [Owner: 我的知识▼] [类型▼] │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ ☐ knowledge-20260320-a1b2 ⭐ 3/5 💬 3 │
│ ────────────────────────────────────────────────────────────────── │
│ Task: 如何使用 selenium 处理登录验证 │
│ Content: 使用 WebDriverWait 等待元素加载完成...(截断显示) │
│ │
│ Owner: user@example.com │ 来源: trace-20260320 > Goal 2.1 │
│ 创建: 2026-03-20 10:00 │ 使用: helpful 3 / harmful 0 │
│ │
│ [查看详情] [✓ 验证通过] [✗ 标记问题] │
│ │
│ ────────────────────────────────────────────────────────────────── │
│ │
│ ☐ knowledge-20260318-c3d4 ⭐ 4/5 💬 1 │
│ ────────────────────────────────────────────────────────────────── │
│ Task: 如何处理 CAPTCHA 验证码 │
│ Content: 使用第三方打码平台 API...(截断显示) │
│ │
│ Owner: user@example.com │ 来源: trace-20260318 > Goal 1.2 │
│ 创建: 2026-03-18 14:30 │ 使用: helpful 1 / harmful 0 │
│ │
│ [查看详情] [✓ 验证通过] [✗ 标记问题] │
│ │
│ ... (更多知识) │
│ │
├──────────────────────────────────────────────────────────────────────┤
│ ☐ 全选 (0/12) [批量验证通过 (0)] │
└──────────────────────────────────────────────────────────────────────┘
点击「查看详情」,知识条目展开显示完整信息:
│ ☑ knowledge-20260320-a1b2 ⭐ 3/5 💬 3 │
│ ────────────────────────────────────────────────────────────────── │
│ Task: 如何使用 selenium 处理登录验证 │
│ Content: │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ 使用 WebDriverWait 等待元素加载完成: │ │
│ │ element = WebDriverWait(driver, 10).until( │ │
│ │ EC.presence_of_element_located((By.XPATH, "//input[@id='.."])) │ │
│ │ 避免直接 find_element 导致 NoSuchElement 异常 │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │
│ 类型: strategy | tool │
│ 标签: platform=selenium, action=login │
│ │
│ 使用历史: │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ ✅ helpful │ trace-20260322-xxx > Goal 2.1 │ agent@research │ │
│ │ ✅ helpful │ trace-20260323-yyy > Goal 1.3 │ agent@research │ │
│ │ 🚨 harmful │ trace-20260324-zzz > Goal 3.2 │ user@example.com │ │
│ │ │ 理由: "该网站实际无需等待..." │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │
│ [✓ 验证通过] [✗ 标记问题] │
┌────────────────────────────────────────────────────────────┐
│ 标记知识问题 - knowledge-20260320-a1b2 [×] │
├────────────────────────────────────────────────────────────┤
│ │
│ Task: 如何使用 selenium 处理登录验证 │
│ │
│ 请选择问题类型: │
│ ● 内容有误(知识本身不准确) │
│ ○ 过时(内容曾经正确,现在已不适用) │
│ ○ 描述模糊(task 或 content 表述不清) │
│ ○ 重复(与其他知识高度重叠) │
│ │
│ 处理方式: │
│ ● 降低评分(-1 分,保留此知识) │
│ ○ 标记为需要修改 │
│ ○ 删除此知识 │
│ │
│ 备注: │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ WebDriverWait 超时参数应该是可配置的,不应写死 10... │ │
│ └────────────────────────────────────────────────────────┘ │
│ │
├────────────────────────────────────────────────────────────┤
│ [取消] [确认提交] │
└────────────────────────────────────────────────────────────┘
status: approved → checked,记录验证人和时间在 helpful_history / harmful_history 中每条记录增加溯源字段:
{
"eval": {
"score": 3,
"helpful": 3,
"harmful": 0,
"confidence": 0.8,
"helpful_history": [
{
"source": "agent",
"trace_id": "trace-20260320-xxx",
"goal_id": "2.1",
"sequence": 42,
"feedback_by": "agent:research_agent",
"feedback_at": "2026-03-20T10:05:00Z",
"eval_status": "helpful",
"feedback_text": "成功应用于登录流程",
"action": "auto"
},
{
"source": "user",
"trace_id": "trace-20260322-yyy",
"goal_id": "3.1",
"sequence": 88,
"feedback_by": "user@example.com",
"feedback_at": "2026-03-22T15:30:00Z",
"eval_status": "helpful",
"feedback_text": "该知识有效,但超时参数建议可配置",
"action": "confirm"
}
],
"harmful_history": []
},
"verification": {
"status": "checked",
"verified_by": "user@example.com",
"verified_at": "2026-03-24T10:30:00Z",
"note": "已确认此知识准确有效",
"issue_type": null,
"issue_action": null
}
}
source 字段说明:
| 值 | 含义 |
|---|---|
| "agent" | 由 Agent 自动评估 |
| "user" | 由人工在 Trace 前端提交 |
action 字段说明:
| 值 | 含义 |
|---|---|
| "auto" | Agent 自动评估(未经人工确认) |
| "confirm" | 用户同意 Agent 评估 |
| "override" | 用户重新评估(覆盖 Agent 结果) |
verification.status 字段说明:
| 值 | 含义 |
|---|---|
| "approved" | 经过去重审核,知识自动通过,等待人工验证 |
| "checked" | 人工已验证通过 |
在 .trace/{trace_id}/metadata.json 中添加:
{
"trace_id": "trace-20260324-abc123",
"task": "登录阿里巴巴后台并导出销售报表",
"user_feedback": {
"knowledge_feedback_submitted": true,
"knowledge_feedback_at": "2026-03-24T10:30:00Z",
"knowledge_feedback_by": "user@example.com",
"knowledge_feedback_count": 3,
"goal_feedback": [
{
"goal_id": "2.1",
"knowledge_id": "knowledge-20260324-new1",
"feedback_at": "2026-03-24T10:35:00Z"
}
],
"message_feedback": [
{
"sequence": 42,
"type": "knowledge",
"knowledge_id": "knowledge-20260324-new2",
"feedback_at": "2026-03-24T10:40:00Z"
}
]
}
}
压缩(Compression)只修改内存 history,不修改存储。
原始消息永远保留在 .trace/{trace_id}/messages/{message_id}.json。
来源:
agent/trace/compaction.py顶部注释 "压缩不修改存储:原始消息永远保留在 messages/,纯内存操作。"
因此,用户在 trace 执行结束后的任意时刻触发重新评估,都可以从文件系统重建出执行时的上下文。
用户在弹窗中选择 action=override 时,将用户的 eval_status 写入 helpful_history / harmful_history,source="user"。这是纯数据记录操作,不调用 LLM。
用户提交「不同意,重新评估」(action=override)
↓
1. 记录覆盖评估(立即写入)
→ 在 knowledge.eval.helpful_history / harmful_history 追加一条记录
→ source="user", action="override", feedback_by=user_email
→ 根据 eval_status 决定 helpful 或 harmful +1
2. 更新 trace 的 knowledge_log.json
→ 将对应 entry 的 eval_result 更新为用户的 eval_status
→ 额外字段: user_override=true, user_feedback_text=...
3. 返回前端
→ {status: "ok", updated: N}
GET /api/trace/{trace_id}/knowledge_log
Response: knowledge_log.json 内容
POST /api/trace/{trace_id}/knowledge_feedback
Body: {
feedback_list: [
{
knowledge_id: "...",
action: "confirm | override | skip",
eval_status: "helpful | harmful | unused | irrelevant | neutral",
feedback_text: "(可选说明)",
source: {feedback_by, feedback_at}
}
]
}
Response: {
status: "ok",
updated: 3
}
后端逻辑:
action=confirm:helpful +1,history 追加 action="confirm"action=override:按 eval_status 对应计数 +1,history 追加 action="override"action=skip:不做任何操作POST /api/knowledge
Body: {task, content, types, source: {trace_id, goal_id, ...}}
Response: {knowledge_id, status: "pending"}
POST /api/knowledge
Body: {task, content, types, source: {trace_id, message_id, sequence, ...}}
Response: {knowledge_id, status: "pending"}
GET /api/knowledge?status=approved&owner={user_email}
Response: {results: [...], count: 12}
POST /api/knowledge/{knowledge_id}/verify
Body: {action: "approve", verified_by, note}
Response: {status: "ok", new_status: "checked"}
POST /api/knowledge/batch_verify
Body: {knowledge_ids: [...], action: "approve", verified_by}
Response: {status: "ok", updated: 5}