How to Build a customer support Agent Using CrewAI in TypeScript for pension funds
A customer support agent for pension funds handles routine member queries: contribution status, retirement eligibility, benefit estimates, transfer requests, and document collection. It matters because pension support sits in a high-trust, high-compliance environment where wrong answers create regulatory risk, angry members, and expensive manual escalations.
Architecture
Build this agent with a small set of components that map to real pension operations:
- •Member intent router
- •Classifies requests like “What’s my current balance?”, “Can I retire next year?”, or “Where is my transfer form?”
- •Policy retrieval layer
- •Pulls answers from approved pension plan documents, FAQs, and regulatory guidance.
- •Case handling toolset
- •Creates tickets, fetches case status, and routes sensitive issues to human advisors.
- •Compliance guardrail
- •Blocks advice outside approved policy, especially anything that looks like financial advice or benefit promises.
- •Audit logger
- •Stores prompt inputs, tool calls, citations, and final responses for review.
- •Member identity context
- •Injects authenticated member attributes from your backend; never let the agent ask for or infer identity on its own.
Implementation
1) Install CrewAI and define the support tools
Use CrewAI’s TypeScript package and wrap your internal systems as tools. For pension funds, keep tools narrow: read-only for account data unless you explicitly need write actions like case creation.
npm install @crew-ai/crewai zod
import { z } from "zod";
import { Agent, Task, Crew } from "@crew-ai/crewai";
const getPensionSummary = {
name: "get_pension_summary",
description: "Fetch the authenticated member's pension summary.",
schema: z.object({
memberId: z.string(),
}),
execute: async ({ memberId }: { memberId: string }) => {
// Replace with your pension admin API call
return {
memberId,
contributionsYtd: "£8,420.00",
projectedRetirementAge: 67,
planName: "Defined Benefit Plan A",
};
},
};
const searchPolicyDocs = {
name: "search_policy_docs",
description: "Search approved pension policy documents and FAQs.",
schema: z.object({
query: z.string(),
}),
execute: async ({ query }: { query: string }) => {
// Replace with vector search / document store lookup
return [
{
title: "Retirement Eligibility FAQ",
excerpt: "Members can request an estimate after age 55 subject to plan rules.",
},
];
},
};
2) Create an agent with strict support behavior
This is where you constrain tone, scope, and escalation. For pension funds, the agent should answer from policy and account data only; it should not speculate on tax treatment or future returns.
const pensionSupportAgent = new Agent({
name: "Pension Support Agent",
role: "Customer support specialist for pension fund members",
goal:
"Resolve routine member queries using approved policy content and authenticated account data.",
backstory:
"You work in a regulated pensions environment. You must stay within approved policy, cite sources when possible, and escalate anything involving complaints, disputes, transfers-in/out exceptions, or financial advice.",
tools: [getPensionSummary, searchPolicyDocs],
});
3) Define the task and run the crew
Keep the task explicit. A good support task includes the member question plus the authenticated context passed from your app session.
const supportTask = new Task({
description: `
Answer the member's question using only approved tools and policy.
If the request requires financial advice, legal interpretation, or a complaint response,
escalate to a human advisor.
Member context:
- memberId: MBR-10291
- locale: en-GB
- authenticatedChannel: web
Question:
"What is my projected retirement age and can I take benefits early?"
`,
expectedOutput:
"A concise support response with any relevant policy note and escalation guidance if needed.",
agent: pensionSupportAgent,
});
const crew = new Crew({
agents: [pensionSupportAgent],
tasks: [supportTask],
});
async function main() {
const result = await crew.kickoff();
console.log(result);
}
main().catch(console.error);
4) Add a guardrail before sending the response back
In production you should not trust raw model output. Run a final check for disallowed content such as guaranteed returns, tax advice, or unsupported claims about benefit entitlement.
function validatePensionResponse(output: string) {
const blockedPatterns = [
/guaranteed return/i,
/financial advice/i,
/you are entitled to/i,
/tax/i,
/legal advice/i,
];
const hit = blockedPatterns.find((pattern) => pattern.test(output));
if (hit) {
throw new Error("Response failed compliance validation.");
}
return output;
}
Production Considerations
- •Deployment
- •Keep the agent behind your authenticated member portal or contact-center middleware.
- •Never expose raw tool endpoints directly to the model; wrap them in a service layer with authz checks.
- •Monitoring
- •Log every tool call with
memberId, case ID, timestamp, prompt hash, and output hash. - •Track escalation rate by intent type so you can spot policy gaps or hallucination clusters.
- •Log every tool call with
- •Guardrails
- •Block outputs that look like regulated advice on transfers, tax treatment, drawdown choices, or retirement timing beyond published rules.
- •Force escalation for complaints handling under your scheme’s complaint process.
- •Data residency
- •Store prompts, embeddings, transcripts, and audit logs in-region if your pension scheme has residency requirements.
- •If you use external LLM APIs, verify where inference happens and whether data is retained.
Common Pitfalls
- •
Letting the agent infer member identity
- •Don’t ask the model to “figure out who this is” from chat history.
- •Pass authenticated identity from your app session into the task context.
- •
Mixing support with advice
- •A support agent can explain plan rules; it should not recommend whether a person should retire early or transfer out.
- •Use explicit escalation paths for anything that crosses into regulated advice.
- •
Skipping auditability
- •If you cannot reconstruct why the agent answered something, you do not have a production system.
- •Persist prompts, retrieved documents, tool outputs, final response text, and a compliance decision flag.
- •
Using broad tools
- •Avoid one giant “pension_api” tool that can read and write everything.
- •Split tools by action so you can apply least privilege and review each capability separately.
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