How BatchTrace Agent Works
A step-by-step walkthrough of how disconnected food manufacturing records become a navigable, deterministic traceability graph powered by controlled open-weight AI.
Document Ingestion & Coordinate Provenance
CSV, XLSX, Text PDF, and Dock LogsWhen documents are uploaded, BatchTrace validates file headers, validates MIME types, and uses deterministic regex parsers alongside AI extraction to parse supplier invoices, dock receipts, production sheets, and bills of lading.
Zero Hallucinated Citations Principle:
For every extracted lot code, quantity, and timestamp, BatchTrace records exact source coordinates: Document ID, page number, row index, original extracted text, and normalized value. If a citation cannot be pointed to an actual byte or row in storage, it is marked invalid.
Deterministic Graph Traversal & Quantity Reconciliation
PostgreSQL Foreign Keys, Join Tables, and Certainty LevelsTraceability is not entrusted to an LLM prompt. Traversal logic executes in typed TypeScript and PostgreSQL relational queries across Suppliers → Ingredient Lots → Production Batches → Finished Lots → Customer Orders.
Certainty Classification:
- • Confirmed: Backed by approved documents and validated joins.
- • Possible: Pending review (e.g. unreviewed batch sheet) or matching rule.
- • Unknown: Missing data explicitly highlighted.
Quantity Reconciliation:
Compares received ingredient mass against cumulative batch usage. Automatically flags variances (such as the 50 kg overage on Lot L-204) without silently coercing numbers.
Controlled AI Agent & Open-Weight Inference
Qwen3-4B / Local Ollama Adapter with Tool CallingThe AI model is sandboxed behind server-side typed tools (`trace_ingredient_lot`, `check_quantity_discrepancies`, `get_source_evidence`). It has zero direct SQL execution, no arbitrary file system permissions, and cannot fabricate business entities.
> Understand Query: "Which batches used lot L-204?"
> Call Tool: get_ingredient_lot(lotId="L-204")
> Call Tool: trace_ingredient_lot(lotId="L-204", direction="FORWARD")
> Ground Explanation in Verified DB Records
> Output Evidence Chips & Request Human Sign-off
Human Decision-Support & Audit Trail
Formal Incident Generation with Sign-off ControlsBatchTrace is decision-support software. It prepares formal incident reports with affected batches, retail destination addresses, and discrepancy breakdowns, but requires an authorized QA manager to approve next actions.