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

Approving Tool Calls

Yes or no.

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

Agents choose their own tools. For a tool that spends money, like placing an order, we want a person to approve each call. The simplest way is to call interrupt inside the tool itself.

Approving Tool Calls
From the video: Approving Tool Calls
  • Agents pick tools
  • Some tools spend money
  • interrupt inside the tool

A tool that asks first

Here's the place order tool. Before doing anything, it calls interrupt, with the title and quantity. The decision comes back as a dictionary. Reject stops the order. Edit changes the quantity. Anything else, the order goes ahead.

order_agent.pypython
@tool
def place_order(title: str, quantity: int) -> str:
    """Place an order for copies of a book."""
    decision = interrupt({"action": "place_order", "title": title, "quantity": quantity})
    if decision["type"] == "reject":
        return "Order rejected by staff."
    if decision["type"] == "edit":
        quantity = decision["quantity"]
    return f"Ordered {quantity} x {title}."

Approving an order

The agent graph, with this tool and a checkpointer, lives in the same helper file. We ask for two copies of Dune. The agent calls place order, and the graph pauses. We print the request, then resume with approve. Run it. The order is placed, and the agent confirms it to the customer.

approve_tool.pypython
from langgraph.types import Command
from order_agent import graph

config = {"configurable": {"thread_id": "order-1"}}
ask = {"messages": [{"role": "user", "content": "Please order 2 copies of Dune."}]}

paused = graph.invoke(ask, config)
print("needs approval:", paused["__interrupt__"][0].value)

done = graph.invoke(Command(resume={"type": "approve"}), config)
print("agent:", done["messages"][-1].text.strip())
Output
needs approval: {'action': 'place_order', 'title': 'Dune', 'quantity': 2}
agent: I have successfully placed an order for 2 copies of Dune.
Also uses order_agent.py
from langchain.chat_models import init_chat_model
from langchain.tools import tool
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import MessagesState, StateGraph, START
from langgraph.prebuilt import ToolNode, tools_condition
from langgraph.types import interrupt

@tool
def place_order(title: str, quantity: int) -> str:
    """Place an order for copies of a book."""
    decision = interrupt({"action": "place_order", "title": title, "quantity": quantity})
    if decision["type"] == "reject":
        return "Order rejected by staff."
    if decision["type"] == "edit":
        quantity = decision["quantity"]
    return f"Ordered {quantity} x {title}."

model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0).bind_tools([place_order])

def agent(s: MessagesState):
    return {"messages": [model.invoke(s["messages"])]}

b = StateGraph(MessagesState)
b.add_node(agent); b.add_node("tools", ToolNode([place_order]))
b.add_edge(START, "agent"); b.add_conditional_edges("agent", tools_condition); b.add_edge("tools", "agent")
graph = b.compile(checkpointer=InMemorySaver())

Summary

Calling interrupt inside a tool makes every call to it wait for approval. Resume with the decision. Next, editing the action before it runs.

Key takeaways
  • interrupt in the tool
  • Pause per call
  • Resume with approve
Next up: Editing Before Continuing — human corrections