How to Build a claims processing Agent Using AutoGen in TypeScript for healthcare
A claims processing agent in healthcare takes an incoming claim, checks the submitted data against policy and clinical rules, routes exceptions to the right workflow, and drafts a decision or request for more information. It matters because claims are high-volume, error-prone, and regulated; if you automate the triage and validation layer correctly, you reduce manual review time without losing auditability or compliance.
Architecture
- •
Claim intake service
- •Receives EDI 837, JSON from a portal, or claim payloads from an internal queue.
- •Normalizes the input into a canonical claim object before any agent logic runs.
- •
Policy/rules retrieval layer
- •Pulls plan-specific coverage rules, prior authorization requirements, and coding policies.
- •Keeps the agent grounded in approved source material instead of free-form reasoning.
- •
AutoGen orchestration layer
- •Uses
AssistantAgentfor claim analysis andUserProxyAgentfor controlled tool execution. - •Coordinates validation, summarization, and escalation decisions.
- •Uses
- •
Deterministic tools
- •Eligibility lookup, CPT/ICD validation, provider registry checks, and claim status APIs.
- •These are called by the agent through explicit functions, not inferred from prompts.
- •
Audit and decision store
- •Persists inputs, tool calls, intermediate outputs, final decisions, and reviewer overrides.
- •Required for compliance review, dispute handling, and model governance.
- •
Human review queue
- •Routes uncertain or high-risk claims to a claims examiner.
- •Keeps the agent in an assistive role where policy requires human sign-off.
Implementation
1) Install AutoGen and define your claim shape
Use the TypeScript AutoGen package that exposes AssistantAgent, UserProxyAgent, and OpenAIChatCompletionClient. Keep your claim schema strict so you can validate before any LLM call.
npm install @autogen/core @autogen/openai zod
import { z } from "zod";
export const ClaimSchema = z.object({
claimId: z.string(),
memberId: z.string(),
providerNpi: z.string(),
diagnosisCodes: z.array(z.string()),
procedureCodes: z.array(z.string()),
dateOfService: z.string(),
amountBilled: z.number(),
placeOfService: z.string()
});
export type Claim = z.infer<typeof ClaimSchema>;
2) Create deterministic tools for eligibility and coding checks
The agent should not invent eligibility results or coding guidance. Wrap those checks as real functions that can be called explicitly.
type EligibilityResult = {
eligible: boolean;
planId: string;
notes: string[];
};
async function checkEligibility(memberId: string): Promise<EligibilityResult> {
// Replace with your payer API call
return {
eligible: true,
planId: "HMO-204",
notes: ["Active coverage", "No termination date found"]
};
}
async function validateCoding(procedureCodes: string[], diagnosisCodes: string[]) {
// Replace with ICD/CPT rules engine
return {
valid: procedureCodes.length > 0 && diagnosisCodes.length > 0,
issues:
procedureCodes.length === 0
? ["Missing procedure codes"]
: []
};
}
3) Wire up AutoGen agents and run the claim review flow
This pattern keeps the LLM focused on reasoning over validated inputs while tools handle regulated system calls. The UserProxyAgent is useful as the execution boundary; the AssistantAgent generates the analysis.
import { AssistantAgent, UserProxyAgent } from "@autogen/core";
import { OpenAIChatCompletionClient } from "@autogen/openai";
import { ClaimSchema } from "./claim-schema";
const client = new OpenAIChatCompletionClient({
model: "gpt-4o-mini",
apiKey: process.env.OPENAI_API_KEY!
});
const claimsAssistant = new AssistantAgent({
name: "claims_assistant",
modelClient: client,
systemMessage: [
"You are a healthcare claims processing assistant.",
"Use only provided claim data and tool outputs.",
"Do not make up eligibility, coding approval, or medical necessity.",
"If confidence is low or data is missing, recommend human review."
].join(" ")
});
const executor = new UserProxyAgent({
name: "claims_executor"
});
export async function processClaim(rawClaim: unknown) {
const claim = ClaimSchema.parse(rawClaim);
const eligibility = await checkEligibility(claim.memberId);
const coding = await validateCoding(claim.procedureCodes, claim.diagnosisCodes);
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