TaskOptions 对象,或任务名称的字符串
执行此任务的函数
一个代理函数,它接受与原始函数相同的参数,并始终将结果作为 Promise 返回
const addOne = task("add", async (a: number) => a + 1);
const workflow = entrypoint("example", async (numbers: number[]) => {
const promises = numbers.map(n => addOne(n));
const results = await Promise.all(promises);
return results;
});
// Call the entrypoint
await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]
const addOne = task({
name: "add",
retry: { maxAttempts: 3 }
},
async (a: number) => a + 1
);
const workflow = entrypoint("example", async (numbers: number[]) => {
const promises = numbers.map(n => addOne(n));
const results = await Promise.all(promises);
return results;
});
使用
task
函数定义 LangGraph 任务。任务只能从 entrypoint 或 StateGraph 内部调用。任务可以像常规函数一样调用,但有以下区别