LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphwebentrypoint
Functionā—Since v0.3

entrypoint

Define a LangGraph workflow using the entrypoint function.

Function signature

The wrapped function must accept at most two parameters. The first parameter is the input to the function. The second (optional) parameter is a LangGraphRunnableConfig object. If you wish to pass multiple parameters to the function, you can pass them as an object.

Helper functions

Streaming

To write data to the "custom" stream, use the getWriter function, or the LangGraphRunnableConfig.writer property.

State management

The getPreviousState function can be used to access the previous state that was returned from the last invocation of the entrypoint on the same thread id.

If you wish to save state other than the return value, you can use the entrypoint.final function.

Copy
entrypoint<
  InputT,
  OutputT
>(
  optionsOrName: string | EntrypointOptions,
  func: EntrypointFunc<InputT, OutputT>
): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, __type, Record<string, unknown>, InputT, EntrypointReturnT<OutputT>, any, Awaited<EntrypointReturnT<OutputT>>>

Used in Docs

  • Choosing between Graph and Functional APIs
  • Functional API overview
  • MISSING_CHECKPOINTER
  • Quickstart
  • Use the functional API

Parameters

NameTypeDescription
optionsOrName*string | EntrypointOptions

Either an EntrypointOptions object, or a string for the name of the entrypoint

func*EntrypointFunc<InputT, OutputT>

The function that executes this entrypoint

Example 1

Copy
import { task, entrypoint } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";
import { interrupt, Command } from "@langchain/langgraph";

const composeEssay = task("compose", async (topic: string) => {
  await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation
  return `An essay about ${topic}`;
});

const reviewWorkflow = entrypoint({
  name: "review",
  checkpointer: new MemorySaver()
}, async (topic: string) => {
  const essay = await composeEssay(topic);
  const humanReview = await interrupt({
    question: "Please provide a review",
    essay
  });
  return {
    essay,
    review: humanReview
  };
});

// Example configuration for the workflow
const config = {
  configurable: {
    thread_id: "some_thread"
  }
};

// Topic for the essay
const topic = "cats";

// Stream the workflow to generate the essay and await human review
for await (const result of reviewWorkflow.stream(topic, config)) {
  console.log(result);
}

// Example human review provided after the interrupt
const humanReview = "This essay is great.";

// Resume the workflow with the provided human review
for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {
  console.log(result);
}

Example 2

Copy
import { entrypoint, getPreviousState } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";

const accumulator = entrypoint({
  name: "accumulator",
  checkpointer: new MemorySaver()
}, async (input: string) => {
  const previous = getPreviousState<number>();
  return previous !== undefined ? `${previous } ${input}` : input;
});

const config = {
  configurable: {
    thread_id: "some_thread"
  }
};
await accumulator.invoke("hello", config); // returns "hello"
await accumulator.invoke("world", config); // returns "hello world"

Example 3

Copy
import { entrypoint, getPreviousState } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";

const myWorkflow = entrypoint({
  name: "accumulator",
  checkpointer: new MemorySaver()
}, async (num: number) => {
  const previous = getPreviousState<number>();

  // This will return the previous value to the caller, saving
  // 2 * num to the checkpoint, which will be used in the next invocation
  // for the `previous` parameter.
  return entrypoint.final({
    value: previous ?? 0,
    save: 2 * num
  });
});

const config = {
  configurable: {
    thread_id: "some_thread"
  }
};

await myWorkflow.invoke(3, config); // 0 (previous was undefined)
await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)

Methods

method
final→ EntrypointFinal<ValueT, SaveT>

A helper utility for use with the functional API that returns a value to the caller, as well as a separate state value to persist to the checkpoint. This allows workflows to maintain state between runs while returning different values to the caller.

View source on GitHub