How to Integrate LangGraph for lending with Redis for multi-agent systems

By Cyprian AaronsUpdated 2026-04-21
langgraph-for-lendingredismulti-agent-systems

Combining LangGraph for lending with Redis gives you a clean way to build loan workflows that need both stateful orchestration and fast shared memory across agents. LangGraph handles the lending decision flow, retries, branching, and human review; Redis gives your multi-agent system a low-latency store for conversation state, task locks, checkpoints, and coordination between specialist agents.

Prerequisites

  • Python 3.10+
  • A running Redis instance
    • Local: redis-server
    • Or managed Redis like AWS ElastiCache / Azure Cache for Redis
  • Access to a LangGraph-based lending workflow
  • pip installed
  • Environment variables configured:
    • REDIS_URL=redis://localhost:6379/0
    • Any LLM keys your LangGraph app uses, such as OPENAI_API_KEY
  • Python packages:
    • langgraph
    • redis
    • langchain-core if your graph uses message objects

Install the dependencies:

pip install langgraph redis langchain-core

Integration Steps

  1. Define the lending state and graph nodes

Start with a simple lending workflow state. In production, this usually includes applicant data, credit signals, underwriting decisions, and agent outputs.

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

class LendingState(TypedDict):
    applicant_id: str
    income: float
    debt: float
    credit_score: int
    decision: str
    notes: list[str]

def precheck(state: LendingState):
    dti = state["debt"] / max(state["income"], 1)
    if state["credit_score"] < 620 or dti > 0.45:
        return {"decision": "review", "notes": ["Failed automated precheck"]}
    return {"decision": "approve", "notes": ["Passed precheck"]}

def underwrite(state: LendingState):
    return {"decision": "approve", "notes": state["notes"] + ["Underwriter approved"]}

graph = StateGraph(LendingState)
graph.add_node("precheck", precheck)
graph.add_node("underwrite", underwrite)

graph.add_edge(START, "precheck")
graph.add_conditional_edges(
    "precheck",
    lambda s: "underwrite" if s["decision"] == "review" else END,
)
graph.add_edge("underwrite", END)

app = graph.compile()
  1. Add Redis as the shared coordination layer

Redis is where multiple agents can share job status, lock an application during underwriting, or store intermediate results. Use a namespaced key pattern so each loan application stays isolated.

import os
import json
import redis

redis_client = redis.Redis.from_url(os.environ["REDIS_URL"], decode_responses=True)

def save_agent_state(applicant_id: str, payload: dict):
    key = f"lending:{applicant_id}:state"
    redis_client.set(key, json.dumps(payload), ex=3600)

def load_agent_state(applicant_id: str):
    key = f"lending:{applicant_id}:state"
    raw = redis_client.get(key)
    return json.loads(raw) if raw else None

def acquire_lock(applicant_id: str) -> bool:
    return redis_client.set(
        f"lending:{applicant_id}:lock",
        "1",
        nx=True,
        ex=120,
    )
  1. Wire LangGraph execution to Redis persistence

Run the graph, then persist the result in Redis so other agents can pick it up later. This is the simplest integration pattern and works well when your lending flow has multiple specialist workers.

input_state = {
    "applicant_id": "A-10021",
    "income": 95000.0,
    "debt": 32000.0,
    "credit_score": 681,
    "decision": "",
    "notes": [],
}

if acquire_lock(input_state["applicant_id"]):
    result = app.invoke(input_state)
    save_agent_state(input_state["applicant_id"], result)
else:
    raise RuntimeError("Application is already being processed")

print(result)
  1. Use Redis for multi-agent handoff

A common pattern is one agent doing document extraction, another doing fraud checks, and LangGraph coordinating the sequence. Redis acts as the shared mailbox between them.

def fraud_agent(applicant_id: str):
    state = load_agent_state(applicant_id)
    if not state:
        return None

    # Example signal from another agent
    fraud_flag = False

    state["notes"].append("Fraud check completed")
    state["fraud_flag"] = fraud_flag
    save_agent_state(applicant_id, state)
    return state

def human_review_agent(applicant_id: str):
    state = load_agent_state(applicant_id)
    if not state:
        return None

    if state.get("decision") == "review":
        state["notes"].append("Queued for human review")
        save_agent_state(applicant_id, state)

fraud_agent("A-10021")
human_review_agent("A-10021")
  1. Add checkpointing for resumable lending flows

If you want LangGraph to resume from interrupted states, use its checkpointing interface with a persistent backend. For production systems that already use Redis heavily, keep Redis as the coordination store and use a durable checkpointer supported by your deployment strategy.

from langgraph.checkpoint.memory import MemorySaver

checkpointer = MemorySaver()
app_with_checkpointing = graph.compile(checkpointer=checkpointer)

thread_config = {"configurable": {"thread_id": "loan-A-10021"}}
output = app_with_checkpointing.invoke(input_state, config=thread_config)

redis_client.set(
    f"lending:{input_state['applicant_id']}:final",
    json.dumps(output),
)

Testing the Integration

Run a quick end-to-end check by invoking the graph and verifying that Redis received the final payload.

test_applicant = {
    "applicant_id": "A-20001",
    "income": 120000.0,
    "debt": 20000.0,
    "credit_score": 710,
    "decision": "",
    "notes": [],
}

if acquire_lock(test_applicant["applicant_id"]):
    output = app.invoke(test_applicant)
    save_agent_state(test_applicant["applicant_id"], output)

stored = load_agent_state("A-20001")
print(stored["decision"])
print(stored["notes"])

Expected output:

approve
['Passed precheck']

If you route borderline cases to underwriting, you should see something like:

approve
['Failed automated precheck', 'Underwriter approved']

Real-World Use Cases

  • Loan origination pipelines

    • One agent extracts documents.
    • Another validates income.
    • LangGraph routes edge cases to manual review.
    • Redis keeps every step synchronized across workers.
  • Fraud and compliance orchestration

    • A fraud agent writes risk flags to Redis.
    • A compliance agent reads them before approval.
    • LangGraph branches based on policy thresholds.
  • Customer-facing loan assistants

    • A chat agent gathers borrower details.
    • A scoring agent runs eligibility checks.
    • Redis stores session context so multiple agents can continue the same application without losing state.

This combo works best when you treat LangGraph as the control plane and Redis as the coordination layer. Keep business logic in graph nodes, keep transient shared data in Redis, and keep every key namespaced by application ID or thread ID.


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