How to Integrate LangGraph for payments with LangSmith for multi-agent systems
Combining LangGraph for payments with LangSmith gives you a clean way to build payment-aware multi-agent systems that are observable end to end. The practical win is simple: one agent can reason about payment flows, another can execute them, and LangSmith gives you traces, metadata, and failure visibility across the whole graph.
For fintech, insurance billing, or subscription ops, this matters because payment workflows are rarely single-step. You need routing, approvals, retries, audit trails, and traceability when something goes wrong.
Prerequisites
- •Python 3.10+
- •
langgraphinstalled - •
langsmithinstalled - •Access to a supported payments backend or sandbox
- •A LangSmith API key
- •Environment variables configured:
- •
LANGSMITH_API_KEY - •
LANGSMITH_TRACING=true - •
LANGSMITH_PROJECT=<your-project-name>
- •
- •If you’re using a payment provider like Stripe:
- •
STRIPE_API_KEY
- •
Install the packages:
pip install langgraph langsmith langchain-openai stripe
Integration Steps
- •Set up LangSmith tracing first.
LangSmith needs to be initialized before your graph runs so every node execution is captured. In production, I keep tracing enabled only for non-local environments or behind a feature flag.
import os
from langsmith import Client
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_PROJECT"] = "payments-multi-agent"
client = Client()
run = client.create_run(
name="payment-orchestration-bootstrap",
run_type="chain",
inputs={"status": "starting"},
project_name=os.environ["LANGSMITH_PROJECT"],
)
print(run.id)
- •Define your payment and policy agents in LangGraph.
A common pattern is to separate intent detection from execution. One agent decides whether the request is safe and complete; another agent handles the actual payment call.
from typing import TypedDict, Annotated
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
class PaymentState(TypedDict):
messages: Annotated[list, add_messages]
amount: float
currency: str
approved: bool
payment_id: str | None
def policy_agent(state: PaymentState):
# Replace with an LLM call or rules engine.
amount = state["amount"]
approved = amount <= 1000.0
return {"approved": approved}
def payment_agent(state: PaymentState):
if not state["approved"]:
return {"payment_id": None}
# Replace with real provider SDK call.
payment_id = f"pay_{state['currency'].lower()}_{int(state['amount'] * 100)}"
return {"payment_id": payment_id}
graph = StateGraph(PaymentState)
graph.add_node("policy_agent", policy_agent)
graph.add_node("payment_agent", payment_agent)
graph.add_edge(START, "policy_agent")
graph.add_edge("policy_agent", "payment_agent")
graph.add_edge("payment_agent", END)
app = graph.compile()
- •Attach LangSmith tracing metadata to each run.
This is where the integration becomes useful. You want every execution to carry business context like tenant ID, customer ID, payment method, and workflow type. That makes debugging agent decisions much easier in LangSmith.
from langsmith import traceable
@traceable(name="multi-agent-payment-workflow")
def run_payment_workflow(amount: float, currency: str):
initial_state = {
"messages": [],
"amount": amount,
"currency": currency,
"approved": False,
"payment_id": None,
}
result = app.invoke(
initial_state,
config={
"metadata": {
"workflow": "payments",
"tenant_id": "acme-finance",
"currency": currency,
}
},
)
return result
result = run_payment_workflow(250.0, "USD")
print(result)
- •Wire a real payment provider into the execution node.
LangGraph handles orchestration; your node should call the provider SDK directly. For Stripe-style flows, create the charge or payment intent inside the node and return the provider reference so LangSmith captures it in the trace output.
import os
import stripe
stripe.api_key = os.environ["STRIPE_API_KEY"]
def stripe_payment_agent(state: PaymentState):
if not state["approved"]:
return {"payment_id": None}
intent = stripe.PaymentIntent.create(
amount=int(state["amount"] * 100),
currency=state["currency"].lower(),
automatic_payment_methods={"enabled": True},
metadata={
"workflow": "payments",
"source": "langgraph",
},
)
return {"payment_id": intent["id"]}
Swap payment_agent in your graph for stripe_payment_agent, then recompile:
graph = StateGraph(PaymentState)
graph.add_node("policy_agent", policy_agent)
graph.add_node("payment_agent", stripe_payment_agent)
graph.add_edge(START, "policy_agent")
graph.add_edge("policy_agent", "payment_agent")
graph.add_edge("payment_agent", END)
app = graph.compile()
- •Add a supervisor pattern for multi-agent routing.
If you have more than two agents, use a router node that decides which specialist should handle the next step. This is where LangGraph shines for multi-agent systems because each node stays small and testable.
def router(state: PaymentState):
if state["amount"] > 1000:
return {"next_step": "manual_review"}
return {"next_step": "payment_agent"}
def manual_review(state: PaymentState):
return {"approved": False}
class RoutedState(TypedDict):
messages: Annotated[list, add_messages]
amount: float
currency: str
approved: bool
payment_id: str | None
next_step: str
workflow = StateGraph(RoutedState)
workflow.add_node("router", router)
workflow.add_node("manual_review", manual_review)
workflow.add_node("payment_agent", stripe_payment_agent)
workflow.set_entry_point("router")
workflow.add_conditional_edges(
"router",
lambda state: state["next_step"],
{
"manual_review": "manual_review",
"payment_agent": "payment_agent",
},
)
workflow.add_edge("manual_review", END)
workflow.add_edge("payment_agent", END)
routed_app = workflow.compile()
Testing the Integration
Run a small smoke test against the compiled graph and confirm that LangSmith receives a trace with metadata and node-level execution.
test_result = run_payment_workflow(125.0, "USD")
print(test_result)
assert test_result["approved"] is True
assert test_result["payment_id"] is not None
print("integration ok")
Expected output:
{'messages': [], 'amount': 125.0, 'currency': 'USD', 'approved': True, 'payment_id': 'pay_usd_12500'}
integration ok
In LangSmith, you should see:
- •A top-level run named
multi-agent-payment-workflow - •Metadata for
workflow,tenant_id, andcurrency - •Child spans for
policy_agentandpayment_agent - •The final payment provider ID attached to the trace
Real-World Use Cases
- •
Payment approval workflows
- •One agent validates limits and fraud rules.
- •Another agent executes the charge.
- •LangSmith gives compliance teams an audit trail of every decision.
- •
Insurance premium collection
- •A policy agent checks customer status.
- •A billing agent retries failed payments.
- •A supervisor agent escalates to manual review when needed.
- •
Marketplace payout orchestration
- •One agent calculates split payouts.
- •Another agent triggers transfers.
- •LangSmith helps you debug failures across seller accounts and payout routes.
If you’re building financial agents that move money or trigger billing actions, don’t treat observability as an afterthought. Use LangGraph to structure the workflow and LangSmith to prove what happened at each step.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
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