How to Build a claims processing Agent Using CrewAI in TypeScript for lending
A claims processing agent for lending takes a borrower’s claim, pulls the relevant loan and policy context, checks it against business rules, and drafts a decision package for a human reviewer or downstream workflow. In lending, this matters because claims are not just support tickets — they affect credit exposure, regulatory posture, customer outcomes, and auditability.
Architecture
- •
Claim intake layer
- •Receives structured claim payloads from a portal, webhook, or case system.
- •Normalizes fields like loan ID, borrower ID, claim type, loss date, and supporting documents.
- •
Policy and loan context retriever
- •Pulls contract terms, repayment status, delinquency state, collateral data, and prior claims.
- •Keeps the agent grounded in source-of-truth systems instead of free-form reasoning.
- •
CrewAI agent layer
- •Uses one agent for claim triage and one for compliance validation.
- •Produces a decision recommendation with citations to retrieved context.
- •
Tooling layer
- •Exposes deterministic tools for CRM lookup, loan ledger lookup, document classification, and audit logging.
- •Keeps sensitive operations outside the LLM.
- •
Decision orchestration
- •Runs the CrewAI
CrewwithProcess.sequentialso each step is auditable. - •Routes low-risk claims automatically and escalates ambiguous cases to humans.
- •Runs the CrewAI
- •
Audit and storage layer
- •Persists inputs, outputs, tool calls, timestamps, model version, and reviewer actions.
- •Required for lending audits, dispute handling, and internal control testing.
Implementation
1) Install dependencies and define your data contract
Use the TypeScript package for CrewAI plus your usual runtime tooling. Keep the claim shape strict; lending workflows fail when fields are inferred loosely.
npm install @crewai/crewai zod dotenv
// src/types.ts
import { z } from "zod";
export const ClaimSchema = z.object({
claimId: z.string(),
borrowerId: z.string(),
loanId: z.string(),
claimType: z.enum(["payment_dispute", "hardship", "fraud", "collateral_damage"]),
amount: z.number().positive(),
currency: z.string().default("USD"),
submittedAt: z.string(),
evidenceUrls: z.array(z.string()).default([]),
});
export type ClaimInput = z.infer<typeof ClaimSchema>;
2) Build deterministic tools for loan and compliance lookups
Do not let the model invent loan facts. Put retrieval behind tools so every fact can be logged and replayed.
// src/tools.ts
import { Tool } from "@crewai/crewai";
export const getLoanContextTool = new Tool({
name: "get_loan_context",
description: "Fetch loan status, repayment history, collateral info, and policy flags by loanId.",
func: async (loanId: string) => {
// Replace with real DB/API calls
return JSON.stringify({
loanId,
status: "active",
daysPastDue: 12,
productType: "personal_loan",
jurisdiction: "US-NY",
collateralized: false,
policyFlags: ["manual_review_required_over_1000"],
});
},
});
export const logAuditEventTool = new Tool({
name: "log_audit_event",
description: "Persist an immutable audit event for the claim decision workflow.",
func: async (payload: string) => {
// Replace with append-only audit store
console.log("AUDIT_EVENT", payload);
return "ok";
},
});
3) Define agents and tasks with explicit responsibilities
Keep the triage agent narrow. Give compliance its own agent so you can inspect where a recommendation came from.
// src/crew.ts
import { Agent, Crew, Process, Task } from "@crewai/crewai";
import { getLoanContextTool, logAuditEventTool } from "./tools";
export function buildClaimsCrew() {
const triageAgent = new Agent({
role: "Claims Triage Analyst",
goal: "Assess whether the lending claim is eligible for auto-resolution or requires escalation.",
backstory:
"You review lending claims using only provided loan context and policy rules. You never guess missing facts.",
tools: [getLoanContextTool],
verbose: true,
allowDelegation: false,
});
const complianceAgent = new Agent({
role: "Lending Compliance Reviewer",
goal:
"Check the proposed outcome against lending policy, regulatory constraints, data residency rules, and audit requirements.",
backstory:
"You validate decisions for explainability and regulatory fit. You flag any missing evidence or jurisdictional risk.",
tools: [logAuditEventTool],
verbose: true,
allowDelegation: false,
});
const triageTask = new Task({
description:
"Review the claim payload. Retrieve loan context using get_loan_context. Determine eligibility, key risks, and whether human review is required.",
expectedOutput:
"A JSON object with fields decision_recommendation, risk_level, reasons[], missing_info[], and cited_facts[].",
agent: triageAgent,
});
const complianceTask = new Task({
description:
"Validate the triage recommendation for lending compliance. Check fairness concerns, auditability gaps, residency constraints, and whether escalation is required.",
expectedOutput:
"A JSON object with fields approved_for_auto_resolution:boolean, compliance_notes[], escalation_reason|null.",
agent: complianceAgent,
context: [triageTask],
});
return new Crew({
agents: [triageAgent, complianceAgent],
tasks: [triageTask, complianceTask],
process: Process.sequential,
verbose: true,
});
}
4) Run the crew from a TypeScript entrypoint
This is the pattern you want in production services: validate input first, run sequential tasks second, persist output last.
// src/index.ts
import "dotenv/config";
import { ClaimSchema } from "./types";
import { buildClaimsCrew } from "./crew";
async function main() {
const rawClaim = {
claimId: "CLM-10021",
borrowerId": "BRW-90011",
loanId": "LN-77881",
claimType": "payment_dispute",
amount": 1250,
submittedAt": new Date().toISOString(),
evidenceUrls": ["https://files.example.com/evidence/receipt.pdf"],
};
EOF
---
## Keep learning
- [The complete AI Agents Roadmap](/blog/ai-agents-roadmap-2026) — my full 8-step breakdown
- [Free: The AI Agent Starter Kit](/starter-kit) — PDF checklist + starter code
- [Work with me](/contact) — I build AI for banks and insurance companies
*By Cyprian Aarons, AI Consultant at [Topiax](https://topiax.xyz).*
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