StarkSphere Labs
← Case studies
AI agentsProduction AIFintechMulti-tenancyERP integration

Taking a multi-tenant finance agent into production

An AI accounting platform's agent reads invoices and bank statements, reconciles them, and posts the results into each client's ERP. We built the production system around the model, so it can be trusted with real money for many companies at once.

The problem

The prototype answered questions about a company's books convincingly. Production asked for more: many client companies in one database, real invoices and bank statements in every format, writes into each client's own ERP, and finance teams who need to know exactly what the agent did and why. The existing row-level security turned out to be inert, and nothing structural stopped the model from acting on its own.

What we built

The backend, integrations, and interface around the agent. The model reads documents and proposes records; deterministic code computes every amount and tax line; a single committer writes to the client's ERP only after a person confirms. Tenant isolation moved into the database, and every stage is observable.

How it works

  • Human-gated writes: the model has no code path to the ERP. It drafts a proposal, a person confirms it, and one deterministic committer performs the write.
  • Document reading for invoices, bills, and bank statements across PDFs, scans, and spreadsheets, with guards that catch misread fields, such as a date read as an amount, before a draft is shown.
  • Odoo and Zoho Books behind one interface and one write path that is idempotent and reads back what it wrote, including bank reconciliation across currencies.
  • Forced row-level security in Postgres and a least-privilege application role, so the agent's connection cannot see another client's rows.
  • Durable background jobs with state in Postgres and a queue for delivery, so syncs and long extractions survive restarts without posting twice.
  • A model gateway in front of every LLM call, Prometheus and Grafana monitoring, and CI gates on schema, API contract, and tenant isolation.

The result

An agent that can be given real work. It drafts invoices, bills, and reconciliations from the documents a finance team already has, and nothing reaches a ledger until a person confirms it. Isolation between clients is enforced by the database, and CI checks those guarantees on every pull request.

StackGoPostgresNext.jsAWSLiteLLMOdooZoho BooksPrometheusGrafana

The full write-up

This page is the summary. Each part of the system has its own write-up, with the code and the failure that shaped it:

Have a system like this to take to production? Let's scope it.