How to Integrate LangGraph for retail banking with LangSmith for AI agents

By Cyprian AaronsUpdated 2026-04-22
langgraph-for-retail-bankinglangsmithai-agents

Combining LangGraph for retail banking with LangSmith gives you a practical way to build agent workflows that are traceable, testable, and safe enough for financial operations. In retail banking, that usually means routing customer requests through controlled decision paths while keeping full visibility into every model call, tool call, and failure point.

This matters when your agent handles things like balance inquiries, card disputes, loan pre-qualification, or KYC follow-ups. LangGraph gives you the workflow control; LangSmith gives you the observability to debug, evaluate, and monitor it in production.

Prerequisites

  • Python 3.10+
  • langgraph
  • langchain
  • langsmith
  • An LLM provider key, such as OPENAI_API_KEY
  • A LangSmith account and project
  • Environment variables configured:
    • LANGSMITH_API_KEY
    • LANGSMITH_TRACING=true
    • LANGSMITH_PROJECT=retail-banking-agents

Install the packages:

pip install langgraph langchain langsmith langchain-openai

Integration Steps

  1. Set up LangSmith tracing first.

LangSmith works best when tracing is enabled before you build the graph. This lets every node execution show up in your project automatically.

import os

os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_PROJECT"] = "retail-banking-agents"
os.environ["LANGSMITH_API_KEY"] = "lsv2-your-key-here"
os.environ["OPENAI_API_KEY"] = "sk-your-openai-key"
  1. Define a retail banking state model for your LangGraph workflow.

Use a typed state object so your nodes pass structured data instead of loose dictionaries. For banking agents, this keeps customer intent, risk flags, and resolution status explicit.

from typing import TypedDict, Literal

class BankingState(TypedDict):
    customer_id: str
    intent: str
    risk_level: Literal["low", "medium", "high"]
    response: str
    approved: bool
  1. Build the LangGraph workflow with node functions.

This example routes a customer request through classification and decision nodes. In a real retail banking system, this is where you would insert policy checks, retrieval from internal systems, or human escalation.

from langgraph.graph import StateGraph, END

def classify_intent(state: BankingState) -> BankingState:
    text = state["intent"].lower()

    if "balance" in text or "statement" in text:
        state["risk_level"] = "low"
        state["response"] = "I can help with account information."
    elif "card" in text or "fraud" in text:
        state["risk_level"] = "high"
        state["response"] = "I’m escalating this to the fraud workflow."
    else:
        state["risk_level"] = "medium"
        state["response"] = "I need more details before proceeding."

    return state

def decide_next_step(state: BankingState) -> BankingState:
    state["approved"] = state["risk_level"] != "high"
    return state

graph = StateGraph(BankingState)
graph.add_node("classify_intent", classify_intent)
graph.add_node("decide_next_step", decide_next_step)

graph.set_entry_point("classify_intent")
graph.add_edge("classify_intent", "decide_next_step")
graph.add_edge("decide_next_step", END)

app = graph.compile()
  1. Attach LangSmith tracing to the graph run.

LangGraph runs are traced through LangSmith once tracing is enabled in the environment. If you want explicit control over runs and metadata, use LangSmith’s client directly to log test cases or custom traces.

from langsmith import Client

client = Client()

result = app.invoke({
    "customer_id": "cust_1029",
    "intent": "I need my account balance",
    "risk_level": "low",
    "response": "",
    "approved": False,
})

client.create_dataset(
    dataset_name="retail-banking-intents",
    description="Customer intents for agent evaluation"
)

print(result)
  1. Add an LLM-backed node if you want natural language responses.

In production banking flows, the graph often needs an LLM only after policy routing is complete. That keeps the model inside guardrails while still letting it generate user-facing responses.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)

def generate_reply(state: BankingState) -> BankingState:
    prompt = f"""
You are a retail banking assistant.
Intent: {state['intent']}
Risk level: {state['risk_level']}
Approved: {state['approved']}
Write a short customer-facing reply.
"""
    msg = llm.invoke(prompt)
    state["response"] = msg.content
    return state

graph2 = StateGraph(BankingState)
graph2.add_node("classify_intent", classify_intent)
graph2.add_node("decide_next_step", decide_next_step)
graph2.add_node("generate_reply", generate_reply)

graph2.set_entry_point("classify_intent")
graph2.add_edge("classify_intent", "decide_next_step")
graph2.add_edge("decide_next_step", "generate_reply")
graph2.add_edge("generate_reply", END)

app2 = graph2.compile()

Testing the Integration

Run a single invocation and confirm two things:

  • The graph returns the expected banking decision
  • The run appears in your LangSmith project with node-level traces
test_input = {
    "customer_id": "cust_2048",
    "intent": "I want my card replaced because it was stolen",
    "risk_level": "low",
    "response": "",
    "approved": False,
}

output = app.invoke(test_input)
print(output)

Expected output:

{
  'customer_id': 'cust_2048',
  'intent': 'I want my card replaced because it was stolen',
  'risk_level': 'high',
  'response': 'I’m escalating this to the fraud workflow.',
  'approved': False
}

If LangSmith is configured correctly, you should also see a trace in your retail-banking-agents project showing:

  • Graph entry run
  • classify_intent node execution
  • decide_next_step node execution
  • Input/output payloads for each step

Real-World Use Cases

  • Card dispute triage

    • Route fraud-related requests to high-priority escalation paths.
    • Keep a full audit trail of how the agent decided to escalate.
  • Loan pre-screening

    • Use LangGraph to separate eligibility checks from explanation generation.
    • Use LangSmith to evaluate whether the agent follows policy on rejected applicants.
  • Customer service automation

    • Handle balance inquiries, fee explanations, and statement requests with controlled branching.
    • Review traces in LangSmith when customers report incorrect responses or hallucinations.

Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides