mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-20 06:01:59 +00:00
问数据页:问题终于传进图里了,而且不再被误报卡住
两条日志(e3c2f743 / 61655cfe,相隔 30 秒)是同一件事的两半,指向三个问题。
**一、用户的问题根本没进图。** store/chat.ts 的 launch 里写死 `input: {}`。
Copilot 只要给入口声明了一个必填字段(它有时候会,比如 topic),这次运行就
在第一个节点上立刻挂掉:"缺少必填输入:topic"——用户刚问完就看到报错,而且
错误里那个字段名他从来没见过,那是生成的图里的东西。e3c2f743 就是这么死的。
之前"能跑"纯属运气:那几次 Copilot 恰好没声明字段。
**二、把提问当成了流程描述。** 两个入口共用一句 "请设计一个工作流:<原话>"。
画布上这是对的(用户在描述流程),但在问数据页用户是在**提问**。于是
"shop 里都有哪些数据?"被设计成了一个"给这段文字生成摘要"的流程,跑完把
用户的问题原样复述一遍还回去(61655cfe 的成果就是这个)。加 intent 区分:
answer 意图下明说"流程是手段,用户要的是答案",并把注入契约写死成
{{ input.question }}——不说死键名,模型会自己编一个(见过 input.text),
下游取到空字符串,而模板取不到值不报错。
**三、我上一个功能把整条对话路径卡住了。** 变量分析器把 `{{ input }}` 报成
"没有任何节点产出"——那是完全合法的写法(template_context 里 input 就是顶层
键),而 runs 启动前要过校验,一条假错误意味着什么都跑不了。这正是我自己在
上个 commit 里写的"误报是 linter 最坏的失败模式",隔天就踩了。
修的时候连着踩了三步,每步都是测试当场抓的:
- 注册裸根之后,input.quesiton 回退到根被当成合法,拼写检查整个失效
- 收紧后 {{ vars.rows[0].name }} 被误报——那是在往值内部钻,结构枚举不了
- 再收紧后 {{ input.question }} 被误报——问数据页的入口**故意不声明字段**
最终规则:裸根合法;input/vars/nodes 只校验到第二段(再往下是值内部);
**入口声明了字段才是闭集,没声明就是开放的**(运行时传什么键都行);
根本不认识的根降成 warning——能穷举才配报 error,假错误比漏报贵得多。
端到端验证:问 "shop 里都有哪些数据?挑一个最大的表说说",现在生成
input→tool→tool→llm→output(带 db_query__shop),input 带着问题,
真查出 backend_log 481,242 行 / 528.64 MB 并列出全部字段。
This commit is contained in:
@@ -229,7 +229,14 @@ export const api = {
|
||||
* 每个操作(add_node / add_edge / …)到达即回调,画布边收边长。
|
||||
*/
|
||||
export function streamCopilot(
|
||||
body: { instruction: string; base_graph?: GraphSpec | null; provider?: string | null; model?: string | null },
|
||||
body: {
|
||||
instruction: string
|
||||
base_graph?: GraphSpec | null
|
||||
provider?: string | null
|
||||
model?: string | null
|
||||
/** answer = 用户在问问题(问数据页),build = 用户在描述流程(画布)*/
|
||||
intent?: 'build' | 'answer'
|
||||
},
|
||||
onOp: (op: any) => void,
|
||||
onEnd: (error?: string) => void,
|
||||
): () => void {
|
||||
|
||||
@@ -108,7 +108,7 @@ export const useChat = create<ChatState>((set, get) => ({
|
||||
}))
|
||||
|
||||
const cancelCopilot = streamCopilot(
|
||||
{ instruction: question, base_graph: null },
|
||||
{ instruction: question, base_graph: null, intent: 'answer' },
|
||||
(op) => {
|
||||
// 先原样收下,翻译交给 decodeCopilot。thinking 合并在写入时做:
|
||||
// 一次生成几百上千条 delta,逐条存下来光数组就比图大一个量级
|
||||
@@ -150,7 +150,7 @@ export const useChat = create<ChatState>((set, get) => ({
|
||||
graph, phase: 'running', status: PHASE_TEXT.running,
|
||||
explanation: op.explanation ?? '',
|
||||
}))
|
||||
void launch(id, graph, patch, set)
|
||||
void launch(id, graph, question, patch, set)
|
||||
break
|
||||
}
|
||||
case 'error':
|
||||
@@ -204,10 +204,40 @@ export const useChat = create<ChatState>((set, get) => ({
|
||||
},
|
||||
}))
|
||||
|
||||
/**
|
||||
* 用户的问题填进这张图的入口字段。
|
||||
*
|
||||
* 在此之前这里是硬编码的 `input: {}`——问题根本没进图。Copilot 只要给入口
|
||||
* 声明了一个必填字段(它有时候会,比如 `topic`),这次运行就在第一个节点
|
||||
* 上立刻挂掉:"缺少必填输入:topic"。用户看到的是自己刚问完就报错,而且
|
||||
* 错误里提的那个字段名他从来没见过——那是生成的图里的东西。
|
||||
*
|
||||
* 之前"能跑"纯属运气:Copilot 那一次恰好没声明字段。
|
||||
*/
|
||||
function fillInput(graph: GraphSpec, question: string): Record<string, any> {
|
||||
const entry = (graph.nodes ?? []).find((n: any) => n.type === 'input')
|
||||
const fields: any[] = (entry?.data?.config?.fields ?? []) as any[]
|
||||
if (!fields.length) return { question } // 没声明字段也带上,下游可能用 input.question
|
||||
|
||||
const payload: Record<string, any> = {}
|
||||
for (const f of fields) {
|
||||
if (f?.name) payload[f.name] = f.default ?? ''
|
||||
}
|
||||
// 问题往哪个字段放:名字像"问题"的优先,其次第一个必填的,再不然第一个。
|
||||
// 只有一个字段时不用挑——那必然就是它
|
||||
const named = fields.find((f) =>
|
||||
/question|query|topic|input|问题|需求|主题/i.test(String(f?.name ?? '')))
|
||||
const target = named ?? fields.find((f) => f?.required) ?? fields[0]
|
||||
if (target?.name) payload[target.name] = question
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 图建好了就直接跑——用户要的是答案,不是一张图。 */
|
||||
async function launch(turnId: string, graph: GraphSpec, patch: Patch, set: any) {
|
||||
async function launch(
|
||||
turnId: string, graph: GraphSpec, question: string, patch: Patch, set: any,
|
||||
) {
|
||||
try {
|
||||
const run = await api.runs.start({ graph, input: {} })
|
||||
const run = await api.runs.start({ graph, input: fillInput(graph, question) })
|
||||
patch(() => ({ run }))
|
||||
watch(run.id, turnId, patch, set)
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user