Inspiration

Procurement teams reconcile hundreds of purchase orders against official price catalogs by hand, every month. A one-dollar overcharge per unit, an arithmetic slip in an invoice total, a volume spike nobody catches in time — none of these show up as one dramatic failure. They show up as slow, quiet financial leakage that becomes an accepted cost simply because nobody had time to check. We wanted an agent that never stops checking, and that takes real action instead of just flagging things in a chat window.

What it does

OpsAgent AI runs a full procurement audit cycle on its own, every hour, with nobody starting it. It pulls pending purchase orders from BigQuery, resolves each vendor's identity and official contact from a dedicated vendor directory, and reconciles pricing and arithmetic using deterministic Decimal math — never floating-point approximations. When it finds a discrepancy, it classifies the type (price mismatch, math error, high-volume risk), quantifies the exact financial exposure, and drafts a formal vendor communication. For example: an order billed at $390/unit against a $350 catalog price, 15 units, gets flagged as a $600 overcharge with severity HIGH, and a ready-to-send draft — automatically. Every one of those drafts lands in a Human-in-the-Loop console, and nothing goes out to a vendor until a person clicks approve.

How we built it

Gemini 3.5 Flash orchestrates through native function calling on Vertex AI, calling three tools: list pending orders, audit math and pricing, and persist the audit log. Every BigQuery query is parameterized — the model never writes free-text SQL. Firestore holds workflow state behind a @firestore.transactional claim, so two workers can never process the same order twice, and a stale lock from a crashed run expires and gets safely reclaimed. A headless worker (worker.py) runs as a Cloud Run Job, triggered hourly by Cloud Scheduler through its own least-privilege service account, completely separate from the runtime identity that talks to BigQuery, Firestore, and Vertex AI. A Streamlit console on Cloud Run gives a human the execution trace, the batch metrics, and the approval queue. Everything ships in one container via Cloud Build and Artifact Registry.

Challenges we ran into

Getting the model version and region right took real trial and error — Gemini 3.5 Flash wasn't reachable from a single-region Vertex AI endpoint, only from the multi-region us endpoint, and that only surfaced as a 404 once deployed. Keeping every BigQuery call parameterized meant designing fixed, purpose-built tools instead of letting the model write its own SQL. Idempotency was the hardest part to get right at a distributed level: a transactional claim has to reject a duplicate in-flight worker but still recover automatically if a previous run died mid-lock. And more than once, a field we assumed would survive a tool call — like the vendor's email — quietly didn't, because it lived one level deeper in the response than our parsing expected. We stopped trusting that a fix worked until we pulled the raw Firestore document and the raw gcloud execution log and confirmed it ourselves.

Accomplishments that we're proud of

A closed loop from raw order data to a vendor-ready draft with zero manual reconciliation, gated by real human approval — not a demo narrated over slides, but something we watched run unattended, hour after hour, triggered by its own scheduler and nobody else. Idempotency and lock recovery that we actually tested against a simulated stale lock, not just wrote and hoped. And a CSV importer that lets anyone — including a judge — load an entirely invented vendor and order and watch the agent resolve it correctly, with no seed data required.

What we learned

The real design decision in an agentic system isn't how much freedom to give the model — it's exactly where autonomy stops and a fixed, deterministic function takes over. Gemini reasons, decides, and drafts. It never determines a price, a total, a vendor's identity, or whether an email actually goes out. Those stay in code, on purpose. And when an agent is touching money, "probably right" isn't good enough — every claim needs to be checked against a real, raw system output before you trust it, including your own.

What's next

Wiring the sandbox dispatch path to a real SMTP gateway for production use, layering BigQuery ML anomaly detection on top of the current deterministic rules, and extending the vendor and catalog model toward direct ERP integrations like SAP and NetSuite.

Built With

  • agentic-ai
  • artifact-registry
  • autonomous-agents
  • bigquery
  • cloud-build
  • cloud-logging
  • cloud-run
  • cloud-scheduler
  • data-warehouse
  • docker
  • enterprise
  • fintech
  • firestore
  • function-calling
  • gemini
  • google-cloud
  • google-genai
  • human-in-the-loop
  • procurement
  • pydantic
  • python
  • sql
  • streamlit
  • vertex-ai
Share this project:

Updates

Submission history