How to Build a underwriting Agent Using AutoGen in TypeScript for insurance

By Cyprian AaronsUpdated 2026-04-21
underwritingautogentypescriptinsurance

An underwriting agent takes a submission, pulls the right policy, claims, and risk data, then produces a recommendation: quote, refer, or decline. For insurance teams, this matters because underwriting is where speed, consistency, and auditability either hold up the business or break it.

Architecture

Build this agent as a small workflow, not a single prompt:

  • Submission intake
    • Normalizes broker emails, ACORD-style forms, CSVs, or API payloads into one internal schema.
  • Risk retrieval layer
    • Pulls policy history, claims history, loss runs, KYC/AML flags, and appetite rules from internal systems.
  • Underwriting reasoning agent
    • Uses AutoGen to analyze the submission against underwriting guidelines and produce a structured recommendation.
  • Compliance and audit logger
    • Stores every input, tool call, intermediate output, and final decision for later review.
  • Decision router
    • Converts the model output into one of three actions: quote, refer, or decline.
  • Human review handoff
    • Escalates borderline cases to an underwriter with the full evidence trail.

Implementation

1) Install AutoGen and define your domain types

Use the TypeScript AutoGen package and keep the underwriting payload strict. Insurance workflows fail when free-form text leaks into core decisioning.

npm install @autogenai/autogen
type Submission = {
  submissionId: string;
  insuredName: string;
  lineOfBusiness: "property" | "casualty" | "professional_liability";
  premiumTarget: number;
  state: string;
  industryCode: string;
  yearsInBusiness: number;
  priorClaimsCount: number;
  lossRatio?: number;
};

type UnderwritingDecision = {
  action: "quote" | "refer" | "decline";
  reason: string;
  confidence: number;
  citedFactors: string[];
};

2) Create an assistant agent with a strict system prompt

For underwriting, the system message should force structured output and prohibit hallucinated facts. Use AssistantAgent for reasoning and keep the instructions specific to insurance appetite rules.

import { AssistantAgent } from "@autogenai/autogen";

const underwritingAgent = new AssistantAgent({
  name: "underwriting_agent",
  systemMessage: `
You are an insurance underwriting assistant.
Only use facts provided in the submission and retrieved risk data.
Do not invent policy terms, claims history, or regulatory outcomes.
Return JSON with:
{
  "action": "quote" | "refer" | "decline",
  "reason": string,
  "confidence": number,
  "citedFactors": string[]
}
If data is missing or contradictory, choose "refer".
`,
});

3) Add a tool-backed data retrieval step

In production you do not want the model guessing about claims history or appetite. Fetch those facts first using your own service layer, then pass them into the agent as context.

async function getRiskData(submissionId: string) {
  // Replace with real calls to PAS/claims/risk services
  return {
    priorClaimsCount: 2,
    openClaims: false,
    sanctionsHit: false,
    appetiteMatch: true,
    lossRatio: 0.42,
    stateRestriction: false,
    notes: ["No open claims", "Within target loss ratio"],
  };
}

async function underwrite(submission: Submission): Promise<UnderwritingDecision> {
  const riskData = await getRiskData(submission.submissionId);

  const prompt = `
Submission:
${JSON.stringify(submission)}

Retrieved risk data:
${JSON.stringify(riskData)}

Apply underwriting rules:
- Decline if sanctionsHit is true
- Refer if appetiteMatch is false
- Refer if required fields are missing
- Quote only if no hard stop exists
`;

  const result = await underwritingAgent.run(prompt);
  return JSON.parse(result.content as string) as UnderwritingDecision;
}

4) Wrap the decision in an auditable workflow

This is where you make it usable for insurers. Persist inputs and outputs so compliance can reconstruct why a case was quoted or referred.

import { writeFile } from "node:fs/promises";

async function auditDecision(
  submission: Submission,
  decision: UnderwritingDecision,
) {
  const record = {
    timestamp: new Date().toISOString(),
    submission,
    decision,
    modelVersion: "autogen-underwriting-agent-v1",
    reviewerRequired: decision.action === "refer",
  };

  await writeFile(
    `./audit/${submission.submissionId}.json`,
    JSON.stringify(record, null, 2),
    "utf8",
  );
}

async function main() {
  const submission: Submission = {
    submissionId: "SUB-10021",
    insuredName: "Northwind Manufacturing",
    lineOfBusiness: "property",
    premiumTarget: 250000,
    state: "TX",
    industryCode: "332710",
    yearsInBusiness: 8,
    priorClaimsCount: 1,
    lossRatio: undefined,
  };

  const decision = await underwrite(submission);
  await auditDecision(submission, decision);

  console.log(decision);
}

main();

Production Considerations

  • Deployment

Build this as a stateless service behind your API gateway. Keep policy admin system access behind private networking so submissions and claims data never leave your controlled environment.

  • Monitoring

Log every agent run with submission ID, retrieved facts, latency, token usage, and final action. Track drift by comparing quote/refer/decline rates against human underwriters by line of business.

  • Guardrails

Hard-stop on sanctions hits, missing mandatory fields, and state-specific restrictions before calling the model. The agent should recommend; your rules engine should decide on non-negotiable compliance constraints.

  • Data residency

Store audit trails and retrieved customer data in-region if you operate across jurisdictions. For regulated carriers and MGAs, make sure vendor hosting matches your retention and residency obligations.

Common Pitfalls

  1. Letting the model infer missing facts

    If claims history or loss ratio is absent, force a refer. Do not let the agent “fill in” gaps from pattern matching.

  2. Mixing policy rules into prompts only

    Hard underwriting rules belong in code or a rules engine. Prompts are for reasoning over facts; they are not a compliance control surface.

  3. Skipping audit structure

    A free-text answer is useless during file review or regulator inquiry. Persist raw inputs, retrieved evidence, final decision, and versioned prompts every time.


Keep learning

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

Related Guides