How to Build a claims processing Agent Using AutoGen in Python for pension funds

By Cyprian AaronsUpdated 2026-04-21
claims-processingautogenpythonpension-funds

A claims processing agent for pension funds takes a member’s claim, checks the required documents, validates eligibility rules, extracts missing details, and routes the case to the right human reviewer when needed. It matters because pension operations are document-heavy, rule-driven, and audit-sensitive; the agent reduces manual handling without weakening compliance, traceability, or control.

Architecture

Build this agent as a small multi-agent workflow, not a single chat loop.

  • Intake agent

    • Receives claim packets from email, portal uploads, or internal case systems.
    • Normalizes inputs into a structured claim object.
  • Document extraction agent

    • Pulls fields from IDs, benefit forms, bank letters, death certificates, or medical evidence.
    • Flags missing or inconsistent fields.
  • Rules validation agent

    • Checks pension-specific eligibility rules.
    • Verifies claim type, member status, beneficiary relationship, service dates, and payment constraints.
  • Compliance and audit agent

    • Produces an auditable decision trail.
    • Captures why a claim was approved, rejected, or escalated.
  • Human escalation agent

    • Routes edge cases to operations staff.
    • Handles exceptions like disputed beneficiaries, sanctions hits, or data mismatches.
  • Case writer agent

    • Drafts the final case note and summary for the claims system.
    • Keeps the language deterministic and reviewable.

Implementation

1) Install AutoGen and define your agents

Use pyautogen and the core AssistantAgent / UserProxyAgent pattern. For pension claims, keep one agent responsible for extraction and another for validation so you can inspect each step independently.

pip install pyautogen
import os
from autogen import AssistantAgent, UserProxyAgent

llm_config = {
    "model": "gpt-4o-mini",
    "api_key": os.environ["OPENAI_API_KEY"],
    "temperature": 0,
}

extractor = AssistantAgent(
    name="document_extractor",
    llm_config=llm_config,
    system_message=(
        "You extract structured fields from pension claim documents. "
        "Return JSON only. Never invent missing data."
    ),
)

validator = AssistantAgent(
    name="rules_validator",
    llm_config=llm_config,
    system_message=(
        "You validate pension claim eligibility against supplied rules. "
        "Return JSON only with decision: approve, reject, or escalate."
    ),
)

case_writer = AssistantAgent(
    name="case_writer",
    llm_config=llm_config,
    system_message=(
        "You write concise pension claims case notes for human review. "
        "Include facts only. No speculation."
    ),
)

user_proxy = UserProxyAgent(
    name="claims_system",
    human_input_mode="NEVER",
)

2) Pass the claim through extraction and validation

This is the core pattern: one agent extracts facts from unstructured content, another applies policy rules. For pension funds this separation is useful because audit teams want to see what came from documents versus what came from policy logic.

claim_packet = """
Member: John A. Moyo
Member ID: PF-882193
Claim type: Early retirement
Date of birth: 1968-04-12
Employment end date: 2025-01-31
Attached docs: ID card scan, resignation letter, bank confirmation letter
Missing docs: proof of service history
"""

extraction_prompt = f"""
Extract these fields from the claim packet:
- member_name
- member_id
- claim_type
- date_of_birth
- employment_end_date
- attached_docs
- missing_docs

Claim packet:
{claim_packet}
"""

extracted = user_proxy.initiate_chat(
    extractor,
    message=extraction_prompt,
)

rules_prompt = """
Validate this early retirement claim using these rules:
1. Member must be at least 55 years old.
2. Employment must have ended before payment processing.
3. Bank confirmation letter must be present.
4. Proof of service history is required before approval.
5. If any required item is missing, escalate.

Use the extracted facts below:
<PASTE_JSON_HERE>
"""

validation_result = user_proxy.initiate_chat(
    validator,
    message=rules_prompt,
)

In production you would replace <PASTE_JSON_HERE> with parsed JSON from the extractor response. The important part is that each stage stays deterministic and reviewable.

3) Add a group chat for escalation and final case notes

When a claim is ambiguous, use GroupChat and GroupChatManager to coordinate multiple agents. This works well for cases like beneficiary disputes or missing proof of service because you can force a structured discussion before escalation.

from autogen import GroupChat, GroupChatManager

groupchat = GroupChat(
    agents=[extractor, validator, case_writer],
    messages=[],
    max_round=4,
)

manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)

summary_prompt = """
Create a final case note for a pension claims officer.
Include:
- key extracted facts
- validation outcome
- missing documents
- recommended next action

Use only verified information.
"""

user_proxy.initiate_chat(manager, message=summary_prompt)

For claims ops teams, this gives you a clean path from raw documents to an auditable summary without burying business logic inside one prompt.

4) Put guardrails around output shape and routing

Do not let free-form text drive downstream actions. Require strict JSON output from agents and validate it before writing to your case management system.

import json

def parse_decision(raw_text: str) -> dict:
    data = json.loads(raw_text)
    allowed = {"approve", "reject", "escalate"}
    if data["decision"] not in allowed:
        raise ValueError("Invalid decision")
    return data

def route_case(decision: dict):
    if decision["decision"] == "approve":
        return "send_to_payment_queue"
    if decision["decision"] == "reject":
        return "send_rejection_letter_queue"
    return "send_to_human_review_queue"

Production Considerations

  • Data residency

    • Pension member records often have jurisdictional storage requirements.
    • Keep model calls inside approved regions and avoid sending sensitive documents to unmanaged endpoints.
  • Audit logging

    • Log every prompt, response hash, model version, timestamp, and routing decision.
    • Store extracted fields separately from narrative summaries so auditors can trace evidence back to source documents.
  • Guardrails

    • Enforce schema validation on every agent output.
    • Block approvals when mandatory evidence is absent; never let the model “fill in” missing service history or beneficiary details.
  • Human override

    • Any sanctions hit, deceased-member claim ambiguity, dependent dispute, or large payout should go to manual review.
    • Build explicit escalation thresholds into code rather than relying on natural-language instructions.

Common Pitfalls

  1. Letting one agent do everything

    • This creates opaque behavior and weak auditability.
    • Split extraction, validation, and summarization into separate agents with narrow responsibilities.
  2. Trusting model output without schema checks

    • Free-form text will eventually break your workflow.
    • Parse JSON strictly and reject anything that does not match your expected contract.
  3. Ignoring pension-specific controls

    • Generic claims automation misses compliance issues like residency limits, document retention rules, and benefit eligibility thresholds.
    • Encode fund policy in deterministic code and use AutoGen only where reasoning over messy inputs adds value.

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