AI Hints
Home›LangGraph Tutorial›Approvals in Practice
LangGraph · Lesson 60 of 120

Practice: Refund Approval

Pause for a manager.

⏱ 2 min read▶ Video at 1:03:35🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Let's practise. Small refunds should go through automatically. Refunds over twenty pounds need a manager. One graph, with a branch, and an interrupt only on the risky path.

Practice: Refund Approval
From the video: Practice: Refund Approval
  • Small refunds: automatic
  • Large refunds: a manager
  • Interrupt only when needed

Refunds with a threshold

The router sends small amounts to auto, and large amounts to manager, which calls interrupt. We try an eight pound refund, and a forty five pound one. Run it. The small refund completes immediately. The large one pauses, and finishes only after the manager approves.

refund_practice.pypython
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START
from langgraph.types import Command, interrupt

class State(TypedDict):
    amount: float
    status: str
def manager(s):
    ok = interrupt(f"Refund £{s['amount']}? approve/decline") == "approve"
    return {"status": "refunded (manager)" if ok else "declined"}

b = StateGraph(State); b.add_node(manager); b.add_node("auto", lambda s: {"status": "refunded (auto)"})
b.add_conditional_edges(START, lambda s: "manager" if s["amount"] > 20 else "auto")
graph = b.compile(checkpointer=InMemorySaver())
for i, amount in enumerate([8.0, 45.0]):
    cfg = {"configurable": {"thread_id": f"t{i}"}}
    out = graph.invoke({"amount": amount}, cfg)
    print(amount, out.get("status") or graph.invoke(Command(resume="approve"), cfg)["status"])
Output
8.0 refunded (auto)
45.0 refunded (manager)

What you practised

You combined a routing function, an interrupt on one branch, and a checkpointer. Only risky cases wait for a person. Try adding a third branch, that rejects refunds over two hundred pounds automatically.

keyvalue
Routeby amount
Interruptonly when risky
Resumewith a decision
Tryan auto-reject branch

Summary

Route small cases automatically, and interrupt only for risky ones. Next, a quiz on human in the loop.

Key takeaways
  • Threshold routing
  • Interrupt on one branch
  • Resume to finish
Next up: Human-in-the-Loop Quiz — test yourself