How to Build a customer support Agent Using CrewAI in TypeScript for insurance
A customer support agent for insurance handles policy questions, claim status checks, document requests, and triage for complex cases. It matters because most support volume is repetitive, but the risk is not: one bad answer can create compliance issues, bad customer outcomes, or an audit problem.
Architecture
- •Intent router
- •Classifies the request into claims, billing, policy changes, FNOL, or escalation.
- •Policy knowledge tool
- •Reads approved product docs, underwriting rules, and support scripts from a controlled source.
- •Customer context tool
- •Pulls account-specific data from CRM or policy admin systems with strict access checks.
- •Compliance guardrail layer
- •Blocks advice that crosses into underwriting decisions or unapproved legal guidance.
- •Escalation workflow
- •Routes complex or sensitive cases to a human adjuster or licensed rep.
- •Audit logger
- •Stores prompts, tool calls, model outputs, and final actions for review.
Implementation
1) Install dependencies and define the agent contract
For TypeScript, keep the agent boundary small. The support agent should answer only from approved sources and escalate when it sees claims disputes, coverage exceptions, or regulated language.
npm install @crewai/core zod
import { Agent, Task, Crew } from "@crewai/core";
import { z } from "zod";
const SupportInputSchema = z.object({
customerId: z.string(),
message: z.string(),
jurisdiction: z.string(),
});
type SupportInput = z.infer<typeof SupportInputSchema>;
2) Add tools for policy lookup and case lookup
In insurance, the agent should not invent answers. It needs tools that query your approved knowledge base and customer systems with explicit scoping.
import { Tool } from "@crewai/core";
const policySearchTool: Tool = {
name: "policy_search",
description: "Search approved insurance policy docs and support articles.",
execute: async ({ query }: { query: string }) => {
// Replace with your vector DB / document store lookup
return `Approved excerpt for "${query}": Claims must be reported within 30 days.`;
},
};
const customerLookupTool: Tool = {
name: "customer_lookup",
description: "Fetch customer policy summary and open service cases.",
execute: async ({ customerId }: { customerId: string }) => {
// Replace with CRM / policy admin integration
return JSON.stringify({
customerId,
activePolicies: ["AUTO-12345"],
openClaims: [{ claimId: "CLM-8891", status: "pending review" }],
});
},
};
3) Create the support agent with guardrails in the system prompt
Use a narrow instruction set. The model should answer factual service questions, cite sources from tools when possible, and escalate anything involving coverage determinations or legal interpretation.
const insuranceSupportAgent = new Agent({
name: "Insurance Support Agent",
role: "Customer support specialist for insurance operations",
goal:
"Resolve routine customer support requests using approved policy content and account data.",
backstory:
"You handle billing questions, claim status updates, document requests, and escalation triage.",
tools: [policySearchTool as any, customerLookupTool as any],
verbose: true,
});
4) Run a task through a crew and return a structured response
The important pattern here is to keep one task focused on one outcome. For production systems, I recommend returning structured JSON to your application layer so you can decide whether to auto-reply or escalate.
const supportTask = (input: SupportInput) =>
new Task({
description: `
You are handling an insurance support request.
Customer ID: ${input.customerId}
Jurisdiction: ${input.jurisdiction}
Message: ${input.message}
Rules:
- Use only approved policy information.
- If coverage interpretation is needed, escalate.
- If the user asks for legal advice or exceptions, escalate.
- Return a concise response plus an escalation flag.
`,
expectedOutput:
'{ "reply": string, "escalate": boolean, "reason": string }',
agent: insuranceSupportAgent,
});
export async function handleSupportRequest(inputRaw: unknown) {
const input = SupportInputSchema.parse(inputRaw);
const crew = new Crew({
agents: [insuranceSupportAgent],
tasks: [supportTask(input)],
verbose: true,
});
const result = await crew.kickoff();
return result;
}
If you want a more deterministic flow in production, split this into two tasks:
- •classification task
- •resolution task
That gives you cleaner routing when the first step detects claims disputes or regulatory sensitivity.
Production Considerations
- •Deployment
- •Keep the agent behind an authenticated API gateway.
- •Restrict tool access by tenant and jurisdiction so one customer cannot query another customer’s records.
- •Monitoring
- •Log every
Crew.kickoff()run with prompt hash, tool calls, output tokens, escalation decision, and final disposition. - •Track false resolution rate on claim-related tickets separately from general support tickets.
- •Log every
- •Guardrails
- •Block responses that mention guaranteed payouts unless they come from approved policy text.
- •Force escalation for coverage denials, complaint language, fraud allegations, and state-specific regulatory questions.
- •Data residency
- •Store prompts and retrieved documents in-region if your insurer operates under residency requirements.
- •Redact PII before sending context to external model providers whenever possible.
Common Pitfalls
- •Letting the model answer coverage questions directly
- •Fix it by forcing tool-backed responses and escalating anything that requires interpretation of contract language.
- •Mixing support automation with claims adjudication
- •Fix it by separating routine service workflows from adjuster workflows. The agent can triage claims; it should not decide them.
- •Ignoring auditability
- •Fix it by storing the full trace of inputs, retrieved documents, outputs, and human handoff decisions. Insurance teams will ask for this later.
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