Production Project · Multi-Agent Orchestration
Featured · GenAI · LangGraph

Underwriter Multi-Agent Orchestration

// Production mortgage underwriting system — 7 specialised agents, hybrid RAG, AWS Bedrock
95%
Decision accuracy
7
Specialised agents
Hybrid
RAG retrieval
<3s
Avg decision time
Full
Audit trail

Problem Statement

Traditional mortgage underwriting is manual, slow, and inconsistent — underwriters spend 60–80% of their time gathering documents, running calculations, and looking up policy rules. Decisions vary across reviewers and are difficult to audit.

The goal was a production-grade autonomous pipeline that ingests loan application documents, performs all analytical steps in parallel, checks policy compliance, scores risk, and produces a fully-reasoned underwriting decision — with a complete audit trail — in under 3 seconds.

Architecture Overview

Built on LangGraph with 7 specialised agents operating as a directed state graph. Each agent receives the shared state object, performs its function, and writes results back. Agents that are independent of each other run in parallel via LangGraph's branching edges.

Agent 01
Document Intake Agent
PDF ingestion, OCR fallback via AWS Textract, structured extraction of applicant fields, income statements, and asset documents. Validates completeness before passing downstream.
Agent 02
Financial Ratio Agent
Computes DTI, LTV, housing ratio, and reserve months. Flags values outside acceptable bands. Runs in parallel with Agent 03 and 04.
Agent 03
Credit Analysis Agent
Analyses credit score, payment history, derogatory marks, and credit utilisation. Classifies credit profile tier and generates narrative summary.
Agent 04
Property Valuation Agent
Retrieves comparable sales via API, validates appraisal figures, computes LTV against market value, and flags collateral risk.
Agent 05
Policy RAG Agent
Hybrid retrieval (BM25 + pgvector + RRF fusion) against the policy knowledge base. Cross-encoder reranking. Checks each ratio and credit flag against applicable policy rules and returns citations.
Agent 06
Risk Scoring Agent
Aggregates all agent outputs into a composite risk score. Applies weighting model. Produces risk tier (Approve / Conditional / Decline) with confidence band.
Agent 07
Decision Writer Agent
Synthesises all agent outputs into a structured underwriting decision letter — reasoning, policy citations, risk summary, conditions if applicable. Writes to database with full state snapshot for audit.

RAG Retrieval Stack

The Policy RAG Agent uses a hybrid retrieval approach — sparse BM25 for exact policy terminology plus dense pgvector semantic search, fused with Reciprocal Rank Fusion (RRF). A cross-encoder reranks the top-20 candidates before passing context to the LLM.

# Hybrid retrieval with RRF fusion
bm25_results   = bm25_retriever.get_relevant_documents(query, k=20)
vector_results = pgvector_retriever.get_relevant_documents(query, k=20)
fused          = reciprocal_rank_fusion([bm25_results, vector_results])
reranked       = cross_encoder.rerank(query, fused[:20])
return reranked[:5]
Policy documents are chunked using semantic chunking (sentence-transformers similarity threshold) to keep policy clauses intact. Each chunk stores policy_section, product_type, and effective_date as metadata for pre-filtering.

End-to-End Flow

01
Document Ingestion
Application PDF uploaded to S3. Lambda triggers ingestion pipeline. Agent 01 extracts structured fields using AWS Textract + LLM parsing.
02
Parallel Analysis
Agents 02, 03, and 04 run in parallel via LangGraph branching. Financial ratios, credit analysis, and property valuation computed simultaneously.
03
Policy Compliance Check
Agent 05 retrieves relevant policy sections for each flagged item. Returns pass/fail per rule with citation. Stored in state for Agent 07.
04
Risk Scoring
Agent 06 aggregates all outputs. Weighted composite score determines tier. Confidence interval computed from ratio variance.
05
Decision & Audit
Agent 07 writes structured decision letter. Full LangGraph state snapshot saved to PostgreSQL. LangSmith traces every agent call for observability.

Infrastructure

LayerTechnologyPurpose
OrchestrationLangGraphAgent state graph, conditional routing, parallel edges
LLMAWS Bedrock (Claude 3)All agent LLM calls — no OpenAI dependency
Vector DBpgvector (PostgreSQL)Dense semantic retrieval for policy RAG
Sparse RetrievalBM25 (rank-bm25)Keyword-exact policy terminology matching
RerankerCross-encoder (ms-marco)Top-20 candidate reranking
OCRAWS TextractScanned document extraction fallback
StorageAWS S3 + PostgreSQLDocument store + structured data + audit log
CachingRedis (semantic cache)Identical query deduplication
ObservabilityLangSmithTrace every agent, token counts, latency
APIFastAPI on ECS FargateREST endpoints, async processing
CI/CDGitHub Actions → ECR → ECSAutomated deploy pipeline

Key Engineering Decisions

Why LangGraph over LangChain LCEL?

LCEL chains are linear. The underwriting flow requires parallel branches (agents 02/03/04 run simultaneously), conditional routing (high-risk applications trigger additional checks), and state persistence across agent hops. LangGraph's directed graph model handles all three natively.

Why pgvector over Weaviate/Pinecone?

Policy documents already live in PostgreSQL. Adding pgvector keeps the retrieval stack in a single database — no network hop to an external vector service, simpler ops, and SQL metadata filtering with zero additional infrastructure.

Semantic Caching

Policy questions repeat across applications. Redis semantic cache (cosine similarity threshold 0.92) means identical or near-identical policy queries skip the LLM entirely — reducing cost and latency by ~40% in steady-state traffic.

LangGraphAWS BedrockFastAPI pgvectorBM25LangSmith RedisAWS TextractECS Fargate PostgreSQLRAGASCross-Encoder