Files
AgentLab/backend/tests/fixtures/copilot_answer_ops_baseline.json
T
ThearchyHelios ba28dee1f0 生成过程抽成 answer_ops、复核抽成 review_of_run,助手建图和复核的用量也记下(细案 01 做法 2、3):评测和问数据页走同一条生成路径,这一轮的花费不再低报
- api/copilot.py:event_stream 原样搬成 async generator answer_ops(payload, *, catalog_view=None),交出的 op dict 不变;开流前的准备(数据源、目录检查器、助手模型、历史、查看服务)用自己的短会话,在第一条操作之前做完。SSE 路由只包一层:先取第一条,开流前的拒绝(模型没配好、限定的数据源都不在)照旧是 HTTP 错误
- catalog_view 一路传给查看服务和自查的 SQL 检查器(目录视图接缝的「生成过程从参数读」)
- providers/usage.py:Meter 是一个 LangChain 回调,和 get_usage_metadata_callback 同一个机制(登记过的上下文变量),按模型累计 tokens、次数,金额按价格目录;估不出的记 unpriced_calls。没直接用 get_usage_metadata_callback:with 块跨 yield 会把变量留在调用方上下文里,调用方随后发起的运行会继承它、被重复计一遍;metered 只在每一步 __anext__ 期间挂上,嵌套时并进外层
- 生成过程读到 done / look / ask 就关模型的流(后面的闲话不要),流末尾才报的用量拿不到:这一次照样计次数和已报的 token,记成估不出,不悄悄少算(遗留:真实接入上建图那几次多半是下限)
- providers/budget.py:BudgetFallback.astream 用 aclosing 包住里面那条流——以前调用方关流时里面那条要等垃圾回收才关,模型那次调用的收尾(用量回调)落在算完账之后;测试去掉它回跑会少计一次
- answer_ops 末尾多一条 {op: usage, by_model, input_tokens, output_tokens, calls, cost_usd, unpriced_calls};/copilot/review 拆出 review_of_run(问数据页、评测共用),结果带 usage(没调模型时全 0)和 retry_instruction(要不要带着原图重来、说什么,按 chat/turn.py 的决定算;ReviewIn 多一个 attempt)
- 新增 app/chat/turn.py(问数据一轮的决定,复核这边先用上;final.next、对照测试、前端照做在下一个提交);新增 tests/test_copilot_answer_ops.py(八种结局的 SSE 输出和抽出来之前录下的 fixtures/copilot_answer_ops_baseline.json 逐条相同,末尾多一条 usage;直接迭代和 SSE 同一串;开流前的拒绝仍是 HTTP 错误)、tests/test_usage_meter.py;读 SSE 的十一个测试文件的收流帮手跳过末尾那条 usage
2026-10-16 10:45:45 +08:00

