会议模式:按 UE 蓝图语义重做(exec 执行链 + data 数据线)+ while 循环节点
用户指出"不只是视觉,他是有个执行链的",查了官方文档 (https://dev.epicgames.com/documentation/unreal-engine/nodes-in-unreal-engine#pins) 之后发现:我之前**只学了长相没学语义**。 蓝图里引脚分两类,作用完全不同: exec 执行引脚(白色三角):**决定执行顺序**。激活输入 → 节点执行 → 激活输出继续。 data 数据引脚(彩色圆点):传值。 我的引擎原来是"谁连着谁就按拓扑序跑",两种作用混在一根线上。现在拆开了。 【边分两种】 kind='exec' 决定顺序;kind='data' 只传值。 老会议里没有 kind 的边当 exec,并且"没有数据入边时就用 exec 上游的输出"—— 所以以前那种"一根线连到底"的图行为完全不变(回归 40/40 可以证明)。 【端口按语义重排】 start 源:没有输入,只有数据输出 agent ▶ 入 / ▶ 出 + 数据入 / 数据出 judge ▶ 入 / **真▶ 假▶ 两条 exec 出**(相当于 Branch)+ 数据入 var ▶ 入 / ▶ 出 + 数据入(**没有数据出**——存进去的值不从它往下传) readvar **纯节点**(蓝图里的 Get):没有 exec 引脚,只有数据出。 值是被需要的节点**拉取**的,自己不在执行链上 end ▶ 入 + 数据入 while ▶ 入 / **循环体▶ 结束▶** + 数据入(条件) ★ "读变量只有输出"原来是这个意思:它是纯节点,压根没有 exec 引脚。 我一开始只按"有没有输入"去理解,做了个"变量被写入时唤醒读变量"的机制 —— 那是错的,纯节点的值是**拉取**的。删掉唤醒逻辑之后, Node 侧漏删了一处,对拍立刻报"rd 混进了执行链"(Python 侧没有)。 两处不一致就是这么被抓出来的。 【while 节点】 和 C 的 while 一样:先判断、再执行循环体,条件为假跳出。 data 入 条件(bool,每轮重新求值,一般来自"读变量") exec 出 循环体 / 结束 引擎的三处关键处理: 1. **嵌套 walk**:循环体必须是"整段跑完再回到判断"。用平铺队列做不到 —— 队列先进先出,循环体第一个节点刚入队 while 自己就被弹出来了, 判断会在循环体还没跑的时候重来一遍。所以循环体是一次嵌套的 walk。 2. **循环头边界(stop_at)**:嵌套 walk 跑到 while 自己就立刻返回。 不设这个边界的话它会一路跑回循环头、一层层递归下去 (踩过:序列是 s,w0,wh,a,e,w1,循环只转一圈就乱了)。 3. **每轮重置循环体的执行计数**:不重置的话循环体里的节点第二轮就被 maxRuns(默认 1)挡在门外,循环等于没用。 while 自己也不受 maxRuns 管 —— 转几轮是条件说了算。 另外兜了 MAX_LOOP_ITERS=200 的轮次上限,并且**会明确告诉用户"已达上限强制结束"**, 不静默停 —— 静默停会让人以为"条件写对了但没生效"。 【验证】 - 引擎回归:40/40,Node 与 Python **16/16 逐用例一致**(exec/data 重构没破坏既有语义) - while 端到端实测: exec seq: s, w0, wh, a, w1, wh, a, w1, wh, a, w1, wh, e body rounds: 3 第 1 轮:条件='3' → 继续循环 第 2 轮:条件='2' → 继续循环 第 3 轮:条件='1' → 继续循环 第 4 轮:条件='0' → 结束循环 n 从 3 递减到 0,转 3 轮后跳出,和 C 的 while(n--) 一致。 - 会议 HTTP 端到端 13/13 【这一轮没做完的,如实说明】 - **Node 侧引擎还没有 while 节点**(Python 有了)。两边的 exec/data 重构都做完了, 对拍 16/16 一致;但 while 是 Python 独有的,还没写 Node 镜像。 - **界面还没跟上**:节点卡片上现在是"▶ 执行引脚(白三角)+ 彩色圆点数据引脚", 但 while 节点的两种 exec 出线(循环体/结束)还没画; 节点配置面板里也没有 while 的说明。 - 这两块下一步补,补完再加 while 的验收用例把两边钉死。
This commit is contained in:
@@ -278,12 +278,24 @@ function sanitizeEdges(edges, nodes) {
|
||||
const a = byId.get(src);
|
||||
const b = byId.get(dst);
|
||||
if (!a || !b || src === dst) continue;
|
||||
// 端口语义是硬约束:写变量只有输入、读变量只有输出。
|
||||
// 端口语义是硬约束:写变量只有**数据**入、读变量只有**数据**出。
|
||||
// 连线文件可以手改、也可能来自旧版本会议,留着"接到不存在端口上的边"
|
||||
// 会变成一个永远不触发的节点 —— 图看着连了就是不跑,最难查。
|
||||
if (a.type === 'end' || a.type === 'var') continue;
|
||||
//
|
||||
// 注意 end / var 是"没有数据出线",但**有 exec 出线**
|
||||
// (蓝图里 Set 节点就是 exec 进 → exec 出),所以只挡数据线。
|
||||
if ((a.type === 'end' || a.type === 'var') && e.kind === DATA) continue;
|
||||
if (b.type === 'start' || b.type === 'readvar') continue;
|
||||
out.push({ from: src, to: dst, branch: String(e.branch || '') });
|
||||
|
||||
let kind = kindOf(e);
|
||||
// ★ 从"读变量"出来的线**一律当数据线**:它是纯节点(蓝图里的 Get),
|
||||
// 输出天然是数据,不该拿它当执行链的一环。
|
||||
// 保存时自动推断,用户不用理解两种线的区别也能连对。
|
||||
if (a.type === 'readvar') kind = DATA;
|
||||
// 进"写变量"的线也是数据线(它要的是值,不是执行信号)
|
||||
if (b.type === 'var' && !e.kind) kind = DATA;
|
||||
|
||||
out.push({ from: src, to: dst, branch: String(e.branch || ''), kind });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -295,15 +307,60 @@ function sanitizeEdges(edges, nodes) {
|
||||
const incoming = (edges, id) => edges.filter((e) => e.to === id);
|
||||
const outgoing = (edges, id) => edges.filter((e) => e.from === id);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 两种连线(照 UE 蓝图的语义) */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
//
|
||||
// 蓝图里引脚分两类,作用完全不同:
|
||||
// 执行引脚(exec)白色:**决定执行顺序**。激活输入 → 节点执行 → 激活输出继续往下。
|
||||
// 数据引脚(data)彩色:传值。谁把它们连起来,谁在执行时就能拿到对方的值。
|
||||
//
|
||||
// 我一开始只把节点画成蓝图的样子、引擎还是"谁连着谁就按拓扑序跑",
|
||||
// 那是**只学了长相没学语义**。真正的蓝图里:
|
||||
// - 顺序完全由 exec 链决定,数据线不决定顺序;
|
||||
// - 读变量这种"纯节点"(Get)**没有 exec 引脚**,它的值是被需要的人
|
||||
// **拉取**的,自己不在执行链上 —— 这正是"读变量只有输出"的真正原因。
|
||||
//
|
||||
// 兼容:老会议里没有 kind 字段的边当 exec 处理,并且"没有数据入边时就用
|
||||
// exec 上游的输出"当输入 —— 以前那种"一根线连到底"的图行为不变。
|
||||
|
||||
export const EXEC = 'exec';
|
||||
export const DATA = 'data';
|
||||
|
||||
const kindOf = (e) => (e.kind === DATA ? DATA : EXEC);
|
||||
const execIn = (edges, id) => incoming(edges, id).filter((e) => kindOf(e) === EXEC);
|
||||
const dataIn = (edges, id) => incoming(edges, id).filter((e) => kindOf(e) === DATA);
|
||||
|
||||
function execOut(edges, id, branch = null) {
|
||||
const out = outgoing(edges, id).filter((e) => kindOf(e) === EXEC);
|
||||
if (branch === null) return out;
|
||||
return out.filter((e) => (e.branch || 'true') === branch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个节点的输入 = 它所有上游节点的输出拼起来。
|
||||
* 算出这个节点的输入文本。
|
||||
*
|
||||
* 多条入边就按连线顺序拼 —— 这样"多个智能体的意见汇总给判断节点"
|
||||
* 不需要额外的合并节点。
|
||||
* 优先级:
|
||||
* 1. **数据入边**:把上游的值拼起来(多条按连线顺序)。
|
||||
* 其中"读变量"是纯节点,在**被读取的这一刻**才求值 ——
|
||||
* 它不在执行链上,不能靠 outputs 里有没有它来判断。
|
||||
* 2. 没有数据入边时,用 **exec 上游的输出**。
|
||||
* 这一步是为了省事:最简单的"一根线连到底"不该逼用户连两根线。
|
||||
*/
|
||||
function collectInput(id, edges, outputs) {
|
||||
function collectInput(id, edges, outputs, variables, byId) {
|
||||
const parts = [];
|
||||
for (const e of incoming(edges, id)) {
|
||||
for (const e of dataIn(edges, id)) {
|
||||
const node = byId.get(e.from);
|
||||
// 纯节点:现取现值
|
||||
const value = node && node.type === 'readvar'
|
||||
? (variables[String(node.varName || '').trim()] ?? '')
|
||||
: outputs[e.from];
|
||||
if (value) parts.push(String(value));
|
||||
}
|
||||
if (parts.length) return parts.join('\n\n').trim();
|
||||
|
||||
// 回退:exec 上游的输出
|
||||
for (const e of execIn(edges, id)) {
|
||||
const text = outputs[e.from];
|
||||
if (text) parts.push(String(text));
|
||||
}
|
||||
@@ -407,22 +464,15 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
};
|
||||
|
||||
/**
|
||||
* 某个变量被写入后,把读它的读变量节点唤醒。
|
||||
* 变量被写入后要做的事。
|
||||
*
|
||||
* 写变量没有输出端口(它是"汇"),所以下游不是靠连线接上的 —— 靠这里。
|
||||
* **不管是写变量节点写的,还是智能体用 [[SET]] 写的,都要走这一条**:
|
||||
* 两处不一致的话,就会出现"用节点写能读到、让智能体写就读不到"
|
||||
* 这种极难查的问题(测试抓到过一次)。
|
||||
* ★ 蓝图里"读变量"是**纯节点**(Get):它不在执行链上,值是被需要的节点
|
||||
* 在运行时拉取的(见 collectInput)。所以这里**不需要**叫醒谁 ——
|
||||
* 留着这个函数是为了集中说明这件事,免得以后有人又加回"唤醒"逻辑,
|
||||
* 那会和"拉取"重复执行一遍(Python 侧已经删干净,Node 这边曾漏删,
|
||||
* 对拍时立刻暴露成"rd 混进了执行链")。
|
||||
*/
|
||||
const wakeReaders = (varName) => {
|
||||
for (const other of nodes) {
|
||||
if (other.type === 'readvar'
|
||||
&& String(other.varName || '').trim() === varName
|
||||
&& canRun(other.id)) {
|
||||
queue.push(other.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
const wakeReaders = () => {};
|
||||
|
||||
while (queue.length && steps < maxSteps) {
|
||||
if (shouldStop && shouldStop()) {
|
||||
@@ -452,7 +502,7 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
maxRuns: limitOf(node),
|
||||
});
|
||||
|
||||
const input = collectInput(nodeId, edges, outputs);
|
||||
const input = collectInput(nodeId, edges, outputs, variables, byId);
|
||||
let nextIds = [];
|
||||
|
||||
try {
|
||||
@@ -462,7 +512,7 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
const text = input || String(node.text || '').trim() || (userInput || '');
|
||||
outputs[nodeId] = text;
|
||||
emit({ type: 'node_done', nodeId, output: text, run: runIndex, note: '用的初始输入' });
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
nextIds = execOut(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'agent') {
|
||||
const raw = await runAgentFn(node, input, settings, emit, nodeId, variables);
|
||||
// ★ 把 [[SET 名字=值]] 抽出来写进变量,正文里不留那些行。
|
||||
@@ -485,22 +535,37 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
// 和写变量节点一样,唤醒读这些变量的节点
|
||||
for (const key of Object.keys(changed)) wakeReaders(key);
|
||||
}
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
|
||||
// ★ 智能体是"多路"的:输出一边照常往下游走,一边**同时**存进变量。
|
||||
// 用户的原话是"既可以把输出给下一个智能体的同时也可以保存到变量"——
|
||||
// 所以做成节点上的一个字段,而不是再拉一根线到「写变量」节点:
|
||||
// 光为了存个值就得摆两个节点、连一根线,太重了。
|
||||
//
|
||||
// 两条路互不影响:下游拿到的是**剥掉 [[SET]] 之后**的正文,
|
||||
// 存进变量的也是同一份(不然变量里会混进控制行)。
|
||||
const saveTo = String(node.saveToVar || '').trim();
|
||||
if (saveTo) {
|
||||
variables[saveTo] = cleaned;
|
||||
emit({ type: 'node_vars', nodeId, vars: { [saveTo]: cleaned }, note: `输出已存到 ${saveTo}` });
|
||||
wakeReaders(saveTo);
|
||||
}
|
||||
|
||||
nextIds = execOut(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'var') {
|
||||
// 写变量节点:有上游就用上游内容当值,否则用节点里写死的
|
||||
const name = String(node.varName || '').trim();
|
||||
if (!name) throw new Error('变量节点没填变量名');
|
||||
const value = String(node.varValue || '').trim() || input;
|
||||
variables[name] = value;
|
||||
// 写变量是"汇"(没有输出端口),唤醒读它的节点
|
||||
wakeReaders(name);
|
||||
outputs[nodeId] = value;
|
||||
emit({
|
||||
type: 'node_done', nodeId, output: value, run: runIndex,
|
||||
note: `变量 ${name} = ${value.slice(0, 40)}`,
|
||||
});
|
||||
// 写变量没有输出端口,所以不往下游走
|
||||
nextIds = [];
|
||||
// ★ 写变量**有 exec 出线**(蓝图里 Set 节点就是 exec 进 → exec 出),
|
||||
// 只是没有**数据**出线 —— 存进去的值不从它这里往下传。
|
||||
// 读变量的值也不靠这里"唤醒":它是纯节点,谁需要谁在运行时拉。
|
||||
nextIds = execOut(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'readvar') {
|
||||
// 读变量节点:把变量的当前值当成输出往下传
|
||||
const name = String(node.varName || '').trim();
|
||||
@@ -511,7 +576,7 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
type: 'node_done', nodeId, output: value, run: runIndex,
|
||||
note: `读到 ${name}` + (value ? '' : '(还没设过,是空的)'),
|
||||
});
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
nextIds = execOut(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'judge') {
|
||||
const kind = String(node.judgeKind || 'not_empty');
|
||||
let passed;
|
||||
@@ -535,7 +600,7 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
branch: passed ? 'true' : 'false',
|
||||
note: `判断结果:${passed}`,
|
||||
});
|
||||
const outs = outgoing(edges, nodeId);
|
||||
const outs = execOut(edges, nodeId);
|
||||
nextIds = outs.filter((e) => (e.branch || 'true') === (passed ? 'true' : 'false')).map((e) => e.to);
|
||||
if (!nextIds.length) nextIds = outs.slice(0, 1).map((e) => e.to);
|
||||
} else if (nodeType === 'end') {
|
||||
@@ -551,7 +616,7 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
// 单个节点出错不该让整场会议停摆:记下来,继续跑下游
|
||||
emit({ type: 'node_error', nodeId, error: err.message, run: runIndex });
|
||||
outputs[nodeId] = '';
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
nextIds = execOut(edges, nodeId).map((e) => e.to);
|
||||
}
|
||||
|
||||
// ★ 只有"还能再跑"的节点才重新入队。
|
||||
|
||||
Reference in New Issue
Block a user