包含在中断中的值。 这将在 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 值时
中断图节点的执行。此函数可用于暂停节点的执行,并在使用
Command
重新调用图时返回resume
输入的值。可以在单个节点内多次调用中断,并且每个中断将按顺序处理。当调用中断时
resume
值(来自之前的Command
),则返回该值。GraphInterrupt
resume
值的Command
来恢复图由于
interrupt
函数通过抛出一个特殊的GraphInterrupt
错误来传播,因此您应避免在interrupt
函数周围使用try/catch
块,或者如果这样做,请确保GraphInterrupt
错误在您的catch
块中再次抛出。