要包含在中断中的值。这将在 task.interrupts[].value 中可用。
当图使用 Command 重新调用时提供的 resume
值
// Define a node that uses multiple interrupts
const nodeWithInterrupts = () => {
// First interrupt - will pause execution and include {value: 1} in task values
const answer1 = interrupt({ value: 1 });
// Second interrupt - only called after first interrupt is resumed
const answer2 = interrupt({ value: 2 });
// Use the resume values
return { myKey: answer1 + " " + answer2 };
};
// Resume the graph after first interrupt
await graph.stream(new Command({ resume: "answer 1" }));
// Resume the graph after second interrupt
await graph.stream(new Command({ resume: "answer 2" }));
// Final result: { myKey: "answer 1 answer 2" }
如果在图的上下文之外调用
当没有可用的 resume 值时
中断图节点(graph node)的执行。此函数可用于暂停节点执行,并在图使用
Command
重新调用时返回resume
输入的值。单个节点中可以调用多个中断,每个中断将按顺序处理。当调用中断时
resume
值(来自之前的Command
),它将返回该值。GraphInterrupt
。resume
值的Command
,可以恢复图的执行。由于
interrupt
函数通过抛出特殊的GraphInterrupt
错误进行传播,因此您应该避免在interrupt
函数周围使用try/catch
块,如果使用了,请确保在您的catch
块中再次抛出GraphInterrupt
错误。