Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Function

entrypoint

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.

How it works

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.

Syntax

entrypoint(optionsOrName, func)

Parameters

NameTypeDescription
optionsOrNamestring | EntrypointOptionsA 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.

Returns

A Pregel instance that can be run to execute the workflow.

Key points

  • The function turns ordinary workflow logic into a LangGraph workflow.
  • The first argument supports either configuration or a concise workflow name.
  • The callback contains the workflow's executable logic.
  • The return value is an executable Pregel runtime object.
  • Custom streaming can be produced through the writer helper or runtime configuration.
  • Use entrypoint.final when persisted state must include more than the normal workflow result.

Common mistakes

  • The wrapped function can take only the input and optional configuration; package multiple logical inputs into one object.
  • The second argument is reserved for LangGraph runtime configuration, not another application input.
  • Use one object input when the workflow needs several values.
  • Previous state is thread-scoped and available through the documented helper rather than being an implicit local variable.

Example: Minimal entrypoint workflow

import { entrypoint } from "@langchain/langgraph";

const workflow = entrypoint(
  "double",
  async (value: number) => value * 2
);

const result = await workflow.invoke(21);
console.log(result); // 42

Creates a named workflow whose input is doubled, then invokes the returned workflow.

When to use it

Function-based workflows

Create a functional LangGraph workflow from a single asynchronous function.

Resumable execution

Run workflows that need checkpoint-backed persistence or human review.

Custom streaming

Expose application-specific events through LangGraph's custom stream.

Interview questions

QWhat does 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.

QWhat arguments does 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.

QHow does an entrypoint support state and runtime features?

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.

  • EntrypointFunction
  • EntrypointOptions
  • LangGraphRunnableConfig
  • Pregel
  • getPreviousState
  • getWriter
  • entrypoint.final

Source: entrypoint | LangGraph.js API Reference. Checked 2026-10-15.