Module 4 · Human-in-the-loop

Multi-step approval workflows

5 min read

Real processes often involve several approvals: a supervisor then finance, legal and security in parallel, a manager who can delegate, a deadline after which the request expires. This lesson assembles the primitives seen so far into complete approval circuits, and addresses the questions that arise as soon as a human enters the loop: deadlines, reminders, notifications and interface.

Sequential approvals

Relay's circuit is sequential: each level is a distinct node, and each node chooses what comes next with a Command.

decide ─► supervisor_review ─┬─► finance_review ─┬─► execute
                             ├─► execute         └─► explain
                             └─► explain

One node per level, rather than a single node asking every question, has several benefits:

  • each approval has its own checkpoint: if the supervisor approved yesterday, their decision stands even if finance answers in three days;
  • the graph shows the circuit, readable on the diagram;
  • a level can be skipped depending on the previous level's decision (a reduced amount that no longer needs finance);
  • each level can be tested independently.

The test_two_level_approval test runs the complete circuit: supervisor interrupt, resume, finance interrupt, resume, refund, and a check of the list of approvers (["alice", "bob"]).

Parallel approvals

When several independent opinions are needed (legal AND security), asking one after the other needlessly lengthens delays. Two nodes launched in the same step can interrupt at the same time:

class ReviewState(TypedDict, total=False):
    votes: Annotated[list[tuple[str, str]], operator.add]


def legal(state: ReviewState) -> dict:
    return {"votes": [("legal", interrupt({"who": "legal"}))]}


def security(state: ReviewState) -> dict:
    return {"votes": [("security", interrupt({"who": "security"}))]}


builder.add_edge(START, "legal")
builder.add_edge(START, "security")
builder.add_edge("legal", "consolidate")
builder.add_edge("security", "consolidate")

The run returns two interrupts. You can resume them together, associating each answer with its interrupt's id:

result = graph.invoke(inputs, config, version="v2")
answers = {i.id: ask_human(i.value["who"]) for i in result.interrupts}
graph.invoke(Command(resume=answers), config, version="v2")

You can also resume them one by one, as answers arrive: you then provide only the available answer, associated with its id, and the other interrupt remains pending. The consolidate node only runs once both branches are done: it's lesson 2.3's fan-in, applied to humans. The votes key has an addition reducer, since both branches write to it in the same step.

Deadlines, reminders and expiration

An interrupted graph waits indefinitely: LangGraph manages no timer. Time is therefore managed outside the graph, by your application:

  1. When an interrupt appears, record a follow-up task: thread, step, deadline.
  2. A scheduled process (cron job, delayed message queue) reminds the reviewer halfway through, then handles expiration.
  3. On expiration, resume the graph with a special answer that the node knows how to handle:
timeout_answer = {"decision": "reject", "reviewer": "system:timeout"}
await graph.ainvoke(Command(resume=timeout_answer), config, context=ctx)

The graph thus remains the single source of truth about the request's state, and expiration appears in the audit log like any decision. For Relay, an expired request should rather escalate than be rejected: it's up to you to define the rule, then code and test it.

Notifying the right humans

The graph must not send notifications itself before interrupt() in the same node: on resume, the node starts over and the notification would go out twice (lesson 4.1). Two safe architectures:

  • A dedicated notification node, placed before the approval node: notify_supervisor → supervisor_review. It runs once; make it idempotent in case it is replayed.
  • Event-driven notifications: your server detects the new interrupt (at the end of a run, or via the event stream) and notifies, outside the graph. That is the approach of Relay's server, which sends an interrupt event to the client.

The second approach decouples the graph from notification channels (email, Slack, mobile app), which change more often than business logic.

The approval interface

An approval is only as good as the interface shown to the human. The content of the interrupt() value is your contract with that interface:

  • step identifies who must answer, hence to whom the request is shown;
  • allowed lists the possible actions, hence the buttons;
  • lines and amount form the case file to display;
  • error, when present, explains why the previous answer was rejected.

Relay's server exposes this contract: GET /threads/{id} returns pending approvals, POST /threads/{id}/resume sends the decision. An admin interface can be built entirely on these two routes. It must check that the logged-in person has the role matching step: only a finance team member can answer a finance approval.

The biggest risk: rubber-stamping

An approval circuit can be technically perfect and protect nothing. If 99% of requests are approved in two seconds, humans have stopped reading them. Watch a few indicators: approval rate, response time, edit rate. An approval rate close to 100% with very short delays signals a threshold set too low: raise it, or automate those cases, so human attention focuses where it matters.

Key takeaways

  • Sequential: one node per level, each decision secured in its own checkpoint, routing with Command.
  • Parallel: several nodes interrupted in the same step, answers matched by id, fan-in afterwards.
  • Time (reminders, expiration) is managed outside the graph; expiration is a resume with a dedicated answer.
  • Notifications come from a dedicated node or event-driven processing, never before interrupt() in the same node.
  • The interrupt() value is the contract with the interface; watch out for rubber-stamping.

Practice

  1. Build the parallel legal + security approval graph above, and resume the two interrupts separately, one after the other.
  2. Add a POST /threads/{id}/expire route to Relay's server that resumes the pending approval with the system:timeout answer, and make it escalate rather than reject.
  3. From the audit logs of a series of tests, compute the approval rate and edit rate per approval level.

Resources