1031 lines
18 KiB
JSON
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.
{
"graph_ok": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "plan",
"summary": "数一数"
},
{
"op": "add_node",
"node": {
"id": "start",
"type": "input",
"label": "start",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"op": "add_node",
"node": {
"id": "init",
"type": "transform",
"label": "init",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "start",
"target": "init"
}
},
{
"op": "add_node",
"node": {
"id": "lp",
"type": "loop",
"label": "lp",
"config": {
"mode": "while",
"condition": "len(vars.items) > 5",
"max_iterations": 2
}
}
},
{
"op": "add_edge",
"edge": {
"source": "init",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "body",
"type": "transform",
"label": "body",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "body",
"sourceHandle": "body"
}
},
{
"op": "add_edge",
"edge": {
"source": "body",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "out",
"type": "output",
"label": "out",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "out",
"sourceHandle": "done"
}
},
{
"op": "done",
"explanation": "数一数",
"run": true
},
{
"op": "check",
"status": "passed",
"repaired": 0,
"warnings": []
},
{
"op": "final",
"graph": {
"nodes": [
{
"id": "start",
"type": "input",
"position": {
"x": 80.0,
"y": 0.0
},
"data": {
"label": "start",
"description": "",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"id": "init",
"type": "transform",
"position": {
"x": 414.0,
"y": 0.0
},
"data": {
"label": "init",
"description": "",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"id": "lp",
"type": "loop",
"position": {
"x": 748.0,
"y": 0.0
},
"data": {
"label": "lp",
"description": "",
"config": {
"mode": "while",
"condition": "len(vars.items) > 5",
"max_iterations": 2
}
}
},
{
"id": "body",
"type": "transform",
"position": {
"x": 1082.0,
"y": -66.0
},
"data": {
"label": "body",
"description": "",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"id": "out",
"type": "output",
"position": {
"x": 1082.0,
"y": 66.0
},
"data": {
"label": "out",
"description": "",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
}
],
"edges": [
{
"id": "start:->init",
"source": "start",
"target": "init",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "init:->lp",
"source": "init",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:body->body",
"source": "lp",
"target": "body",
"sourceHandle": "body",
"targetHandle": null,
"label": ""
},
{
"id": "body:->lp",
"source": "body",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:done->out",
"source": "lp",
"target": "out",
"sourceHandle": "done",
"targetHandle": null,
"label": ""
}
],
"viewport": {},
"defaults": {}
},
"issues": [],
"explanation": "数一数",
"autorun": true,
"layout": {
"mode": "full",
"placed": [
"start",
"init",
"lp",
"body",
"out"
]
},
"tool_changes": []
}
],
"graph_fixed": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "plan",
"summary": "数一数"
},
{
"op": "add_node",
"node": {
"id": "start",
"type": "input",
"label": "start",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"op": "add_node",
"node": {
"id": "init",
"type": "transform",
"label": "init",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "start",
"target": "init"
}
},
{
"op": "add_node",
"node": {
"id": "lp",
"type": "loop",
"label": "lp",
"config": {
"mode": "while",
"condition": "{{ vars.items | length }} > 5",
"max_iterations": 2
}
}
},
{
"op": "add_edge",
"edge": {
"source": "init",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "body",
"type": "transform",
"label": "body",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "body",
"sourceHandle": "body"
}
},
{
"op": "add_edge",
"edge": {
"source": "body",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "out",
"type": "output",
"label": "out",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "out",
"sourceHandle": "done"
}
},
{
"op": "done",
"explanation": "数一数",
"run": true
},
{
"op": "check",
"status": "repairing",
"round": 1,
"issues": [
{
"level": "error",
"node_id": "lp",
"edge_id": null,
"message": "循环条件有误:表达式中不支持 | 过滤器(那是模板的写法):取长度请写 len(x),转换大小写请写 upper(x) / lower(x)(原文:{{ vars.items | length }} > 5)",
"field": "condition",
"code": null,
"fix": null
}
]
},
{
"op": "update_node",
"id": "lp",
"config": {
"mode": "while",
"condition": "len(vars.items) > 5",
"max_iterations": 2
}
},
{
"op": "check",
"status": "passed",
"repaired": 1,
"warnings": []
},
{
"op": "final",
"graph": {
"nodes": [
{
"id": "start",
"type": "input",
"position": {
"x": 80.0,
"y": 0.0
},
"data": {
"label": "start",
"description": "",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"id": "init",
"type": "transform",
"position": {
"x": 414.0,
"y": 0.0
},
"data": {
"label": "init",
"description": "",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"id": "lp",
"type": "loop",
"position": {
"x": 748.0,
"y": 0.0
},
"data": {
"label": "lp",
"description": "",
"config": {
"mode": "while",
"condition": "len(vars.items) > 5",
"max_iterations": 2
}
}
},
{
"id": "body",
"type": "transform",
"position": {
"x": 1082.0,
"y": -66.0
},
"data": {
"label": "body",
"description": "",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"id": "out",
"type": "output",
"position": {
"x": 1082.0,
"y": 66.0
},
"data": {
"label": "out",
"description": "",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
}
],
"edges": [
{
"id": "start:->init",
"source": "start",
"target": "init",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "init:->lp",
"source": "init",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:body->body",
"source": "lp",
"target": "body",
"sourceHandle": "body",
"targetHandle": null,
"label": ""
},
{
"id": "body:->lp",
"source": "body",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:done->out",
"source": "lp",
"target": "out",
"sourceHandle": "done",
"targetHandle": null,
"label": ""
}
],
"viewport": {},
"defaults": {}
},
"issues": [],
"explanation": "数一数",
"autorun": true,
"layout": {
"mode": "full",
"placed": [
"start",
"init",
"lp",
"body",
"out"
]
},
"tool_changes": []
}
],
"check_failed": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "plan",
"summary": "数一数"
},
{
"op": "add_node",
"node": {
"id": "start",
"type": "input",
"label": "start",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"op": "add_node",
"node": {
"id": "init",
"type": "transform",
"label": "init",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "start",
"target": "init"
}
},
{
"op": "add_node",
"node": {
"id": "lp",
"type": "loop",
"label": "lp",
"config": {
"mode": "while",
"condition": "foo(vars.items)",
"max_iterations": 2
}
}
},
{
"op": "add_edge",
"edge": {
"source": "init",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "body",
"type": "transform",
"label": "body",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "body",
"sourceHandle": "body"
}
},
{
"op": "add_edge",
"edge": {
"source": "body",
"target": "lp"
}
},
{
"op": "add_node",
"node": {
"id": "out",
"type": "output",
"label": "out",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
},
{
"op": "add_edge",
"edge": {
"source": "lp",
"target": "out",
"sourceHandle": "done"
}
},
{
"op": "done",
"explanation": "数一数",
"run": true
},
{
"op": "check",
"status": "repairing",
"round": 1,
"issues": [
{
"level": "error",
"node_id": "lp",
"edge_id": null,
"message": "循环条件有误:不支持函数 foo(),可用的函数:len、str、int、float、bool、abs、min、max、sum、round、sorted、any、all、lower、upper、contains、startswith、endswith、matches、get、cell(原文:foo(vars.items))",
"field": "condition",
"code": null,
"fix": null
}
]
},
{
"op": "update_node",
"id": "lp",
"config": {
"mode": "while",
"condition": "bar(vars.items)",
"max_iterations": 2
}
},
{
"op": "check",
"status": "repairing",
"round": 2,
"issues": [
{
"level": "error",
"node_id": "lp",
"edge_id": null,
"message": "循环条件有误:不支持函数 bar(),可用的函数:len、str、int、float、bool、abs、min、max、sum、round、sorted、any、all、lower、upper、contains、startswith、endswith、matches、get、cell(原文:bar(vars.items))",
"field": "condition",
"code": null,
"fix": null
}
]
},
{
"op": "update_node",
"id": "lp",
"config": {
"mode": "while",
"condition": "bar(vars.items)",
"max_iterations": 2
}
},
{
"op": "check",
"status": "failed",
"issues": [
{
"level": "error",
"node_id": "lp",
"edge_id": null,
"message": "循环条件有误:不支持函数 bar(),可用的函数:len、str、int、float、bool、abs、min、max、sum、round、sorted、any、all、lower、upper、contains、startswith、endswith、matches、get、cell(原文:bar(vars.items))",
"field": "condition",
"code": null,
"fix": null
}
],
"warnings": []
},
{
"op": "final",
"graph": {
"nodes": [
{
"id": "start",
"type": "input",
"position": {
"x": 80.0,
"y": 0.0
},
"data": {
"label": "start",
"description": "",
"config": {
"fields": [
{
"name": "question"
}
]
}
}
},
{
"id": "init",
"type": "transform",
"position": {
"x": 414.0,
"y": 0.0
},
"data": {
"label": "init",
"description": "",
"config": {
"mode": "expression",
"expression": "[1, 2]",
"assign_to": "items"
}
}
},
{
"id": "lp",
"type": "loop",
"position": {
"x": 748.0,
"y": 0.0
},
"data": {
"label": "lp",
"description": "",
"config": {
"mode": "while",
"condition": "bar(vars.items)",
"max_iterations": 2
}
}
},
{
"id": "body",
"type": "transform",
"position": {
"x": 1082.0,
"y": -66.0
},
"data": {
"label": "body",
"description": "",
"config": {
"mode": "expression",
"expression": "1"
}
}
},
{
"id": "out",
"type": "output",
"position": {
"x": 1082.0,
"y": 66.0
},
"data": {
"label": "out",
"description": "",
"config": {
"fields": [
{
"name": "结果",
"value": "{{ vars.items }}"
}
]
}
}
}
],
"edges": [
{
"id": "start:->init",
"source": "start",
"target": "init",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "init:->lp",
"source": "init",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:body->body",
"source": "lp",
"target": "body",
"sourceHandle": "body",
"targetHandle": null,
"label": ""
},
{
"id": "body:->lp",
"source": "body",
"target": "lp",
"sourceHandle": null,
"targetHandle": null,
"label": ""
},
{
"id": "lp:done->out",
"source": "lp",
"target": "out",
"sourceHandle": "done",
"targetHandle": null,
"label": ""
}
],
"viewport": {},
"defaults": {}
},
"issues": [
{
"level": "error",
"node_id": "lp",
"edge_id": null,
"message": "循环条件有误:不支持函数 bar(),可用的函数:len、str、int、float、bool、abs、min、max、sum、round、sorted、any、all、lower、upper、contains、startswith、endswith、matches、get、cell(原文:bar(vars.items))",
"field": "condition",
"code": null,
"fix": null
}
],
"explanation": "数一数",
"autorun": false,
"layout": {
"mode": "full",
"placed": [
"start",
"init",
"lp",
"body",
"out"
]
},
"tool_changes": []
}
],
"reply": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "reply",
"text": "上一轮已经查过了:一共 3 家门店。"
}
],
"ask_only": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "plan",
"summary": "先问清楚"
},
{
"op": "ask",
"question": "要看哪个月的?",
"options": [
"九月",
"十月"
]
},
{
"op": "final",
"graph": {
"nodes": [],
"edges": []
},
"issues": [],
"explanation": "",
"autorun": false,
"layout": {
"mode": "keep",
"placed": []
},
"tool_changes": [],
"asked": {
"question": "要看哪个月的?",
"options": [
"九月",
"十月"
]
}
}
],
"error": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "error",
"message": "助手本轮未完成:接入返回了 502",
"hint": "",
"detail": "RuntimeError: 接入返回了 502"
}
],
"no_ops": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "error",
"message": "助手本轮未完成:模型没有给出任何修改,也没有说明原因",
"hint": "画布未修改。可以重试,或把需求描述得更具体",
"detail": ""
}
],
"truncated": [
{
"op": "model",
"model": "mock-fast"
},
{
"op": "plan",
"summary": "想了很久"
},
{
"op": "error",
"message": "助手本轮未完成:模型的输出超出了长度上限,修改没有写完",
"hint": "画布未修改。可以重试,或把需求拆成几步分别提出",
"detail": "finish_reason=length"
}
]
}