How to Integrate LangGraph for lending with Redis for AI agents
Combining LangGraph for lending with Redis gives you a clean way to build lending agents that remember state, coordinate multi-step workflows, and recover fast after failures. LangGraph handles the loan decision flow, while Redis stores checkpoints, session state, and short-lived agent memory so your system can resume exactly where it left off.
Prerequisites
- •Python 3.10+
- •A Redis instance running locally or in the cloud
- •A LangGraph-based lending workflow already defined
- •
langgraph - •
redis - •
langchain-coreif you’re using message objects in your graph - •An OpenAI-compatible model provider or another LLM backend for your agent nodes
Install the packages:
pip install langgraph redis langchain-core
Set your Redis connection string:
export REDIS_URL="redis://localhost:6379/0"
Integration Steps
- •Define your lending graph with checkpoint support.
For lending workflows, you usually want durable execution across steps like intake, eligibility check, risk review, and final decision. LangGraph’s checkpointer API is what lets you persist state between those steps.
from typing import TypedDict, Annotated
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
class LendingState(TypedDict):
messages: Annotated[list, add_messages]
applicant_name: str
income: float
requested_amount: float
decision: str
def intake_node(state: LendingState):
return {
"decision": "pending",
"messages": [("assistant", "Intake complete. Running eligibility checks.")]
}
def underwriting_node(state: LendingState):
income = state["income"]
amount = state["requested_amount"]
if income >= amount * 3:
decision = "approved"
else:
decision = "manual_review"
return {
"decision": decision,
"messages": [("assistant", f"Underwriting result: {decision}")]
}
graph = StateGraph(LendingState)
graph.add_node("intake", intake_node)
graph.add_node("underwriting", underwriting_node)
graph.add_edge(START, "intake")
graph.add_edge("intake", "underwriting")
graph.add_edge("underwriting", END)
- •Configure Redis as the LangGraph checkpoint store.
LangGraph supports a Redis-backed checkpointer through its checkpoint integrations. The key point is that Redis becomes the persistence layer for thread-level state so each loan application can be resumed by thread_id.
import os
from redis import Redis
# Depending on your LangGraph version/package layout,
# use the Redis checkpointer provided by the integration package.
from langgraph.checkpoint.redis import RedisSaver
redis_url = os.environ["REDIS_URL"]
redis_client = Redis.from_url(redis_url)
checkpointer = RedisSaver(redis_client)
checkpointer.setup()
If you are on a version where the constructor takes a URL directly, use that instead:
# Alternative pattern depending on package version
# from langgraph.checkpoint.redis import RedisSaver
# checkpointer = RedisSaver.from_conn_string(redis_url)
# checkpointer.setup()
- •Compile the graph with the checkpointer and run a lending session.
This is where Redis starts paying off. Every invocation uses a stable thread_id, which lets LangGraph store and retrieve the loan workflow state across turns.
app = graph.compile(checkpointer=checkpointer)
config = {
"configurable": {
"thread_id": "loan-app-10023"
}
}
initial_state = {
"messages": [("user", "Run lending review for Maria Chen")],
"applicant_name": "Maria Chen",
"income": 120000,
"requested_amount": 30000,
"decision": ""
}
result = app.invoke(initial_state, config=config)
print(result["decision"])
print(result["messages"][-1])
- •Store agent memory or supporting loan context in Redis.
Use Redis for non-checkpoint data too. For example, you can cache KYC status, document extraction results, or risk scores so your graph nodes don’t recompute them every time.
import json
from datetime import timedelta
cache_key = f"loan:{config['configurable']['thread_id']}:kyc"
kyc_payload = {
"status": "verified",
"provider": "trulioo",
"score": 0.98
}
redis_client.setex(cache_key, timedelta(minutes=30), json.dumps(kyc_payload))
cached_kyc = json.loads(redis_client.get(cache_key))
print(cached_kyc["status"])
- •Resume or branch the workflow from persisted state.
This is the main reason to pair LangGraph with Redis in lending systems. If underwriting needs manual review later, or an analyst adds new information, you can load the same thread and continue from saved state instead of restarting the application.
follow_up_state = {
"messages": [("user", "Add analyst note: verified employment history.")],
}
next_result = app.invoke(follow_up_state, config=config)
print(next_result["decision"])
print(next_result["messages"][-1])
Testing the Integration
Run a quick end-to-end test to confirm both persistence and execution work.
test_config = {"configurable": {"thread_id": "test-loan-001"}}
test_state = {
"messages": [("user", "Test applicant")],
"applicant_name": "Test Applicant",
"income": 90000,
"requested_amount": 20000,
"decision": ""
}
output = app.invoke(test_state, config=test_config)
print("Decision:", output["decision"])
# Verify checkpoint data exists in Redis by checking a key pattern manually if needed.
keys = redis_client.keys("*test-loan-001*")
print("Redis keys:", keys)
Expected output:
Decision: approved
Redis keys: [b'...test-loan-001...']
If you get a decision back and see thread-related keys in Redis, your integration is working.
Real-World Use Cases
- •Loan origination assistants that collect applicant data over multiple turns and resume after interruptions.
- •Underwriting copilots that cache risk signals, document extraction results, and policy lookups in Redis while LangGraph manages the decision path.
- •Collections or servicing agents that maintain conversation state across channels and keep delinquency workflow checkpoints durable.
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