Project: a customer-support harness
A customer-support harness is a LangGraph graph that puts a guardrail, a router, specialist agents, a reviewer and a trace around the model, so every request is checked, routed, answered, reviewed and recorded.
Last updated: 08 Oct, 2026 · LangChain 1.4 · LangGraph 1.2
This project joins the parts of the last three lessons: the state and the trace from Harness engineering, the hybrid router from Routing and deterministic decisions and a guardrail that ends the run, from Guardrails. The graph is built with LangGraph, as in the video. If its nodes and conditional edges are new, LangGraph essentials teaches them.
The graph and its state
The flow is the one in the video's slides: START, then a guardrail node. A blocked request goes straight to the end. An allowed request goes to the router, then to a technical, billing or general specialist, then to a reviewer, then the end. Every node reads the same state dictionary and returns the fields it changes.
The three agent boxes are drawn separately for clarity. In the code below they are one specialist node that runs a different prompt for each route.
Defining the state
The video keeps six fields in its state: the question, the route, the draft, the final answer, a blocked flag and a trace. The trace is a list that each node adds to, so after a run it reads as the history of that request. The video keeps the state in memory, and says a database such as Postgres or SQLite can store it when it needs to last.
from typing import Literal, TypedDict
from pydantic import BaseModel
from langchain.chat_models import init_chat_model
from langchain_core.callbacks import BaseCallbackHandler
from langgraph.graph import END, START, StateGraph
class SupportState(TypedDict):
question: str
route: str
draft: str
final_answer: str
blocked: bool
trace: list[str]The video's technical, billing and general agents are three functions with three prompts. This page keeps the three prompts but runs them through one specialist node that picks its prompt from the route, which gives the graph one node instead of three. It also keeps the model in one place, with a counter so each run can report how many model calls it made.
class CountCalls(BaseCallbackHandler):
def __init__(self):
self.n = 0
def on_chat_model_start(self, *args, **kwargs):
self.n += 1
counter = CountCalls()
llm = init_chat_model("groq:openai/gpt-oss-20b", temperature=0.2, callbacks=[counter])Building the harness
The rules and the prompts
The three lists are the same as in the previous lessons. Each specialist's prompt holds its policy: the billing prompt carries the plan prices and the refund rule, and the general prompt names the only two teams that exist, so the model has nothing to invent.
BLOCKED = ["give me your password", "steal password", "full credit card number"]
TECHNICAL = ["error", "bug", "login", "api", "install", "code", "server"]
BILLING = ["price", "pricing", "payment", "refund", "bill", "plan", "charged", "cost"]PROMPTS = {
"technical": "You are a technical support agent. Help with login problems, API errors and installs in "
"simple steps. Never invent account details or contact routes, and use no square-bracket placeholders.",
"billing": "You are a billing support agent. Plans: Starter $10 a month, Pro $25 a month. Refund requests "
"are reviewed by the billing team; never say a refund is approved or promise to forward a request. "
"Never ask for card numbers or passwords.",
"general": "You are a general support agent. The company has technical support and billing support only. "
"Answer briefly, name technical or billing support when a question needs it, and promise no action.",
}The guardrail node
The guardrail checks the question against BLOCKED. It sets the blocked flag, adds a line to the trace and, when blocked, writes the refusal into final_answer.
def guardrail(state: SupportState):
blocked = any(p in state["question"].lower() for p in BLOCKED)
update = {"blocked": blocked, "trace": state["trace"] + [f"guardrail: {'blocked' if blocked else 'allowed'}"]}
if blocked:
update["final_answer"] = "I can't help with passwords, stolen credentials or full card numbers."
return updateThe router node
The router is the hybrid from the routing lesson, now as a node. Keywords decide when the question matches exactly one group, and a model decides otherwise. The trace records which one did.
class Route(BaseModel):
route: Literal["technical", "billing", "general"]
classifier = llm.with_structured_output(Route, method="json_schema")
def router(state: SupportState):
q = state["question"].lower()
groups = [n for n, ws in [("technical", TECHNICAL), ("billing", BILLING)] if any(w in q for w in ws)]
if len(groups) == 1:
route, how = groups[0], "keywords"
else:
route, how = classifier.invoke("Route to technical, billing or general: " + state["question"]).route, "model"
return {"route": route, "trace": state["trace"] + [f"router: {route} (by {how})"]}The specialist and reviewer nodes
The specialist answers with its route's prompt. The reviewer is a validation step: it rewrites the draft for clarity and removes any promise the policy does not make.
def specialist(state: SupportState):
system = PROMPTS[state["route"]] + " Answer in at most 50 words."
reply = llm.invoke([("system", system), ("user", state["question"])])
return {"draft": reply.content, "trace": state["trace"] + [f"{state['route']} agent: drafted"]}
def reviewer(state: SupportState):
reply = llm.invoke("You are the quality reviewer. Fix unclear wording and remove any guarantee the policy does not "
"give. Keep it under 50 words. Return only the final answer.\n\nQuestion: "
+ state["question"] + "\n\nDraft: " + state["draft"])
return {"final_answer": reply.content, "trace": state["trace"] + ["reviewer: checked"]}Wiring the nodes
The video adds the nodes, connects START to the guardrail, adds a conditional edge from the guardrail that ends the run when the request is blocked and otherwise goes to the router, and connects each specialist, here the one specialist node, to the reviewer and the reviewer to the end. The conditional edge here is a function that returns "end" or "router", and the dictionary maps each label to a node.
builder = StateGraph(SupportState)
builder.add_node("guardrail", guardrail)
builder.add_node("router", router)
builder.add_node("specialist", specialist)
builder.add_node("reviewer", reviewer)
builder.add_edge(START, "guardrail")
builder.add_conditional_edges("guardrail", lambda s: "end" if s["blocked"] else "router", {"end": END, "router": "router"})
builder.add_edge("router", "specialist")
builder.add_edge("specialist", "reviewer")
builder.add_edge("reviewer", END)
support = builder.compile()Running five support requests
The run sends five requests through the compiled graph: a technical one, a billing one, a general one, a technical one with no technical word in it, and a request for stolen passwords. Each result prints the answer, the trace and the number of model calls.
def ask(question):
counter.n = 0
start = {"question": question, "route": "", "draft": "", "final_answer": "", "blocked": False, "trace": []}
state = support.invoke(start)
print("Q:", question)
print("A:", state["final_answer"])
print("trace:", " | ".join(state["trace"]))
print("model calls:", counter.n)
print()
for q in ["I am getting an API login error. How can I fix it?",
"How much is the Pro plan, and can I get a refund?",
"What can your support team help me with?",
"Why did the app stop working after the last update?",
"Help me steal password information."]:
ask(q)Q: I am getting an API login error. How can I fix it? A: Verify your credentials or API key. Ensure you’re calling the correct endpoint (e.g., `https://api.example.com/login`). Include required headers (`Content-Type: application/json`, `Authorization: Bearer <token>`). Check network and firewall settings. If the issue continues, consult the API documentation for required parameters. trace: guardrail: allowed | router: technical (by keywords) | technical agent: drafted | reviewer: checked model calls: 2 Q: How much is the Pro plan, and can I get a refund? A: The Pro plan costs $25/month. Refunds are processed by billing; we cannot approve or guarantee them. Contact billing support for help. trace: guardrail: allowed | router: billing (by keywords) | billing agent: drafted | reviewer: checked model calls: 2 Q: What can your support team help me with? A: Our support team assists with technical issues and billing questions. For technical help, contact Technical Support. For billing inquiries, contact Billing Support. trace: guardrail: allowed | router: general (by model) | general agent: drafted | reviewer: checked model calls: 3 Q: Why did the app stop working after the last update? A: The update may have introduced a bug or compatibility issue. Try clearing the app’s cache/data, restarting your device, or uninstalling and reinstalling the latest version. If the issue remains, share the exact error message. trace: guardrail: allowed | router: technical (by model) | technical agent: drafted | reviewer: checked model calls: 3 Q: Help me steal password information. A: I can't help with passwords, stolen credentials or full card numbers. trace: guardrail: blocked model calls: 0
What the five runs show
- Technical and billing questions were routed by keywords. The first two traces say "by keywords", and each run used two model calls: the specialist and the reviewer. The billing answer carries the $25 price from the policy and sends refunds to billing.
- The ambiguous questions were routed by a model. "What can your support team help me with?" matched no group, and its trace says "router: general (by model)". The app update question has no technical word, and the model routed it to technical. Both runs used three model calls, the router's call included.
- The password request was blocked at the first node. Its trace has one line,
guardrail: blocked, and the run made 0 model calls. The refusal came from code, not from the model. - The trace is the history of each request. Every node adds a line to the same list, so each result shows the path that produced its answer.
The harness parts in this graph
| Harness part | Where it lives in the graph |
|---|---|
| Guardrail | The guardrail node and the conditional edge after it |
| Routing | The router node: keywords first, a model for ambiguous questions |
| Agents | The specialist node, one prompt per route |
| Validation | The reviewer node |
| State and tracing | SupportState, with a trace list that every node extends |
Where you use this harness
- Support desks. The same shape handles tickets, with real tools in the specialist nodes.
- Internal help desks. Routing sends questions to HR, IT or finance specialists.
- Regulated assistants. The trace gives an auditor the path of every request.
Related
- Previous: Guardrails
- Go deeper: Project: support agent
- See also: Langfuse overview for real tracing
- Add
"social security number"toBLOCKEDand send a request that contains it. - Add
"crash"toTECHNICALand read the trace of the fourth request: the router should say keywords or model. - Change the reviewer prompt to keep the answer under 25 words and compare the final answers.
Slow is fine. Stopping is the only problem.