a small agent that chases unpaid invoices for an agency. it reads invoices from a csv and from images, drafts polite reminders and follows up on replies.
all data is fake. the mailbox is a json file. no real email is sent.
- plain code loops over the ledger.
- each invoice gets its own agent run. the loop is our own code on the anthropic messages api. no agent sdk.
- the agent calls six tools:
list_unpaid,extract_invoice,draft_reminder,send_email,check_reply,mark_paid. - images are read by claude vision. each result has a
confidencefield. - tests use a stub model with fake token usage. they run offline.
pip install -r requirements.txt
python make_samples.py # builds the fake data
pytest # offline, no key needed
python agent.py --demo # offline run with a rule-based stub model
python agent.py --reset # clears state.json and outbox.jsonlive run:
cp .env.example .env # then fill in ANTHROPIC_API_KEY and ANTHROPIC_MODEL
python agent.py --only INV-001 # one invoice first
python agent.py --only inv_clean.png # one image
python agent.py # the whole ledgereach tool call prints as it runs. add --quiet for the summary only.
a live run allows up to 50 model calls per invoice and uses your api credit. try the demo first.
| file | purpose |
|---|---|
agent.py |
the agent loop, model adapters, stub models, cli |
tools.py |
the six tools, shared context, injectable clock |
extract.py |
image to invoice fields. real extractor and an offline one |
make_samples.py |
builds invoices.csv, inbox.json, invoices_in/, samples_labels.json |
test_replay.py |
replay tests with stub models |
data files:
invoices.csv: 36 fake invoices. read-only seed data.inbox.json: scripted client replies.invoices_in/: 8 fake invoice files. clean, blurry, rotated, two currencies, a duplicate, a missing due date and a pdf.samples_labels.json: the expected fields for each sample.state.jsonandoutbox.json: written at run time.