# Add Human-in-the-Loop Approval to a LangGraph Agent

Yes. An agent adds a review node that pauses the graph with interrupt() before each tool call, resumes it with Command, tests both answers and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-human-in-the-loop/langgraph/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts from how the graph is built and served, because an approval step is a change to both. In a LangGraph project like langchain-ai/react-agent, `pyproject.toml` asks for `langgraph>=1.2.11` and `uv.lock` holds 1.2.17. `src/react_agent/graph.py` builds `StateGraph(State, input_schema=InputState, context_schema=Context)` with two nodes, `call_model` and `tools` (a `ToolNode` over the `TOOLS` list), and a conditional edge, `route_model_output`, that sends an `AIMessage` with tool calls to `tools` and anything else to the end. The file finishes with `graph = builder.compile(name="ReAct Agent")`, with no checkpointer, and `langgraph.json` serves that variable as the graph named `agent`. The one tool, `search` in `tools.py`, calls Tavily. The README even suggests the exercise: try adding an interrupt before the agent calls tools.

It adds a node, `review_tool_calls`, between the model and the tools. `route_model_output` returns that node's name where it returned `tools`, and the node calls `interrupt({"tool_calls": last_message.tool_calls})` from `langgraph.types`, so whoever is watching the thread receives the exact calls the model wants to make. The value the caller resumes with is the decision. On approve the node returns `Command(goto="tools")`. On reject it returns `Command(goto="call_model", update=...)` with one `ToolMessage` per pending call, each carrying that call's id and the reviewer's reason, so the next model request holds an answer for every tool call it made. The agent uses this dynamic form and not `interrupt_before=["tools"]` on `compile`, which also pauses but hands the caller no payload and is resumed by invoking with `None`, leaving a refusal to be done by editing state by hand.

Three behaviours of the installed version shape the change, and the agent checks each by running it. First, a pause needs somewhere to be stored: compiled the way the repository compiles it, the first call still returns with an `__interrupt__` entry, but resuming raises `RuntimeError: Cannot use Command(resume=...) without checkpointer`. Second, the fix is not to add a checkpointer to the exported `graph`. The `langgraph-api` package that `langgraph dev` runs from this lockfile refuses to load a graph compiled with one, with an error that names the custom checkpointer and says the platform handles persistence itself. So the exported graph stays as it is, and code that embeds the agent elsewhere compiles `builder` with its own saver. Third, a resumed node starts again from its first line, and the run's `context` is not part of the checkpoint: a resume call that omits `context=` reaches `call_model` with `runtime.context` set to `None` and fails on `.model`.

