How to Integrate LangGraph for lending with Kubernetes for AI agents

By Cyprian AaronsUpdated 2026-04-21
langgraph-for-lendingkubernetesai-agents

LangGraph gives you the orchestration layer for lending workflows: application intake, credit checks, policy rules, underwriting, and exception handling. Kubernetes gives you the runtime layer to scale those agent workflows across pods, isolate workloads, and keep them running under load.

Put together, you get an AI lending system that can route cases, recover from failures, and scale per borrower volume without rewriting the workflow logic.

Prerequisites

  • Python 3.10+
  • Access to a Kubernetes cluster
    • kubectl configured
    • namespace created for your agent workloads
  • A LangGraph-compatible lending workflow project
  • Installed Python packages:
    • langgraph
    • kubernetes
    • pydantic
    • requests
  • A Kubernetes service account with permissions to:
    • create deployments
    • create services
    • read pod status
  • Your lending agent graph already defined or ready to define

Integration Steps

  1. Define the lending workflow in LangGraph

Start by modeling the lending process as a graph. Keep each node focused on one responsibility: intake, validation, underwriting, and decisioning.

from typing import TypedDict, Annotated
from langgraph.graph import StateGraph, START, END

class LendingState(TypedDict):
    applicant_id: str
    income: float
    debt: float
    score: int
    decision: str

def intake(state: LendingState):
    return state

def validate(state: LendingState):
    if state["income"] <= 0:
        return {"decision": "reject_invalid_income"}
    return state

def underwrite(state: LendingState):
    dti = state["debt"] / state["income"]
    score = state["score"]
    if dti < 0.4 and score >= 700:
        return {"decision": "approve"}
    if score >= 650:
        return {"decision": "manual_review"}
    return {"decision": "reject"}

graph = StateGraph(LendingState)
graph.add_node("intake", intake)
graph.add_node("validate", validate)
graph.add_node("underwrite", underwrite)

graph.add_edge(START, "intake")
graph.add_edge("intake", "validate")
graph.add_edge("validate", "underwrite")
graph.add_edge("underwrite", END)

app = graph.compile()
  1. Wrap the graph in a service entrypoint

Kubernetes should run your graph as a containerized API or worker. A small FastAPI app is enough for most lending systems.

from fastapi import FastAPI
from pydantic import BaseModel
from langgraph.graph import StateGraph

app_api = FastAPI()

class LendingRequest(BaseModel):
    applicant_id: str
    income: float
    debt: float
    score: int

@app_api.post("/evaluate")
def evaluate(req: LendingRequest):
    result = app.invoke(req.model_dump())
    return result

This is the point where your LangGraph workflow becomes deployable infrastructure. Your Kubernetes pods can now run the same decision logic consistently across environments.

  1. Deploy the agent service to Kubernetes using the Python client

Use the Kubernetes SDK to create a deployment and service from Python. This is useful when your orchestration platform needs to spin up lending workers dynamically.

from kubernetes import client, config

config.load_kube_config()

apps_v1 = client.AppsV1Api()
core_v1 = client.CoreV1Api()

deployment = client.V1Deployment(
    metadata=client.V1ObjectMeta(name="lending-agent"),
    spec=client.V1DeploymentSpec(
        replicas=2,
        selector=client.V1LabelSelector(match_labels={"app": "lending-agent"}),
        template=client.V1PodTemplateSpec(
            metadata=client.V1ObjectMeta(labels={"app": "lending-agent"}),
            spec=client.V1PodSpec(containers=[
                client.V1Container(
                    name="agent",
                    image="your-registry/lending-agent:latest",
                    ports=[client.V1ContainerPort(container_port=8000)],
                )
            ])
        )
    )
)

apps_v1.create_namespaced_deployment(namespace="ai-agents", body=deployment)

And expose it with a service:

service = client.V1Service(
    metadata=client.V1ObjectMeta(name="lending-agent-svc"),
    spec=client.V1ServiceSpec(
        selector={"app": "lending-agent"},
        ports=[client.V1ServicePort(port=80, target_port=8000)],
        type="ClusterIP"
    )
)

core_v1.create_namespaced_service(namespace="ai-agents", body=service)
  1. Call the deployed graph from another agent or workflow

Once Kubernetes exposes your service, other systems can call it over HTTP. This is how you connect upstream intake agents or downstream compliance checks.

import requests

payload = {
    "applicant_id": "A-10021",
    "income": 120000,
    "debt": 35000,
    "score": 721,
}

resp = requests.post(
    "http://lending-agent-svc.ai-agents.svc.cluster.local/evaluate",
    json=payload,
    timeout=10,
)

print(resp.json())

If you want stronger control inside the graph itself, use LangGraph’s conditional edges to route approvals and manual review paths.

from langgraph.graph import StateGraph, START, END

def route(state):
    return state["decision"]

workflow = StateGraph(LendingState)
workflow.add_node("underwrite", underwrite)
workflow.add_conditional_edges(
    "underwrite",
    route,
    {
        "approve": END,
        "manual_review": END,
        "reject": END,
        "reject_invalid_income": END,
    }
)
  1. Add scaling and failure handling in Kubernetes

For lending traffic spikes, use Kubernetes primitives instead of changing your graph logic. Horizontal Pod Autoscaler keeps throughput stable when applications surge.

from kubernetes import client, config

config.load_kube_config()
autoscaling_v2 = client.AutoscalingV2Api()

hpa = client.V2HorizontalPodAutoscaler(
    metadata=client.V2ObjectMeta(name="lending-agent-hpa"),
    spec=client.V2HorizontalPodAutoscalerSpec(
        scale_target_ref=client.V2CrossVersionObjectReference(
            api_version="apps/v1",
            kind="Deployment",
            name="lending-agent"
        ),
        min_replicas=2,
        max_replicas=10,
        metrics=[
            client.V2MetricSpec(
                type="Resource",
                resource=client.V2ResourceMetricSource(
                    name="cpu",
                    target=client.V2MetricTarget(type="Utilization", average_utilization=70)
                )
            )
        ]
    )
)

autoscaling_v2.create_namespaced_horizontal_pod_autoscaler(
    namespace="ai-agents",
    body=hpa,
)

Testing the Integration

Run a real request against the service and confirm both layers are working: LangGraph returns a decision, and Kubernetes keeps the pod reachable.

import requests

test_payload = {
    "applicant_id": "T-90001",
    "income": 95000,
    "debt": 28000,
    "score": 690,
}

response = requests.post(
    "http://localhost:8000/evaluate",
    json=test_payload,
)

print(response.status_code)
print(response.json())

Expected output:

200
{'applicant_id': 'T-90001', 'income': 95000.0, 'debt': 28000.0, 'score': 690, 'decision': 'manual_review'}

If you want cluster-level verification:

kubectl get pods -n ai-agents
kubectl get svc -n ai-agents
kubectl logs deploy/lending-agent -n ai-agents

Real-World Use Cases

  • Loan pre-screening at scale

    • Run borrower intake through LangGraph nodes while Kubernetes handles burst traffic from web forms and partner APIs.
  • Manual review routing

    • Send borderline applications to human underwriters when LangGraph flags uncertainty or policy exceptions.
  • Policy-driven portfolio monitoring

    • Trigger re-evaluation graphs for delinquency risk, limit changes, or covenant breaches across many tenants or business units.

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