Function-based workflows
Create a functional LangGraph workflow from a single asynchronous function.
AI Agents · Function
entrypoint wraps an asynchronous function as a LangGraph workflow. It returns an executable Pregel instance and can be configured with a name, checkpointer, and runtime features.
Call entrypoint with a name or options object and an asynchronous function. The function receives the workflow input and optionally a runtime configuration, while entrypoint returns a Pregel instance that supports workflow execution; use a checkpointer when the workflow needs persisted state or resumable behavior.
entrypoint(optionsOrName, func)| Name | Type | Description |
|---|---|---|
optionsOrName | string | EntrypointOptions | A string name or an EntrypointOptions configuration object. |
func | (input: InputT, config?: LangGraphRunnableConfig) => Promise<OutputT> | The asynchronous function that executes the workflow; it accepts input and optionally LangGraphRunnableConfig. |
A Pregel instance that can be run to execute the workflow.
entrypoint.final when persisted state must include more than the normal workflow result.import { entrypoint } from "@langchain/langgraph";
const workflow = entrypoint(
"double",
async (value: number) => value * 2
);
const result = await workflow.invoke(21);
console.log(result); // 42Creates a named workflow whose input is doubled, then invokes the returned workflow.
Create a functional LangGraph workflow from a single asynchronous function.
Run workflows that need checkpoint-backed persistence or human review.
Expose application-specific events through LangGraph's custom stream.
entrypoint return?entrypoint defines a workflow around a function. Its wrapped function accepts an input and optionally a LangGraphRunnableConfig, and the call returns a Pregel instance that executes the workflow.
Follow-up: How would you pass three independent values? Use a single object as the input, because the wrapped function may accept at most two parameters and the second is configuration.
entrypoint accept?The first argument can be an entrypoint name string or an options object, and the second is the function that performs the workflow. The resulting Pregel instance can then be invoked to run it.
Follow-up: When would the options object be preferable? Use it when configuring properties such as a name or checkpointer rather than relying on the shorthand name form.
A checkpointer can persist workflow state, and getPreviousState can retrieve the value returned by the previous invocation on the same thread ID. State beyond the return value can be saved with entrypoint.final.
Follow-up: How can custom stream data be emitted? Use getWriter or the writer property on LangGraphRunnableConfig.
EntrypointFunctionEntrypointOptionsLangGraphRunnableConfigPregelgetPreviousStategetWriterentrypoint.final