How to Integrate LangGraph for payments with Kubernetes for multi-agent systems
Combining LangGraph for payments with Kubernetes gives you a clean way to run payment-aware agent workflows at scale. LangGraph handles the orchestration logic for multi-agent payment decisions, while Kubernetes gives you isolation, scaling, and deployment control for the workers executing those workflows.
This is the pattern you want when one agent checks fraud rules, another validates invoices, and a third triggers payment execution. You get deterministic graph execution on top of infrastructure that can survive load spikes, retries, and rolling updates.
Prerequisites
- •Python 3.10+
- •A Kubernetes cluster:
- •local:
kind,minikube, ork3d - •production: EKS, GKE, AKS, or on-prem
- •local:
- •
kubectlconfigured against your cluster - •A payment provider test environment or sandbox credentials
- •LangGraph installed:
- •
pip install langgraph langchain-openai
- •
- •Kubernetes Python client installed:
- •
pip install kubernetes
- •
- •Access to a container registry for your agent image
- •A secrets strategy for payment credentials:
- •Kubernetes Secrets, External Secrets Operator, or Vault
Integration Steps
- •Define the payment workflow in LangGraph
Start by modeling the payment flow as a graph. Each node represents an agent responsibility: validate request, check risk, execute payment, then persist status.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class PaymentState(TypedDict):
invoice_id: str
amount: float
currency: str
risk_score: int
status: str
def validate_payment(state: PaymentState) -> PaymentState:
if state["amount"] <= 0:
return {**state, "status": "rejected"}
return {**state, "status": "validated"}
def risk_check(state: PaymentState) -> PaymentState:
score = 20 if state["amount"] < 1000 else 80
return {**state, "risk_score": score}
def execute_payment(state: PaymentState) -> PaymentState:
if state["risk_score"] > 50:
return {**state, "status": "manual_review"}
return {**state, "status": "paid"}
graph = StateGraph(PaymentState)
graph.add_node("validate_payment", validate_payment)
graph.add_node("risk_check", risk_check)
graph.add_node("execute_payment", execute_payment)
graph.add_edge(START, "validate_payment")
graph.add_edge("validate_payment", "risk_check")
graph.add_edge("risk_check", "execute_payment")
graph.add_edge("execute_payment", END)
payment_app = graph.compile()
- •Add a Kubernetes-backed worker entrypoint
Your agents should run as pods. The pod can receive payment jobs from an API gateway or queue consumer and then invoke the compiled LangGraph workflow.
import os
from kubernetes import client, config
def load_kube():
if os.getenv("KUBERNETES_SERVICE_HOST"):
config.load_incluster_config()
else:
config.load_kube_config()
def submit_job(job_name: str):
load_kube()
batch_v1 = client.BatchV1Api()
job = client.V1Job(
metadata=client.V1ObjectMeta(name=job_name),
spec=client.V1JobSpec(
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "payment-agent"}),
spec=client.V1PodSpec(
restart_policy="Never",
containers=[
client.V1Container(
name="agent",
image="your-registry/payment-agent:latest",
env=[
client.V1EnvVar(name="PAYMENT_ENV", value="sandbox")
],
)
],
),
),
backoff_limit=2,
),
)
batch_v1.create_namespaced_job(namespace="default", body=job)
- •Wire multi-agent coordination through Kubernetes services
In production, one pod should not do everything. Run separate agents for fraud review, compliance checks, and payment execution behind internal services. The orchestrator can call them over HTTP or gRPC from inside the cluster.
import requests
def fraud_agent_call(payload: dict) -> dict:
resp = requests.post(
"http://fraud-agent.default.svc.cluster.local/check",
json=payload,
timeout=10,
)
resp.raise_for_status()
return resp.json()
def compliance_agent_call(payload: dict) -> dict:
resp = requests.post(
"http://compliance-agent.default.svc.cluster.local/check",
json=payload,
timeout=10,
)
resp.raise_for_status()
return resp.json()
def orchestrate_payment(state):
fraud_result = fraud_agent_call(state)
compliance_result = compliance_agent_call(state)
if fraud_result["approved"] and compliance_result["approved"]:
return payment_app.invoke({**state})
return {**state, "status": "blocked"}
- •Run LangGraph inside the Kubernetes pod
Your container entrypoint should read input from an event source or request payload and invoke the graph. Keep it stateless; store durable results in Postgres or your ledger service.
import json
import os
def main():
payload = json.loads(os.environ["PAYMENT_REQUEST"])
result = payment_app.invoke(payload)
print(json.dumps(result))
if __name__ == "__main__":
main()
A practical deployment uses environment variables for non-sensitive config and Kubernetes Secrets for credentials.
from kubernetes import client
secret = client.V1Secret(
metadata=client.V1ObjectMeta(name="payment-secrets"),
string_data={
"PAYMENT_API_KEY": "sandbox-key-123",
"PAYMENT_API_SECRET": "sandbox-secret-abc",
},
)
- •Deploy and scale the agent workload
Use a Deployment for always-on agents and a Job for one-off payment tasks. For multi-agent systems handling bursts of invoices or claims payouts, Jobs are usually better because each workflow run is isolated.
from kubernetes import client
deployment = client.V1Deployment(
metadata=client.V1ObjectMeta(name="payment-agent"),
spec=client.V1DeploymentSpec(
replicas=3,
selector=client.V1LabelSelector(match_labels={"app": "payment-agent"}),
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "payment-agent"}),
spec=client.V1PodSpec(
containers=[
client.V1Container(
name="agent",
image="your-registry/payment-agent:latest",
ports=[client.V1ContainerPort(container_port=8080)],
)
]
),
),
),
)
Testing the Integration
Run a local invocation first to confirm the graph works before pushing it into Kubernetes.
test_input = {
"invoice_id": "inv_10001",
"amount": 250.0,
"currency": "USD",
"risk_score": 0,
"status": ""
}
result = payment_app.invoke(test_input)
print(result)
Expected output:
{
'invoice_id': 'inv_10001',
'amount': 250.0,
'currency': 'USD',
'risk_score': 20,
'status': 'paid'
}
Then verify your pod is healthy:
kubectl get pods -l app=payment-agent
kubectl logs deploy/payment-agent
Real-World Use Cases
- •
Invoice-to-payment automation
- •One agent extracts invoice data.
- •Another validates policy limits.
- •LangGraph routes approved payments to execution while Kubernetes scales workers during month-end spikes.
- •
Claims payout processing
- •A triage agent checks claim completeness.
- •A fraud agent scores suspicious claims.
- •A payout agent executes approved disbursements with audit logs per workflow run.
- •
Treasury operations
- •Agents reconcile balances across systems.
- •A policy agent enforces approval thresholds.
- •Kubernetes runs isolated jobs for each treasury action so failures don’t cascade across tenants.
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