How to Build a document extraction Agent Using AutoGen in TypeScript for wealth management
A document extraction agent for wealth management reads client statements, prospectuses, account opening forms, tax documents, and KYC packets, then turns them into structured fields your downstream systems can trust. It matters because advisors and operations teams lose time on manual rekeying, and mistakes in net worth, beneficiary details, tax IDs, or suitability data create compliance and client risk.
Architecture
Build this agent with a narrow, auditable pipeline:
- •
Document ingress
- •Accept PDFs, images, and scanned forms from a controlled source like S3, SharePoint, or an internal DMS.
- •Enforce tenant scoping and document classification before extraction.
- •
OCR / text normalization
- •Convert scans into text with page-level metadata.
- •Preserve bounding boxes when possible so reviewers can trace every extracted field back to source.
- •
AutoGen extraction agent
- •Use an
AssistantAgentto extract structured JSON from normalized text. - •Keep the prompt strict: schema-first, no freeform summaries.
- •Use an
- •
Validation layer
- •Validate output against a TypeScript schema before anything hits CRM or onboarding systems.
- •Reject missing required fields like account number, tax residency, or beneficial owner names.
- •
Human review queue
- •Route low-confidence or policy-sensitive cases to an operations reviewer.
- •Wealth management workflows need human sign-off on KYC/AML edge cases.
- •
Audit store
- •Persist input hash, model output, reviewer edits, timestamps, and document lineage.
- •This is non-negotiable for compliance and post-trade or onboarding disputes.
Implementation
1) Define the extraction contract first
Start with the fields you actually need in wealth management. Don’t ask the model to “extract everything”; ask for a fixed schema that matches onboarding or servicing.
import { z } from "zod";
export const ClientDocumentSchema = z.object({
documentType: z.enum([
"account_opening",
"statement",
"kyc",
"tax_form",
"beneficiary_form",
]),
clientName: z.string(),
accountNumber: z.string().optional(),
taxIdLast4: z.string().optional(),
jurisdiction: z.string().optional(),
beneficiaries: z.array(
z.object({
name: z.string(),
relationship: z.string().optional(),
percentage: z.number().optional(),
})
).default([]),
netWorth: z.number().optional(),
liquidNetWorth: z.number().optional(),
});
This schema is your contract with downstream systems. If the model returns extra fields or malformed values, you fail closed.
2) Create an AutoGen assistant that extracts only JSON
AutoGen’s TypeScript package gives you AssistantAgent and UserProxyAgent. For this pattern, the assistant does extraction and the user proxy acts as the orchestrator for tool calls or message passing.
import { AssistantAgent, UserProxyAgent } from "@autogen-ai/autogen";
import { ClientDocumentSchema } from "./schema";
const extractor = new AssistantAgent({
name: "wealth_doc_extractor",
systemMessage: `
You extract structured data from wealth management documents.
Return only valid JSON matching this shape:
{
"documentType": "...",
"clientName": "...",
"accountNumber": "...",
"taxIdLast4": "...",
"jurisdiction": "...",
"beneficiaries": [{"name":"...","relationship":"...","percentage":0}],
"netWorth": 0,
"liquidNetWorth": 0
}
Rules:
- Do not invent missing values.
- Use null or omit optional fields if absent.
- Preserve exact names as written in the document.
- If confidence is low, include only what is explicit in the text.
`,
});
const orchestrator = new UserProxyAgent({
name: "orchestrator",
});
The key here is that the model is not asked to interpret policy. It extracts facts; your application enforces policy.
3) Send normalized document text through AutoGen and validate output
In production you’ll feed OCR output. For this example, assume you already have cleaned text from PDF/OCR processing.
async function extractFields(documentText: string) {
const result = await orchestrator.initiateChat(extractor, {
message: `
Extract structured data from this document:
${documentText}
`,
maxTurns: 1,
clearHistory: true,
summaryMethod: "last_msg",
// If your runtime supports it, keep temperature at zero for deterministic extraction.
// modelClientConfig belongs in your agent/model setup depending on your AutoGen version.
});
const raw = typeof result === "string" ? result : result?.summary ?? "";
const parsed = JSON.parse(raw);
return ClientDocumentSchema.parse(parsed);
}
This pattern gives you three gates:
- •model output generation
- •JSON parsing
- •schema validation
That sequence is what keeps bad extractions out of your core systems.
4) Add a review path for exceptions
Wealth workflows need escalation when confidence is low or the document contains regulated attributes. A simple rule engine works well here.
function needsReview(data: unknown): boolean {
const doc = ClientDocumentSchema.safeParse(data);
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