#329: Human in the Loop With LangGraph
Last week we learned how to build our own tools to use in LangGraph. Sometimes those tools could be dangerous, and we want to approve their usage before they run. For that we can use the Human-in-the-Loop (HITL) pattern.
Human-in-the-Loop?
Human-in-the-loop means pausing an automated workflow at key moments so a human can review, edit, approve, or reject important decisions, especially when judgment, risk, ethics, or accountability matter.
LangGraph implements this pattern through breakpoints, which pause agent execution at specific nodes. The system saves its state to a checkpointer, allowing a human to inspect the current context and intervene before the graph continues. This active review step improves safety and accuracy in high-stakes autonomous workflows.
Augment our tool graph
We can add the HITL pattern to the graph we created last week to work with our tools. Most of the code stays the same, but we need a few additional imports and new sections to create the checkpointer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
Review the tool use
When we now run our script, the workflow gets interrupted before LangGraph runs the tool. This gives us the opportunity to review and decide how we want to continue.
--- Starting Graph ---
================================ Human Message =================================
What is 144 multiplied by 2?
--- AGENT: Reasoning ---
================================== Ai Message ==================================
Tool Calls:
multiply (162488692)
Call ID: 162488692
Args:
a: 144
b: 2
>>> PAUSED: The agent wants to call tools: ('tools',)
Do you allow the tool execution? (yes/no): yes
--- Resuming Graph ---
================================== Ai Message ==================================
Tool Calls:
multiply (162488692)
Call ID: 162488692
Args:
a: 144
b: 2
================================= Tool Message =================================
Name: multiply
288
--- AGENT: Reasoning ---
================================== Ai Message ==================================
The product of 144 and 2 is **288**.
In this example we accepted the action and we got our usual output. However, if we say no to the tool call, the workflow ends before it calls the tool:
--- Starting Graph ---
================================ Human Message =================================
What is 144 multiplied by 2?
--- AGENT: Reasoning ---
================================== Ai Message ==================================
Tool Calls:
multiply (325071064)
Call ID: 325071064
Args:
a: 144
b: 2
>>> PAUSED: The agent wants to call tools: ('tools',)
Do you allow the tool execution? (yes/no): no
Tool execution denied by user.
Next
With this little script we could see how we can add a manual check for a human. While this could prevent our agent from doing something it should not do, it will often end in a lot of manual work that we may not need. Therefore, be careful with what you use the HITL pattern.
Next week we search for a way to only use HITL for a few tools but not all. That is not as straightforward as one would think.