Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Langchain ai Langgraph Entrypoint Definition

From Leeroopedia
Attribute Value
Concept Defining workflow entry points that compose tasks into executable graphs using the functional API
Workflow Functional_API_Workflow
Type Principle
Repository Langchain_ai_Langgraph
Source libs/langgraph/langgraph/func/__init__.py

Overview

The entrypoint is the top-level construct in LangGraph's functional API. It defines the boundary of a workflow -- the function that external callers invoke and that serves as the container for all task orchestration. When a function is decorated with @entrypoint(), it is implicitly compiled into a Pregel graph with a single node, gaining access to LangGraph's execution engine including checkpointing, streaming, interrupts, and store access.

Unlike the graph-based API where developers explicitly create StateGraph objects, add nodes, and define edges, the functional API uses the entrypoint decorator to infer the graph structure from ordinary Python control flow. The decorated function becomes both the graph definition and its sole orchestration node; individual @task-decorated functions called within it become the parallelizable units of work.

Description

Entrypoint as a Workflow Container

An entrypoint defines the outermost scope of a functional API workflow. It has several responsibilities:

  • Input validation: The decorated function must accept exactly one positional parameter (the workflow input). This input can be of any type -- a string, integer, dictionary, or custom object. Additional keyword-only parameters can be declared for dependency injection (e.g., previous, config, runtime).
  • Task orchestration: Within the entrypoint body, the developer calls @task-decorated functions, which return futures. Standard Python control flow (conditionals, loops, exception handling) governs the orchestration logic.
  • Result production: The return value of the entrypoint function becomes the output of the workflow. When using entrypoint.final, the return value and the checkpointed state can differ.

Decorator-Based Graph Creation

When @entrypoint() is applied to a function, the entrypoint class's __call__ method executes and:

  1. Inspects the function signature to determine the input type, output type, and whether entrypoint.final is used.
  2. Wraps the function in a RunnableCallable that supports both sync and async execution.
  3. Constructs a Pregel graph with a single PregelNode bound to the wrapped function.
  4. Configures channels for START (input), END (output), and PREVIOUS (checkpointed state).
  5. Attaches the checkpointer, store, cache, and retry/cache policies from the decorator parameters.

The resulting Pregel object is returned in place of the original function, so calling my_workflow.invoke(data) or my_workflow.stream(data) routes through the full LangGraph execution pipeline.

Implicit Compilation

In the graph-based API, the developer must explicitly call graph.compile(checkpointer=...) to produce a runnable graph. The functional API eliminates this step: the @entrypoint() decorator is the compilation step. The checkpointer and other configuration are provided as decorator arguments, and the compiled Pregel graph is produced immediately when the decorator executes at module load time.

This implicit compilation means:

  • The decorated name (e.g., my_workflow) is a Pregel instance, not the original function.
  • It has .invoke(), .stream(), .ainvoke(), and .astream() methods.
  • It can be used as a subgraph within other LangGraph graphs.
  • Graph metadata (node names, channel types) is derived from the function signature rather than explicit builder calls.

Injectable Parameters

The entrypoint function can declare special keyword parameters that are injected automatically at runtime:

Parameter Description
config A RunnableConfig object containing runtime configuration such as thread_id, callbacks, and metadata.
previous The return value (or save value) from the previous invocation on the same thread. Only available when a checkpointer is provided.
runtime A Runtime object bundling context, store, and stream writer for the current run.

These injectable parameters enable the entrypoint to access execution context without breaking the single-input-parameter contract.

Usage

from langgraph.func import entrypoint, task
from langgraph.checkpoint.memory import InMemorySaver

@task
def process_item(item: str) -> str:
    return item.upper()

@entrypoint(checkpointer=InMemorySaver())
def my_workflow(items: list[str]) -> list[str]:
    futures = [process_item(item) for item in items]
    return [f.result() for f in futures]

# The decorated function is a Pregel graph
config = {"configurable": {"thread_id": "t1"}}
result = my_workflow.invoke(["hello", "world"], config)
# result: ["HELLO", "WORLD"]

# Streaming is also available
for chunk in my_workflow.stream(["foo", "bar"], config):
    print(chunk)

Theoretical Basis

The entrypoint concept draws from several foundational ideas:

  • Workflow Orchestration: In workflow engines (Temporal, Airflow, Prefect), a workflow is a top-level function that composes individual activities or tasks. LangGraph's entrypoint follows this pattern, serving as the orchestrator that dispatches tasks and collects results. The key distinction is that LangGraph entrypoints use standard Python control flow rather than a separate DSL or YAML configuration.
  • Implicit Graph Construction: Traditional dataflow systems require explicit graph definitions (nodes and edges). The functional API infers the graph from function calls and data dependencies, similar to how TensorFlow's eager mode or JAX's tracing constructs computation graphs from Python code. The entrypoint function is "traced" at runtime to discover which tasks are called and how their results flow.
  • Single-Responsibility Entry Point: The entrypoint pattern follows the principle that a system should have a well-defined entry point that encapsulates initialization and configuration. By combining graph compilation with function decoration, the entrypoint becomes the single point of configuration for checkpointing, caching, retry, and context management.
  • Decorator as Meta-programming: The use of a class-based decorator (entrypoint is a class, not a function) enables attaching class-level attributes like entrypoint.final while maintaining the @entrypoint() decorator syntax. This is a Python meta-programming pattern that provides both runtime behavior modification and IDE-friendly type information.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment