Python workflows written as plain functions lose their place when they stop to wait for a person or fail partway through. A LangGraph Functional API entrypoint keeps that code as ordinary functions and if statements, and adds saved progress so a run can pause for input and return its result once the same thread resumes.

The @entrypoint decorator turns one function into a workflow with a checkpointer, and @task marks the work whose results belong in the checkpoint. A resume does not continue from the paused line. The entrypoint runs again from its first line and completed tasks return their saved results, so anything outside a task repeats and side effects belong inside tasks.

LangGraph recommends its Graph API for new workflows, while the Functional API suits procedural code that already exists because it needs no state schema or graph definition. InMemorySaver needs no database but keeps checkpoints inside one Python process, so a run that must resume after a restart needs a database-backed checkpointer.

Steps to build a Functional API entrypoint in LangGraph:

  1. Install the current LangGraph release in the active project environment.
    $ python -m pip install --upgrade langgraph

    LangGraph requires Python 3.10 or newer. Tested with LangGraph 1.2.20 on Python 3.12 on Linux.
    Related: How to install LangGraph with pip

  2. Create a file named refund_workflow.py in your project folder using your text editor.
  3. Enter the imports for the decorators, the interrupt helpers, and the checkpointer at the top of the file.
    refund_workflow.py
    from langgraph.checkpoint.memory import InMemorySaver
    from langgraph.func import entrypoint, task
    from langgraph.types import Command, interrupt
  4. Add the first task below the imports to calculate the requested refund.
    @task
    def calculate_refund(order: dict) -> int:
        print("Calculating refund")
        return order["quantity"] * order["unit_price"]

    Calling a @task function starts it and returns a future, so the workflow reads the value with .result(). A task needs a running workflow, and a direct call from ordinary code raises RuntimeError.

  5. Add a second task below calculate_refund() for the step that issues the refund.
    @task
    def issue_refund(order_id: str, amount: int) -> str:
        print("Issuing refund")
        return f"Refunded {amount} on {order_id}"

    A real version would call a payment service here. A task that started but did not finish may run again, so such a call should use an idempotency key.

  6. Add the entrypoint below the tasks with an InMemorySaver as its checkpointer.
    @entrypoint(checkpointer=InMemorySaver())
    def refund_workflow(order: dict) -> str:
        print("Entrypoint started")
        requested = calculate_refund(order).result()
     
        if requested <= 50:
            return issue_refund(order["id"], requested).result()

    An entrypoint takes one positional input, so several values travel in one dictionary. The if is plain Python, and a refund of 50 or less finishes here without pausing.

  7. Add the interrupt at the end of the refund_workflow() function body, indented to match the lines above it.
        approved = interrupt(
            {"order_id": order["id"], "requested": requested}
        )
        return issue_refund(order["id"], approved).result()

    interrupt() stops the run and hands the dictionary to the caller. On resume, the same call returns the value the caller supplied, so approved holds the reviewer's amount. Without a checkpointer the pause still appears, but the resume raises RuntimeError.

  8. Add the first invocation below the function, starting at the left margin, with a thread_id for this refund.
    config = {"configurable": {"thread_id": "refund-1042"}}
    order = {"id": "order-1042", "quantity": 3, "unit_price": 40}
     
    paused = refund_workflow.invoke(order, config)
    request = paused["__interrupt__"][0].value
    print("Waiting on:", refund_workflow.get_state(config).next)

    While a run is paused, invoke() returns the pending interrupts in a dictionary instead of the function's return value. get_state() reads the saved thread, and next names the work still pending.

  9. Add the resume call at the end of the file with the same config.
    print("Review request:", request)
    approved = int(input("Amount to refund: "))
    result = refund_workflow.invoke(
        Command(resume=approved), config
    )
     
    print("Result:", result)
    print("Waiting on:", refund_workflow.get_state(config).next)

    A Command sent with a different thread_id does not reach this pause. It starts a new run with the Command as its input, which fails here with TypeError.

  10. Save refund_workflow.py.
  11. Run refund_workflow.py from your project folder with the project environment active.
    $ python refund_workflow.py
    Entrypoint started
    Calculating refund
    Waiting on: ('refund_workflow',)
    Review request: {'order_id': 'order-1042', 'requested': 120}
    Amount to refund:

    The script stops at the prompt with the run paused and its calculate_refund() result saved in the thread.

  12. Enter 80 at the prompt to confirm that the same thread resumes with the reviewer's amount.
    Amount to refund: 80
    Entrypoint started
    Issuing refund
    Result: Refunded 80 on order-1042
    Waiting on: ()

    Entrypoint started prints again because the resume reran the function from its first line. Calculating refund does not, because the saved task result was restored. The result carries the amount you entered, and the empty Waiting on value shows nothing is pending in the thread.

Share this guide