Generative AI and Agentic AILangChain 1.4 · LangGraph 1.2 · Python 3.12 or 3.13
Dashboard
0%

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 customer support harness as a graph. START goes to the guardrail node, which ends the run when it blocks a request. Otherwise the router sends the request to the technical, billing or general agent, all three feed the reviewer, and the reviewer ends the run.

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.

The state of the support harness · from the Loop and Harness Engineering Crash Course video · 3:15:23 to 3:17:27

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.

python
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.

python
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.

python
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"]
python
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.

python
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 update

The 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.

python
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.

python
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"]}
Connecting the nodes into a graph · from the Loop and Harness Engineering Crash Course video · 3:23:41 to 3:26:10

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.

python
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.

ExampleAPI keyLive run on Groq, openai/gpt-oss-20b
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)

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 partWhere it lives in the graph
GuardrailThe guardrail node and the conditional edge after it
RoutingThe router node: keywords first, a model for ambiguous questions
AgentsThe specialist node, one prompt per route
ValidationThe reviewer node
State and tracingSupportState, 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.
Watch out. The trace here is a list in state. It shows the path of one request, but it is not a tracing system: it keeps no timings, token counts or history across requests. A tracing platform such as Langfuse records those, and the guardrail's phrase list is a first filter, not complete safety.
Try it yourself
  • Add "social security number" to BLOCKED and send a request that contains it.
  • Add "crash" to TECHNICAL and 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.
PreviousGuardrails

Slow is fine. Stopping is the only problem.