Then it writes tests under `tests/unit_tests/`, in the style of the suite that is there: `pytestmark = pytest.mark.anyio`, with the backend fixed to asyncio in `tests/conftest.py`. A scripted fake model replaces `load_chat_model` and a stub replaces the search, so no key is read. The tests compile `builder` with `InMemorySaver` and cover the pause (the search has not run and the thread's `next` is `review_tool_calls`), approve, reject, and a call with no `thread_id`, which fails with a `ValueError` naming the missing key. Last, `uv sync --extra dev`, because `ruff` and `mypy` sit in the `dev` extra while `pytest` is in the `dev` dependency group, and the three commands of `.github/workflows/unit-tests.yml`: `ruff check .`, `mypy --strict src/` and `pytest tests/unit_tests`.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add human approval before tool calls to this LangGraph agent. Read pyproject.toml, uv.lock (the langgraph, langgraph-checkpoint and langgraph-api versions), langgraph.json, the Makefile, every file under src/react_agent, tests/conftest.py, both test directories and .github/workflows first. In src/react_agent/graph.py add a node review_tool_calls between call_model and tools: route_model_output sends an AIMessage with tool calls to it, it calls interrupt() from langgraph.types with the pending tool calls as the payload, and it returns Command(goto=\"tools\") when the resume value approves, or Command(goto=\"call_model\") with one ToolMessage per pending tool call id carrying the reviewer's reason when it rejects. Put nothing with a side effect before the interrupt() call, because the node runs again from the top on resume. Do not compile the exported graph with a checkpointer: check what langgraph dev does with one and say what you found. Keep builder importable so callers and tests can compile it with their own checkpointer. Add unit tests under tests/unit_tests that compile builder with InMemorySaver, use a scripted fake model and a stubbed search so no API key is needed, and cover: the pause before the tool runs, approve, reject, a call without thread_id, and a resume without context. Document in the README how a caller resumes a paused thread, including that context must be passed again. Run uv sync --extra dev, ruff check ., mypy --strict src/ and pytest tests/unit_tests, do not run tests/integration_tests, paste the output in the pull request and open it.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that changes `src/react_agent/graph.py`, adds one test file under `tests/unit_tests/` and a short README section. The graph gains one node and one changed return value in the routing function; `tools.py`, `state.py` and `context.py` are untouched, and so is `langgraph.json`, since the served graph keeps its name. The README section shows the two calls a client makes: the first `ainvoke` with a `thread_id`, which returns the pending tool calls under `__interrupt__`, and the second with `Command(resume={"action": "approve"})`, the same config and the same `context`.

A reviewer reads the payload first, because it becomes the contract with whatever screen shows the approval: is the list of tool calls enough, or does the reviewer need the user's question beside it. They check that a rejection writes one `ToolMessage` for every pending call, since a model may ask for several tools at once and a missing answer is refused by the provider on the next request. And they decide the policy the code cannot: this change asks for approval on every call, including a read-only web search, which is the right default for a tool that sends email and probably more than a search needs.

## Run it on every Linear issue labelled needs-approval

The approval node is written once; what recurs is deciding which new tool goes behind it. In the console, add an automation on the Project that holds the repository with a `linear` trigger on `linear.issue.labeled` and the label `needs-approval`, and a prompt that says: put the tool the issue names behind `review_tool_calls`, leave the other tools unreviewed, add a test for each answer and open a pull request. The issue is placed after the prompt as the event and fills in nothing, so the tool's name comes from whoever wrote the issue. The trigger needs a Linear connection for the automation's runner and fires only when the label is applied by someone in your Rush org.

## Why run it on Rush?

The parts of this job that go wrong are not in the node, which is a dozen lines, but in how pausing behaves in the version you have: what happens with no checkpointer, what the dev server does with one, what a resumed node repeats, what a resume call must pass again. Those are answered by running the graph, and the agent runs it in its own sandbox against the versions in your lockfile, with a fake model, so no provider key is involved and nothing on your machine is occupied while it does.

Each of those experiments stays in the run's transcript at `GET /o/{org}/sessions/{id}/messages`, command and output together. When the pull request says the dev server refuses a custom checkpointer, the traceback it quotes is there to read. A reviewer who doubts a claim about a library that changes this quickly can check it against what was printed, which is a better basis for merging than a summary of the documentation.

## Frequently asked questions

### Does interrupt() work without a checkpointer?

It pauses, but the pause cannot be resumed. On `langgraph` 1.2.17 the first call returns with `__interrupt__` in its result, and `Command(resume=...)` then raises a `RuntimeError` saying a checkpointer is required. Compile `builder` with a saver, and pass a `thread_id` in `configurable` on both calls.

### Do I add a checkpointer when the graph runs under langgraph dev or LangGraph Platform?

No. The server supplies persistence for every thread, and the `langgraph-api` version in this template's lockfile fails to load a graph that was compiled with its own checkpointer. Keep the exported graph compiled without one, and compile `builder` with a saver only where you embed the agent in your own process, as the tests do.

### Why does my node run twice after a resume?

A resumed node starts again from its first line, and `interrupt()` returns the resume value the second time through. Anything above that call runs on both passes. The node this change adds does nothing before the interrupt but read the last message, so the repeat is harmless.

## More LangGraph jobs

- [Add a Fallback Model to a LangGraph Agent](https://getrush.ai/run/add-model-fallbacks/langgraph/)
- [Add Rate Limiting to a LangGraph Agent](https://getrush.ai/run/add-rate-limiting/langgraph/)
- [Add Structured Output to a LangGraph Agent](https://getrush.ai/run/add-structured-output/langgraph/)

## More jobs like this: Turn a Linear label into a PR

- [Add i18n to an AdonisJS App](https://getrush.ai/run/add-i18n/adonisjs/)
- [Add i18n to an Angular App](https://getrush.ai/run/add-i18n/angular/)
- [Add a Second Language to an Astro Site](https://getrush.ai/run/add-i18n/astro/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
