Conversational AI (artificial intelligence) · 13 / 22

LangSmith Example

The booking assistant built with LangGraph and traced, tested and monitored in LangSmith: graph, tracing, datasets and release gates.

The same assistant with LangGraph and LangSmith

LangGraph models the conversation as a graph of nodes with explicit state, and LangSmith traces every run, stores datasets and runs evaluations. This build suits teams that want code-level control of the booking flow and a tight test loop. It uses the same tool contracts, gateway and security profile as the other builds.

NodeKindWhat it does
understandModel (fast)Extracts intent and booking slots from the message
askModel (fast)Asks for the next missing slot, one question at a time
policyCodeChecks airport rules, aircraft fit and fee rules from retrieval and the pricing service
quoteToolCalls the pricing and availability tools
holdToolPlaces a time-limited hold
confirmHuman in the loopPauses the graph until the guest explicitly confirms
commitToolCommits with an idempotency key, only after confirm
handoffToolOpens a ticket for the agent desk with the full thread

The graph in code

State is a typed object. The confirm node interrupts the run and resumes only when the guest answers, so there is no path to commit that skips it. This is a sketch; check the current LangGraph API (Application Programming Interface) for exact names.

agent/graph.py · confirm is the only way to commit
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.postgres import PostgresSaver
from langgraph.types import interrupt, Command

class Booking(TypedDict, total=False):
    messages: list
    slots: dict
    quote: dict
    hold_id: str
    confirmed: bool

def confirm(state: Booking) -> Command:
    answer = interrupt({"hold_id": state["hold_id"], "quote": state["quote"]})   # pauses here
    return Command(update={"confirmed": answer == "CONFIRM"},
                   goto="commit" if answer == "CONFIRM" else "ask")

g = StateGraph(Booking)
for name, fn in [("understand", understand), ("ask", ask), ("policy", policy), ("quote", quote),
                 ("hold", hold), ("confirm", confirm), ("commit", commit), ("handoff", handoff)]:
    g.add_node(name, fn)
g.add_edge(START, "understand")
g.add_conditional_edges("understand", route_after_understand, ["ask", "policy", "handoff"])
g.add_edge("policy", "quote")
g.add_edge("quote", "hold")
g.add_edge("hold", "confirm")
g.add_edge("commit", END)

app = g.compile(checkpointer=PostgresSaver.from_conn_string(DB_URL))

Sequence: pause at confirm, resume on reply

LangGraph interrupt and resume with a checkpointer The graph runs to the confirm node, saves its state and pauses. The guest's confirmation arrives later as a new request, the service resumes the thread from the saved state, and only then does the graph commit. Spans for the run go to LangSmith. Guest Service API LangGraph app Checkpointer Booking tools LangSmith request invoke, thread id understand, policy, quote hold_resources hold id save state at confirm interrupt: wait paused, prompt terms and CONFIRM prompt CONFIRM resume, thread id load saved state commit_booking + key BK-20417 trace spans confirmation
LangGraph interrupt and resume with a checkpointer

State survives the pause, so a guest can answer in a minute or in an hour, and a restart of the service does not lose the hold.

Tracing every turn

LangSmith traces each run with nested spans for model calls, tools and retrieval. Metadata ties a trace to a conversation, a channel and the gateway's trace identifier, so a bad answer can be followed from the guest's message to the security scan and the booking call.

service configuration · masking before traces leave your network
# Environment for the service
LANGSMITH_TRACING=true
LANGSMITH_PROJECT=booking-assistant-prod
LANGSMITH_HIDE_INPUTS=true      # keep raw guest text out of the tracing vendor
LANGSMITH_HIDE_OUTPUTS=true     # trace a redacted copy instead (see below)

# In code: attach the identifiers and a redacted view
result = app.invoke(
    {"messages": [("user", message)]},
    config={"configurable": {"thread_id": session_id},
            "metadata": {"channel": channel, "gateway_trace_id": trace_id, "airport": airport},
            "tags": ["prod", "web-chat"]},
)

Raw inputs and outputs are hidden by default, and a redaction step writes a masked copy of the fields needed to debug: slots without tail numbers, tool names, outcomes and scan verdicts. This follows ADR-006.

Datasets and evaluation

A dataset holds conversations with the expected outcome: the slots, the tools that should be called and whether the assistant should refuse or hand off. Offline runs compare the graph against the dataset on every change.

tests/test_eval.py · offline evaluation as a release gate
from langsmith import Client, evaluate

client = Client()

def tool_calls_correct(run, example) -> dict:
    called = [s["name"] for s in run.outputs["tool_calls"]]
    return {"key": "tool_calls_correct", "score": float(called == example.outputs["expected_tools"])}

def no_policy_violation(run, example) -> dict:
    bad = any(c["name"] == "commit_booking" and not c["confirmed"] for c in run.outputs["tool_calls"])
    return {"key": "no_policy_violation", "score": 0.0 if bad else 1.0}

results = evaluate(
    run_conversation,                                # target: runs the graph on one example
    data="booking-eval-v14",
    evaluators=[tool_calls_correct, no_policy_violation, groundedness_judge],
    experiment_prefix="pr-1842",
    max_concurrency=4,
)

Sequence: an offline experiment

A LangSmith offline experiment CI calls evaluate with the target and a dataset. The client loads the examples, runs the graph on each, scores the outputs with the evaluators and stores an experiment, then CI compares it with the baseline and passes or fails the check. CI LangSmith client Dataset Graph under test Evaluators Experiment evaluate(target, data) load booking-eval-v14 examples run each example outputs, tool calls score outputs scores store experiment results vs baseline gate: pass or fail
A LangSmith offline experiment

Every example runs in its own trace, so a failing score links straight to the conversation that caused it.

Release gates and online monitoring

CheckHowThreshold
Tool calls match the expected onesCode evaluator on the datasetAt least 0.95
Zero commits without confirmationCode evaluator on the dataset and on production tracesExactly 1.0, any failure blocks release
Policy answers grounded in a sourceJudge model, spot-checked by peopleAt least 0.9
Adversarial set: injection, lookup, cancellationDataset of attacks with expected refusalsAll refused or handed off
Cost per conversationToken and cost metadata on tracesWithin 10% of the last release
Drift in productionOnline evaluators on sampled traces, with alertsAlert on a drop of 5 points

The improvement loop

  1. Sample

    Online evaluators and thumbs-down feedback flag conversations for review.

  2. Review

    An annotation queue puts flagged traces in front of a support lead, who marks what the assistant should have done.

  3. Add to the dataset

    Reviewed traces become new dataset examples, after redaction.

  4. Fix and compare

    Change the prompt, policy or tool, run the experiment and compare against the baseline on the same dataset.

  5. Release

    The gate passes, the new prompt version is promoted and the online evaluators watch the result.

Build this for your business

This example is a booking assistant for a ground-handling network, but the same pattern, a governed gateway, runtime security, grounded knowledge, deterministic commits and measured quality, fits any customer-facing assistant that takes actions. We can scope a pilot on your own systems.

Book a discovery call