Articles / agentslanggraphpython
Build a customer support agent with LangGraph: routing, refunds with human approval, and a routing eval
Build a LangGraph support agent that routes intents, looks up orders, pauses large refunds for human approval, escalates on low confidence, and gets a routing eval.
A support bot that can only talk is a chatbot. A support agent reads the order system, issues refunds and knows when to hand the ticket to a person. The hard part of the second one is not the model call. It is deciding which requests the model may act on alone, which need a human to sign off, and what happens to the conversation while it waits.
This post builds that agent in LangGraph, as a graph you can run on a laptop with no API key. A message is classified into an intent, routed to FAQ retrieval, an order lookup or a refund flow, and sent to a human when the classifier is unsure. Refunds above Rs 2,000 pause the graph with interrupt() until a reviewer approves or rejects them. A checkpointer keeps each conversation's state between turns. At the end, a 15-message labelled set measures routing accuracy at four confidence thresholds.
The architecture questions (scale, cost per ticket, permission tiers, guardrails, rollout) are covered in System design of an AI customer support agent. This post is the code. If LangGraph's state, reducers and checkpoints are new to you, read LangGraph explained from scratch first.
All code ran against langgraph 1.2.24, the current release on PyPI (uploaded 20 November 2026, Python 3.10 or newer), with langchain-core 1.8.4.
Why a router and not one tool-calling loop#
The common tutorial version of this agent is a single model node with tools bound to it and LangGraph's prebuilt tools_condition deciding whether to call a tool. The model picks the tool, the tool runs, the model reads the result and answers. That works for "where is my order", and it is a fine starting point.
It is the wrong shape for refunds. If the refund tool is bound to the model, the rule "refunds above Rs 2,000 need a human" lives in a prompt, and a prompt is a request, not a control. Here the model does one narrow job: label the message and give a confidence. Plain Python decides where the label goes, checks the order status, compares the amount to the threshold and calls interrupt(). Anthropic's Building effective agents describes this pattern as routing: classify the input, then send it to a specialised path, which suits tasks with distinct categories that are better handled separately.
+-----------+
customer message -> | classify | model: intent + confidence + order_id
+-----+-----+
| route() (code, not the model)
+-----------+--------+---------+----------------------+
| | | |
conf < 0.6 intent=faq intent=order_status intent=refund
or "human" | | |
| +---v---+ +-----v------+ +------v-------+
| | faq | |order_lookup| | refund_check |
| +---+---+ +-----+------+ +------+-------+
| no doc | | not delivered -> reply, END
| matched | | <= Rs 2000 | | > Rs 2000
+----v----+ | | | +---v-----------+
|escalate |<-----+ | | |approve_refund |
+----+----+ | | | interrupt() |
| | | +---+-------+---+
| | | yes | | no
| | +---v------v-+ +---v----------+
| | |issue_refund| |refund_denied |
v v +-----+------+ +------+-------+
END END v v
END END
Checkpointer (InMemorySaver) saves state after every step, per thread_id.
Setup#
python3 -m venv .venv
.venv/bin/pip install langgraph
That pulls in langchain-core for the message types. There are four files: model.py, agent.py, demo.py and eval_routing.py.
Step 1: put the model behind an interface#
The graph needs two things from a model: classify a message, and turn facts into a reply. Putting those behind a Protocol keeps provider code out of the graph and lets a scripted fake stand in for the model. The fake below is keyword rules and templates. It is deterministic, so the outputs in this post are reproducible, and its weaknesses are easy to see in the eval later.
# model.py
"""The model sits behind a two-method interface so the graph never imports a provider SDK.
FakeModel is a scripted stand-in: keyword rules for classify(), templates for write().
It lets everything run with no API key and gives the same answer every time.
"""
import re
from typing import Protocol, TypedDict
class Classification(TypedDict):
intent: str # faq | order_status | refund | human | unknown
confidence: float # 0.0 - 1.0
order_id: str | None
class SupportModel(Protocol):
def classify(self, text: str) -> Classification: ...
def write(self, kind: str, facts: dict) -> str: ...
class FakeModel:
def classify(self, text: str) -> Classification:
t = text.lower()
m = re.search(r"\b(\d{4})\b", t)
oid = m.group(1) if m else None
if any(w in t for w in ("human", "real person", "manager", "speak to someone")):
return {"intent": "human", "confidence": 0.95, "order_id": oid}
if any(w in t for w in ("refund", "money back", "charged twice")):
return {"intent": "refund", "confidence": 0.9, "order_id": oid}
if any(w in t for w in ("where is", "track", "status", "not arrived", "late")):
return {"intent": "order_status", "confidence": 0.9 if oid else 0.7, "order_id": oid}
if any(w in t for w in ("how", "policy", "can i", "do you", "what is")):
return {"intent": "faq", "confidence": 0.8, "order_id": oid}
if oid: # an order number with no verb: probably status, but unsure
return {"intent": "order_status", "confidence": 0.55, "order_id": oid}
return {"intent": "unknown", "confidence": 0.3, "order_id": oid}
def write(self, kind: str, facts: dict) -> str:
templates = {
"faq": "{answer} (source: {doc})",
"order": "Order {order_id} is {status}. Expected by {eta}.",
"no_order": "I could not find order {order_id}. Please check the number.",
"need_id": "Which order is this about? Please share the 4-digit order number.",
"refund_done": "Refund of Rs {amount} for order {order_id} is issued (ref {ref}).",
"refund_denied": "A specialist reviewed order {order_id} and could not approve "
"the refund. Ticket {ticket} has the details.",
"not_eligible": "Order {order_id} is {status}, so it cannot be refunded yet.",
"escalated": "I have passed this to a human agent (ticket {ticket}). "
"Reason: {reason}.",
}
return templates[kind].format(**facts)
# A real model goes here instead, for example:
# from langchain.chat_models import init_chat_model
# llm = init_chat_model("<provider>:<model-name>", temperature=0)
# classifier = llm.with_structured_output(Classification)
# class RealModel:
# def classify(self, text): return classifier.invoke(CLASSIFY_PROMPT + text)
# def write(self, kind, facts): return llm.invoke(REPLY_PROMPT.format(kind=kind, facts=facts)).content
The commented block at the bottom is where a real model plugs in. init_chat_model (from the langchain package, a separate install) builds a chat model for any supported provider, and with_structured_output makes it return a dict that matches Classification, so the graph code does not change. A confidence number the model writes into its own output is not a reliable probability. In production, take the confidence from log-probabilities of the label tokens, or from agreement across two or three samples, and tune the threshold on labelled data as shown later.
Step 2: the state#
agent.py starts with fake back-office data and the state schema.
# agent.py
from typing import Annotated, TypedDict
from langchain_core.messages import AIMessage
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.graph.message import add_messages
from langgraph.types import interrupt
from model import FakeModel
MIN_CONFIDENCE = 0.6 # below this, a human takes the ticket
REFUND_APPROVAL_OVER = 2000 # rupees; larger refunds wait for a person
# ---- fake back-office systems -------------------------------------------
ORDERS = {
"1042": {"status": "out for delivery", "eta": "today", "amount": 899},
"1077": {"status": "delivered", "eta": "delivered 18 Nov", "amount": 649},
"2210": {"status": "delivered", "eta": "delivered 15 Nov", "amount": 5499},
"3301": {"status": "processing", "eta": "26 Nov", "amount": 1299},
"2288": {"status": "delivered", "eta": "delivered 12 Nov", "amount": 3199},
}
FAQ = {
"returns": "You can return most items within 10 days of delivery.",
"shipping": "Standard shipping takes 3-5 working days and is free above Rs 499.",
"address": "You can change the delivery address until the order is packed.",
"payment": "We accept UPI, cards and cash on delivery up to Rs 10,000.",
}
REFUNDS: dict[str, dict] = {} # the ledger; keyed by order_id so a retry cannot pay twice
TICKETS: list[dict] = []
model = FakeModel()
class State(TypedDict, total=False):
messages: Annotated[list, add_messages]
intent: str
confidence: float
order_id: str | None
escalation_reason: str
approved: bool | None
def say(text: str) -> dict:
return {"messages": [AIMessage(text)]}
messages uses the add_messages reducer, so a node that returns one message appends it instead of replacing the history. The other fields have no reducer, so each write overwrites the old value. That is what you want for intent and confidence, which describe the current turn. order_id is different on purpose: it is kept across turns so "refund it" can find the order mentioned two messages ago. The Graph API docs cover reducers in detail.
Step 3: classify and route#
# ---- nodes ---------------------------------------------------------------
def classify(state: State) -> dict:
c = model.classify(state["messages"][-1].content)
# A follow-up like "refund it" has no number; reuse the one from earlier turns.
order_id = c["order_id"] or state.get("order_id")
return {"intent": c["intent"], "confidence": c["confidence"],
"order_id": order_id, "approved": None, "escalation_reason": ""}
def route(state: State) -> str:
if state["intent"] == "human" or state["confidence"] < MIN_CONFIDENCE:
return "escalate"
return {"faq": "faq", "order_status": "order_lookup", "refund": "refund_check"}.get(
state["intent"], "escalate")
classify resets the per-turn fields (approved, escalation_reason) so a value from the previous turn cannot leak into this one. route is a plain function used as a conditional edge. Anything the model labels unknown, or labels with low confidence, goes to a person. So does an explicit request for a human, at any confidence.
Step 4: FAQ and order lookup#
def faq(state: State) -> dict:
words = set(state["messages"][-1].content.lower().replace("?", "").split())
keys = {"returns": {"return", "returns"}, "shipping": {"shipping", "delivery", "ship"},
"address": {"address"}, "payment": {"pay", "upi", "card", "cod", "cash"}}
hits = [doc for doc, kw in keys.items() if words & kw]
if not hits:
return {"escalation_reason": "no help-center article matched"}
return say(model.write("faq", {"answer": FAQ[hits[0]], "doc": hits[0]}))
def after_faq(state: State) -> str:
return "escalate" if state.get("escalation_reason") else END
def order_lookup(state: State) -> dict:
oid = state.get("order_id")
if not oid:
return say(model.write("need_id", {}))
order = ORDERS.get(oid)
if not order:
return say(model.write("no_order", {"order_id": oid}))
return say(model.write("order", {"order_id": oid, **order}))
The FAQ node stands in for retrieval with keyword overlap over four articles. In a real build, this is a vector or hybrid search over the help center, and the "no match" branch becomes "top score below a cutoff". The behaviour that matters is the same either way: when nothing relevant is found, the agent escalates instead of answering from the model's general knowledge. That is how a support bot ends up inventing a return policy.
Step 5: the refund flow with an interrupt#
def refund_check(state: State) -> dict:
oid = state.get("order_id")
if not oid:
return say(model.write("need_id", {}))
order = ORDERS.get(oid)
if not order:
return say(model.write("no_order", {"order_id": oid}))
if order["status"] != "delivered":
return say(model.write("not_eligible", {"order_id": oid, "status": order["status"]}))
return {}
def after_refund_check(state: State) -> str:
if isinstance(state["messages"][-1], AIMessage):
return END # refund_check already replied
amount = ORDERS[state["order_id"]]["amount"]
return "approve_refund" if amount > REFUND_APPROVAL_OVER else "issue_refund"
def approve_refund(state: State) -> dict:
# Nothing with side effects above this line: the node reruns from the top on resume.
oid = state["order_id"]
decision = interrupt({"action": "refund", "order_id": oid,
"amount": ORDERS[oid]["amount"],
"customer_said": state["messages"][-1].content})
return {"approved": bool(decision.get("approved"))}
def after_approval(state: State) -> str:
return "issue_refund" if state["approved"] else "refund_denied"
def issue_refund(state: State) -> dict:
oid = state["order_id"]
if oid not in REFUNDS: # idempotent: a replay finds the existing refund
REFUNDS[oid] = {"amount": ORDERS[oid]["amount"], "ref": f"RF-{oid}"}
r = REFUNDS[oid]
return say(model.write("refund_done", {"order_id": oid, "amount": r["amount"], "ref": r["ref"]}))
def refund_denied(state: State) -> dict:
TICKETS.append({"order_id": state["order_id"], "reason": "refund rejected by reviewer"})
return say(model.write("refund_denied", {"order_id": state["order_id"],
"ticket": f"T-{len(TICKETS):03d}"}))
Eligibility is checked in code before any human sees the request, so reviewers only get refunds the policy allows. interrupt(payload) stops the run, the checkpointer saves state, and the caller gets the payload back under __interrupt__. The reviewer's answer arrives later as Command(resume=...) and becomes the return value of interrupt().
Two details come straight from the interrupts docs. First, on resume the node restarts from its first line, not from the interrupt() call. That is why approve_refund does nothing but build the payload, and the payment happens in a separate node after it. Second, interrupts need a checkpointer and a thread ID, and the docs recommend a durable checkpointer in production, because the paused state has to live somewhere while the reviewer decides. issue_refund is also idempotent: the ledger is keyed by order ID, so a retried step cannot pay twice.
Step 6: escalate, then wire the graph#
def escalate(state: State) -> dict:
reason = state.get("escalation_reason") or (
"customer asked for a person" if state["intent"] == "human"
else f"low confidence ({state['confidence']:.2f}) on intent '{state['intent']}'")
TICKETS.append({"order_id": state.get("order_id"), "reason": reason,
"transcript": [m.content for m in state["messages"]]})
return say(model.write("escalated", {"ticket": f"T-{len(TICKETS):03d}", "reason": reason}))
# ---- graph ---------------------------------------------------------------
def build(checkpointer=None):
g = StateGraph(State)
for fn in (classify, faq, order_lookup, refund_check, approve_refund,
issue_refund, refund_denied, escalate):
g.add_node(fn.__name__, fn)
g.add_edge(START, "classify")
g.add_conditional_edges("classify", route,
["faq", "order_lookup", "refund_check", "escalate"])
g.add_conditional_edges("faq", after_faq, ["escalate", END])
g.add_conditional_edges("refund_check", after_refund_check,
["approve_refund", "issue_refund", END])
g.add_conditional_edges("approve_refund", after_approval, ["issue_refund", "refund_denied"])
for n in ("order_lookup", "issue_refund", "refund_denied", "escalate"):
g.add_edge(n, END)
return g.compile(checkpointer=checkpointer or InMemorySaver())
The escalation ticket carries the reason and the full transcript, so the person who picks it up does not ask the customer to repeat everything. The list passed as the third argument to add_conditional_edges names every possible destination, so LangGraph knows the edges without running route and can draw the graph correctly.
InMemorySaver keeps checkpoints in RAM. The persistence docs state that all checkpoints are lost when the process restarts, which here means every paused refund. For anything real, pass a durable saver such as langgraph-checkpoint-postgres or langgraph-checkpoint-sqlite into build().
Run five conversations#
Each conversation gets its own thread_id. The checkpointer keys saved state by that ID, so turns on the same thread share history and turns on different threads never see each other. How chatbots remember conversations explains what that history costs once it grows.
# demo.py
from langchain_core.messages import HumanMessage
from langgraph.types import Command
from agent import REFUNDS, build
app = build()
def turn(thread: str, text: str):
cfg = {"configurable": {"thread_id": thread}}
out = app.invoke({"messages": [HumanMessage(text)]}, cfg)
print(f"[{thread}] customer: {text}")
if "__interrupt__" in out:
print(f"[{thread}] PAUSED, waiting at {app.get_state(cfg).next}:",
out["__interrupt__"][0].value)
else:
print(f"[{thread}] agent ({out['intent']}, {out['confidence']:.2f}): "
f"{out['messages'][-1].content}")
return cfg
def resume(cfg, decision: dict):
out = app.invoke(Command(resume=decision), cfg)
t = cfg["configurable"]["thread_id"]
print(f"[{t}] reviewer: {decision}")
print(f"[{t}] agent: {out['messages'][-1].content}")
print("--- 1. FAQ, then a follow-up that relies on memory")
turn("c1", "How long does shipping take?")
turn("c1", "Where is my order 1042?")
turn("c1", "Can I get a refund for it?")
print("\n--- 2. Small refund, no approval needed")
turn("c2", "I want a refund for order 1077, the size is wrong")
print("\n--- 3. Large refund: pause for a human, then resume")
cfg = turn("c3", "Please refund order 2210, the screen is cracked")
resume(cfg, {"approved": True, "by": "priya@support"})
print("ledger:", REFUNDS)
print("messages kept on thread c3:", len(app.get_state(cfg).values["messages"]))
print("\n--- 4. Low confidence and no FAQ match go to a person")
turn("c4", "1042")
turn("c4", "Do you sell gift cards?")
print("\n--- 5. Large refund the reviewer rejects")
cfg = turn("c5", "Refund 2288 please, I changed my mind")
resume(cfg, {"approved": False, "by": "priya@support"})
Output of .venv/bin/python demo.py:
--- 1. FAQ, then a follow-up that relies on memory
[c1] customer: How long does shipping take?
[c1] agent (faq, 0.80): Standard shipping takes 3-5 working days and is free above Rs 499. (source: shipping)
[c1] customer: Where is my order 1042?
[c1] agent (order_status, 0.90): Order 1042 is out for delivery. Expected by today.
[c1] customer: Can I get a refund for it?
[c1] agent (refund, 0.90): Order 1042 is out for delivery, so it cannot be refunded yet.
--- 2. Small refund, no approval needed
[c2] customer: I want a refund for order 1077, the size is wrong
[c2] agent (refund, 0.90): Refund of Rs 649 for order 1077 is issued (ref RF-1077).
--- 3. Large refund: pause for a human, then resume
[c3] customer: Please refund order 2210, the screen is cracked
[c3] PAUSED, waiting at ('approve_refund',): {'action': 'refund', 'order_id': '2210', 'amount': 5499, 'customer_said': 'Please refund order 2210, the screen is cracked'}
[c3] reviewer: {'approved': True, 'by': 'priya@support'}
[c3] agent: Refund of Rs 5499 for order 2210 is issued (ref RF-2210).
ledger: {'1077': {'amount': 649, 'ref': 'RF-1077'}, '2210': {'amount': 5499, 'ref': 'RF-2210'}}
messages kept on thread c3: 2
--- 4. Low confidence and no FAQ match go to a person
[c4] customer: 1042
[c4] agent (order_status, 0.55): I have passed this to a human agent (ticket T-001). Reason: low confidence (0.55) on intent 'order_status'.
[c4] customer: Do you sell gift cards?
[c4] agent (faq, 0.80): I have passed this to a human agent (ticket T-002). Reason: no help-center article matched.
--- 5. Large refund the reviewer rejects
[c5] customer: Refund 2288 please, I changed my mind
[c5] PAUSED, waiting at ('approve_refund',): {'action': 'refund', 'order_id': '2288', 'amount': 3199, 'customer_said': 'Refund 2288 please, I changed my mind'}
[c5] reviewer: {'approved': False, 'by': 'priya@support'}
[c5] agent: A specialist reviewed order 2288 and could not approve the refund. Ticket T-003 has the details.
Conversation 1 shows the checkpointer at work. The third message has no order number, and the agent still answers about order 1042 because order_id came back from the saved state of the same thread. It also refused the refund for the right reason: the order has not been delivered.
Conversations 2 and 3 are the threshold. Rs 649 went straight through. Rs 5,499 stopped at approve_refund, and get_state(cfg).next reported the paused node. Nothing was paid until the reviewer's Command(resume=...) arrived on the same thread. In a deployed system, the __interrupt__ payload goes to a review queue together with the thread_id, and the reviewer's button calls the resume.
Conversation 4 has two different escalations. A bare "1042" is probably a status question, but at 0.55 the router hands it over rather than guess. "Do you sell gift cards?" was classified confidently as FAQ, but retrieval found nothing, so the FAQ node escalated instead of letting the model make up an answer.
Evaluate the routing#
A wrong route is the most expensive mistake this agent makes, because every later node works on the wrong problem. Routing is also the cheapest part to test, since classify and route are plain functions with no side effects. The script below runs 15 hand-labelled messages through them at four thresholds.
# eval_routing.py
"""Routing eval: does each message reach the right branch? No side effects, no graph run."""
from collections import Counter
import agent
from agent import classify, route
from langchain_core.messages import HumanMessage
LABELLED = [
("How long does shipping take?", "faq"),
("Can I pay with UPI?", "faq"),
("What is your returns policy?", "faq"),
("How do I change my delivery address?", "faq"),
("Where is my order 1042?", "order_lookup"),
("Track 3301 please", "order_lookup"),
("Order 2210 is late, what is going on", "order_lookup"),
("My parcel hasn't come yet", "order_lookup"),
("I want a refund for 1077", "refund_check"),
("I was charged twice for 3301", "refund_check"),
("Give me my money back for 2210", "refund_check"),
("Let me speak to a real person", "escalate"),
("This is the third time I am writing, get me a manager", "escalate"),
("Cancel 3301", "escalate"),
("asdf", "escalate"),
]
def predict(text: str) -> str:
return route(classify({"messages": [HumanMessage(text)]}))
def run(threshold: float):
agent.MIN_CONFIDENCE = threshold
preds = [(t, gold, predict(t)) for t, gold in LABELLED]
correct = sum(g == p for _, g, p in preds)
esc = Counter(p for *_, p in preds)["escalate"]
return correct, esc, [x for x in preds if x[1] != x[2]]
for th in (0.5, 0.6, 0.75, 0.85):
correct, esc, misses = run(th)
print(f"threshold {th:.2f}: accuracy {correct}/{len(LABELLED)} = {correct/len(LABELLED):.0%}, "
f"escalated {esc}/{len(LABELLED)}")
for text, gold, pred in misses:
print(f" miss: {text!r:58} gold={gold:13} pred={pred}")
threshold 0.50: accuracy 13/15 = 87%, escalated 4/15
miss: "My parcel hasn't come yet" gold=order_lookup pred=escalate
miss: 'Cancel 3301' gold=escalate pred=order_lookup
threshold 0.60: accuracy 14/15 = 93%, escalated 5/15
miss: "My parcel hasn't come yet" gold=order_lookup pred=escalate
threshold 0.75: accuracy 14/15 = 93%, escalated 5/15
miss: "My parcel hasn't come yet" gold=order_lookup pred=escalate
threshold 0.85: accuracy 10/15 = 67%, escalated 9/15
miss: 'How long does shipping take?' gold=faq pred=escalate
miss: 'Can I pay with UPI?' gold=faq pred=escalate
miss: 'What is your returns policy?' gold=faq pred=escalate
miss: 'How do I change my delivery address?' gold=faq pred=escalate
miss: "My parcel hasn't come yet" gold=order_lookup pred=escalate
Read the misses, not only the accuracy. The two errors are not equally bad. "My parcel hasn't come yet" escalating is a safe miss: a person answers a question the bot could have handled, at the cost of a human-handled ticket. "Cancel 3301" at threshold 0.5 is an unsafe miss: the agent has no cancel action, so it would report the order status and leave the customer thinking the request was handled. Count the two kinds separately and accept a higher escalation rate to drive unsafe misses to zero.
The sweep also shows the threshold trade-off in numbers. Raising it from 0.6 to 0.85 sent four ordinary FAQ questions to humans, pushing escalations from 5 to 9 out of 15 for no gain. With a real model, the confidence values differ, so rerun this sweep whenever you change the model or the prompt.
Fifteen messages is a smoke test. Each miss changes accuracy by about 7 points, so 87% and 93% here are one message apart. Before trusting the numbers, label a few hundred real tickets per intent from your own logs, include the ugly ones (typos, Hinglish, two questions in one message), and run the same script in CI on every prompt change. Evaluating an AI agent in Python covers end-to-end checks beyond routing, such as whether the final reply was correct and whether the right tool ran.
Failure modes found while building this#
A new message on a paused thread drops the pending approval. A separate test thread asked for the same Rs 5,499 refund, paused at approve_refund, and then received "Hello? Any update?" through a normal invoke. LangGraph started a new run from START, classified the message as unknown and escalated it. Afterwards get_state(cfg).next was empty: the refund that was waiting for review was gone, with no error. The fix is to check app.get_state(cfg).next before handling each customer message. If the thread is paused, store the message and reply "your refund is with a reviewer" without invoking the graph.
Carried-over order_id can point at the wrong order. Reusing the last order number is what made conversation 1 work. It also means "refund my other order" refunds the previous one. In production, confirm the order ID in the reply before any money moves, or clear it when the classifier sees a new topic.
Side effects before interrupt() run twice. The node reruns from the top on resume, as the interrupts docs state. Keep payment, email and ticket creation in nodes after the pause, and make them idempotent anyway, since a crashed step can also be retried. The durable execution docs cover this in more depth.
An in-memory checkpointer loses paused work. Every pending refund vanishes when the process restarts. Use a database-backed saver before any reviewer depends on the queue.
Reviewers approve blind if the payload is thin. The interrupt payload here carries the order, the amount and the customer's words. A real one should add order history and prior refunds for this customer, because the reviewer decides from that payload alone.
Swapping in a real model#
Replace FakeModel() in agent.py with a class that implements the same two methods, using the commented sketch in model.py. Keep temperature=0 for classification, ask for structured output so the graph always gets a valid Classification, and rerun eval_routing.py before anything else. Nothing in the graph, the refund gate or the eval changes. The router, the threshold and the approval step are all code, so a new model can only change the labels it produces, and the eval tells you whether those got better or worse.
Sources#
- langgraph on PyPI (version 1.2.24, Python 3.10+)
- LangGraph Graph API: state, reducers, conditional edges
- LangGraph persistence: checkpointers and threads
- LangGraph interrupts
- LangGraph durable execution
- LangChain models and init_chat_model
- LangChain structured output
- langgraph-checkpoint-postgres on PyPI
- langgraph-checkpoint-sqlite on PyPI
- Anthropic: Building effective agents