6.3

The functional API: @entrypoint and @task

An @entrypoint function runs again from its top on every resume, and each @task that finished before the pause returns its saved result instead of running again.

You have a plain Python function that calls three services in a row. You want it to pause for a person and survive a restart. Rewriting it as nodes and edges would change code that works. The functional API keeps the function and adds checkpoints around its calls.

When you finish this section, you can turn a function into an @entrypoint with @task calls. You can also predict which calls run again on a resume, and keep a value between runs.

The entrypoint and its tasks

Entrypoint: a function decorated with @entrypoint. LangGraph runs it as a graph with one node, and it saves checkpoints on its thread when you pass a checkpointer.

Task: a function decorated with @task. A call returns a future at once, and LangGraph saves the result of the task when it finishes.

The kit workflow doubles three numbers in three tasks, adds them, and asks a person to keep the total. The question is an interrupt inside a task:

pythonan entrypoint with three tasks and a questionFull log
    @task
    def double(x: int) -> int:
        runs.append(f"double({x})")
        return x * 2

    @task
    def ask_human(total: int) -> str:
        return interrupt({"total": total, "question": "Keep it?"})

    @entrypoint(checkpointer=InMemorySaver())
    def workflow(numbers: list[int]) -> dict:
        futures = [double(n) for n in numbers]
        total = sum(f.result() for f in futures)
        answer = ask_human(total).result()
        return {"total": total, "answer": answer}

The three calls of double start all three tasks before the first result(), and each result() waits for one of them.

The functional API page sets three rules for this code. The entrypoint takes one positional argument. Its input and output, and the output of each task, must be JSON-serializable when a checkpointer is set. You call a task only from an entrypoint, from another task, or from a node of a graph.

The first run stops inside a task

The first run doubled 1, 2, and 3, added 12, and stopped at the question. invoke with version="v2" returns the value and the interrupts apart:

jsonthe first run of the workflowFull log
{
  "value": {},
  "interrupts": [
    {
      "value": {
        "total": 12,
        "question": "Keep it?"
      },
      "id": "<hex-1>",
      "response_schema": null
    }
  ]
}

task runs:
[
  "double(1)",
  "double(2)",
  "double(3)"
]

The value is empty, because the function did not return.

The resume restores finished tasks

Command(resume="yes") on the same thread runs workflow again from its first line. The three calls of double return their saved results, and the body of double does not run. ask_human gets "yes" from interrupt, and the function returns:

jsonthe resume of the workflowFull log
{
  "total": 12,
  "answer": "yes"
}

task runs:
[
  "double(1)",
  "double(2)",
  "double(3)"
]

The list of task runs still has three entries. The docs say the same. A resume starts at the top of the entrypoint, and the checkpointer gives back the results of finished tasks. Figure 6.4 draws both runs.

Fig. 6.4two runs of one entrypointsequence
Two runs of one entrypoint Five lifelines: your code, the workflow entrypoint, the double task, the ask_human task, and the checkpointer. A sixth column is the log of task bodies that ran, read from the capture. Run 1: invoke with 1, 2, 3 runs the bodies double(1), double(2), double(3), saves the results 2, 4, 6, calls ask_human with 12, and stops with the interrupt "Keep it?". Run 2: Command resume yes runs workflow again from its top. The double calls return the saved results and the log gets 0 new entries. ask_human gets yes, and workflow returns total 12 and answer yes. your code invoke workflow @entrypoint double @task ask_human @task checkpointer InMemorySaver TASK BODIES RUN the log, in order RUN 1 1 invoke([1, 2, 3]) 2 double(1), (2), (3) double(1) double(2) double(3) 3 results 2, 4, 6 4 ask_human(12) 5 interrupt: Keep it? RUN 2, THE RESUME 6 Command(resume='yes') 7 double(1), (2), (3) 0 new entries 8 saved 2, 4, 6 9 2, 4, 6, no body runs 10 ask_human(12) 11 'yes' 12 total 12, answer yes 3 entries after both runs: each double body ran once
The resume runs workflow from its top, the three double tasks return saved results without running, and only ask_human runs again. Read run 1 at the top and run 2 under it. Teal arrows are saved results, and the amber row is the interrupt. The right column is the log of task bodies that ran.

Code in the entrypoint itself is not a task, so it runs again on every resume, as the docs say. The sum in the kit is such code, and the kit records only the task runs. Put each side effect inside a task, so that a resume starts from saved results. A crash after the effect and before the save can run the task again. Make the effect idempotent too, as section 5.3 shows.

The updates stream of a new run yields one chunk for each finished task, keyed by the task name. The run with the input [5] yielded {"double": 10}, then the __interrupt__ chunk.

A value that stays on the thread

entrypoint.final: a return value of an entrypoint that splits what the caller gets from what the thread saves. The saved value comes back as the previous argument of the next run.

The kit counter adds each input to the saved total. It returns a sentence and saves the number:

pythona counter that keeps its totalFull log
    @entrypoint(checkpointer=InMemorySaver())
    def counter(n: int, *, previous: int | None = None) -> entrypoint.final[int, int]:
        total = (previous or 0) + n
        return entrypoint.final(value=f"added {n} to {previous}, saved {total}", save=total)

Three calls on one thread with 3, 4, and 5 returned these values:

jsonthree calls of the counterFull log
three calls:
[
  "added 3 to None, saved 3",
  "added 4 to 3, saved 7",
  "added 5 to 7, saved 12"
]

The first call got None as previous. Each later call got the number that the call before it saved. The return type entrypoint.final[int, int] in the kit does not match the string value, and the run still works, because LangGraph does not check it.

One node, not a graph of nodes

The graph of the workflow has three nodes: __start__, workflow, and __end__. The tasks are not nodes, so a graph drawing shows none of them. The functional API page says to use the graph API for new agents and workflows. It suggests the functional API for an agent that already exists in other code and must run on Agent Server.

Figure 6.5 draws the graph from its Mermaid text.

Fig. 6.5the graph of an entrypointstructure
The graph of an entrypoint The graph of the workflow entrypoint, drawn from its draw_mermaid output. It has 3 nodes: workflow, __start__, __end__. A plain edge goes from __start__ to workflow and a conditional edge goes from workflow to __end__. The tasks double and ask_human run inside the workflow node and are not in the graph. GET_GRAPH() OF AN @ENTRYPOINT 3 nodes, no task nodes __start__ workflow __end__ double and ask_human run in here plain edge conditional edge, chosen at run time
An entrypoint compiles to one node between __start__ and __end__, and its tasks run inside that node with no node of their own. Read from the top. The workflow node runs the whole function, and each task call runs inside it.

A task can also take retry_policy, cache_policy, and timeout. A timeout works only on an async task, and on a sync task it raises ValueError. The kit does not run them on a task yet. Captures of them come in the next edition, with the other open items of section 8.8.

LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11