Most accounting teams still reconcile invoices by hand — copying numbers between spreadsheets, chasing approvals over email, and fixing mismatches one cell at a time. A single AI agent built with the Anthropic Agents SDK can do all of that in seconds.

This guide walks through building an invoice-processing agent that extracts line items from PDFs, matches them against your general ledger, and flags discrepancies for human review.

Why the Anthropic Agents SDK?

The Anthropic Agents SDK lets you define agents with instructions, tools, and handoff logic — then orchestrate them into workflows powered by Claude. Unlike rigid RPA scripts, these agents can reason about edge cases and recover from unexpected formats.

Key advantages over traditional automation:

  • Handles unstructured data — OCR + LLM parsing beats template-based extraction
  • Self-correcting — agents can re-read a blurry field or ask for clarification
  • Composable — add new agents (e.g. an auditor) without rewriting the pipeline

Architecture Overview

The system uses three agents working in sequence:

  1. Extractor — reads PDF invoices, outputs structured JSON
  2. Matcher — compares extracted data against the GL using fuzzy matching
  3. Reporter — produces a reconciliation summary with flagged items

Setting Up the Project

pip install anthropic-agents pandas pdfplumber

Define the extractor agent:

from agents import Agent, Runner
 
extractor = Agent(
    name="Invoice Extractor",
    instructions="Extract line items from PDF invoices into structured data. You are an expert at reading financial documents.",
    model="claude-sonnet-4-5",
    tools=[pdf_reader_tool],
)

Each agent gets focused instructions. The tools parameter injects capabilities — here, a PDF reader that returns page text.

Building the Matching Logic

The matcher agent uses Pandas to compare extracted invoices against the ledger:

import pandas as pd
 
def match_invoices(extracted: list[dict], ledger: pd.DataFrame) -> pd.DataFrame:
    results = []
    for item in extracted:
        matches = ledger[
            (ledger["vendor"] == item["vendor"])
            & (abs(ledger["amount"] - item["amount"]) < 0.01)
        ]
        results.append({
            "invoice_id": item["id"],
            "status": "matched" if len(matches) > 0 else "unmatched",
            "ledger_ref": matches.iloc[0]["ref"] if len(matches) > 0 else None,
        })
    return pd.DataFrame(results)

For production use, you would add fuzzy string matching on vendor names and date-range tolerance for payment terms.

Running the Agent Pipeline

Wire the agents into a sequential workflow using handoffs:

import asyncio
from agents import Agent, Runner
 
reporter = Agent(
    name="Reporter",
    instructions="Produce a reconciliation summary with flagged items from the matching results.",
    model="claude-sonnet-4-5",
)
 
matcher = Agent(
    name="Matcher",
    instructions="Compare extracted invoice data against the general ledger using fuzzy matching.",
    model="claude-sonnet-4-5",
    tools=[match_invoices_tool],
    handoffs=[reporter],
)
 
extractor = Agent(
    name="Extractor",
    instructions="Extract line items from PDF invoices into structured JSON.",
    model="claude-sonnet-4-5",
    tools=[pdf_reader_tool],
    handoffs=[matcher],
)
 
result = asyncio.run(Runner.run(extractor, input="Process the invoices in /data/invoices/"))

The Runner.run() call starts with the extractor, which hands off to the matcher, which hands off to the reporter — passing context between agents automatically.

Results and Next Steps

In our pilot with a mid-market logistics company, this pipeline processed 340 invoices in 12 minutes — work that previously took a junior accountant two full days.

The agent flagged 23 discrepancies, of which 21 were genuine mismatches and 2 were false positives (a 91% precision rate). With prompt tuning, we brought false positives to zero in the second iteration.

"We didn't eliminate the accountant — we eliminated the drudgery. Our team now spends their time on analysis and vendor negotiations instead of data entry." — CFO, logistics client

Where to Go From Here

  • Add an approval workflow agent that routes flagged items to the right person via Slack
  • Integrate with QuickBooks or Xero APIs for direct ledger access
  • Set up scheduled runs with a cron job or Airflow DAG
  • Add anomaly detection to catch unusual patterns across months of data