By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The support graph is now one compiled object, and it serves two very different requests. A question — where is order A17? — is a read: the model asks for a lookup, the result lands in state, and the run ends with an answer. A write — refund order A17 — must cross a guardrail and a human approval before anything executes. Same nodes, same state schema, different path: to understand the graph, you have to trace a request through it, edge by edge.
The diagram below is that trace. Pick a scenario, then step through it; each step lights up the part of the graph that is active at that moment — a state field, the router, the tool that runs, or the approval gate.
Read the two scenarios as one machine under different input. Both start at START, both call the model, and both end at END — but the lookup path never touches the approval gate, and the refund path never touches the lookup tool. The state column is the only thing they share: messages accumulates the conversation the model reads, and order_id is the fact every node can rely on without re-parsing the text.
Not every edge in the diagram has the same status. An unconditional edge always fires once its source node completes; a conditional edge fires only when the router returns the label it maps to. Both kinds are visible in the code example below: START -> model and tools -> model are unconditional, while the three edges leaving the router are a mapping from labels to destinations.
| Edge or gate | Kind | When it fires |
|---|---|---|
START -> model | Unconditional | Every run — the graph always starts at the model |
tools -> model | Unconditional | Every time a tool node finishes, so the model can read the result |
approve -> END | Unconditional | Whenever the approval node finishes — but it is only reached on the refund path |
model -> tools, model -> approve, model -> END | Conditional | Only when route_after_model returns that label for the last message |
refund_order | Gated | Only inside the branch resumed with an approval — the write is unreachable before the decision |
The snippet below builds both scenarios as one graph. A fake model scripts both conversations, so the run is deterministic and needs no API key; the routing, the interrupt, the checkpoint and the reducer are the real runtime. Notice that the write tool is not in the ToolNode at all — it can only run inside the branch that a human approved.
from typing import Annotated, Literal, TypedDict
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, ToolCall
from langchain_core.tools import tool
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode
from langgraph.types import Command, interrupt
ORDERS = {"A17": "shipped, arriving Thursday"}
@tool
def lookup_order(order_id: str) -> str:
"""Read-only: return an order's delivery status."""
return ORDERS.get(order_id, "unknown order")
@tool
def refund_order(order_id: str) -> str:
"""Write: queue a refund. Only ever called after an approval."""
return f"refund queued for {order_id}"
class TraceState(TypedDict):
order_id: str
messages: Annotated[list, add_messages]
def route_after_model(state: TraceState) -> Literal["tools", "approve", "end"]:
"""The guardrail: read-only calls go to ToolNode, writes go to approval."""
last = state["messages"][-1]
if not last.tool_calls:
return "end"
if any(call["name"] == "refund_order" for call in last.tool_calls):
return "approve"
return "tools"
def approve_refund(state: TraceState) -> dict:
decision = interrupt(
{
"action": "refund_order",
"order_id": state["order_id"],
"question": "Refund this order?",
}
)
if decision != "approved":
return {"messages": [AIMessage(content="Refund declined; nothing written.")]}
result = refund_order.invoke({"order_id": state["order_id"]})
return {"messages": [AIMessage(content=str(result))]}
def build_graph(model):
def call_model(state: TraceState) -> dict:
return {"messages": [model.invoke(state["messages"])]}
builder = StateGraph(TraceState)
builder.add_node("model", call_model)
builder.add_node("tools", ToolNode([lookup_order]))
builder.add_node("approve", approve_refund)
builder.add_edge(START, "model")
builder.add_conditional_edges(
"model",
route_after_model,
{"tools": "tools", "approve": "approve", "end": END},
)
builder.add_edge("tools", "model")
builder.add_edge("approve", END)
return builder.compile(checkpointer=InMemorySaver())
lookup_model = GenericFakeChatModel(
messages=iter(
[
AIMessage(
content="",
tool_calls=[
ToolCall(
name="lookup_order",
args={"order_id": "A17"},
id="call_lookup",
)
],
),
AIMessage(content="Order A17 shipped and arrives Thursday."),
]
)
)
lookup_graph = build_graph(lookup_model)
lookup = lookup_graph.invoke(
{"order_id": "A17", "messages": [HumanMessage("Where is order A17?")]},
{"configurable": {"thread_id": "trace-lookup-A17"}},
)
print([message.type for message in lookup["messages"]])
refund_model = GenericFakeChatModel(
messages=iter(
[
AIMessage(
content="",
tool_calls=[
ToolCall(
name="refund_order",
args={"order_id": "A17"},
id="call_refund",
)
],
),
]
)
)
refund_graph = build_graph(refund_model)
config = {"configurable": {"thread_id": "trace-refund-A17"}}
paused = refund_graph.invoke(
{"order_id": "A17", "messages": [HumanMessage("Refund order A17.")]},
config,
)
print("__interrupt__" in paused)
print(refund_graph.get_state(config).next)
resumed = refund_graph.invoke(Command(resume="approved"), config)
print(resumed["messages"][-1].content)When a request misbehaves in production, walk its trace in this order. The order matters: each question narrows the one after it.
tools for a read, approve for a write, end when the model already answered. The last AIMessage is the evidence.ToolMessage in messages is proof of execution, and its content is what every later step saw.__interrupt__ entry means a checkpointed pause, not an error. Resuming needs the same thread_id and a validated decision.END returns whatever the last node merged; read the fields you rely on rather than the model's prose alone.Key takeaways
Two requests share one graph and diverge at the router: read paths go to tools, write paths go to an approval gate.
An unconditional edge always fires when its source node completes; a conditional edge fires only when the router returns its label.
interrupt() pauses the refund path with the exact proposed action; Command(resume=...) on the same thread re-runs the node with the human's decision.
Keep the write tool out of the read-only ToolNode: reachable only through the approved branch, it cannot run by accident.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.