Either an TaskOptions object, or a string for the name of the task
The function that executes this task
A proxy function that accepts the same arguments as the original and always returns the result as a 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;
});
Define a LangGraph task using the
task
function.Tasks can only be called from within an entrypoint or from within a StateGraph. A task can be called like a regular function with the following differences: