← Work

Systems Architecture  ·  Personal R&D

AI-Ready System Architecture

Sentient Supply Chain  ·  2026

Outcome

A layered mock ERP where business logic is encoded structurally — not held as tacit knowledge in people. An AI agent operates through a constrained API boundary and cannot commit orders without explicit human approval. The system tests one hypothesis: the prerequisite for trusted autonomous procurement is a better-designed underlying system, not a better model.

Context

AI adoption in supply chain operations fails at the system layer. The agent has no validated data to reason about, no enforced business rules to operate within, no audit trail. Business logic lives in the operator's head. That knowledge cannot be delegated.

SSC is a personal R&D project exploring what the underlying system must look like before an agent can be trusted to make autonomous procurement decisions. Mid-development, the project was formally repositioned from prototype to portfolio-grade codebase — architectural clarity took priority over delivery speed.

Problem

Standard ERP adoption places business logic in human judgment — operators know which suppliers are valid, which stock thresholds trigger reorders, which state transitions are legal. That tacit knowledge cannot be delegated to an agent. The agent needs the system to enforce the rules, not the person.

Constraints

  • Solo R&D project — no production environment, no real client data
  • Scoped to procurement and inventory — not a full ERP
  • Agent scope limited to reorder decisions: the highest-frequency, lowest-ambiguity procurement task

Approach

01 —

Data contracts as constitution

Defined Pydantic models for Supplier, Product, and Order with hard validation rules: SKU format enforced by regex, stock values non-negative, supplier reliability bounded 0–1, order status constrained to a fixed state machine. Invalid states cannot be created. The system rejects malformed data at the boundary before it reaches business logic.

Three domain invariants were formalized: stock allocation safety (confirmed orders cannot exceed available stock), upper bound constraint (inbound replenishment cannot exceed thresholds without an explicit override workflow), and shipped immutability (a shipped order cannot be reversed except through a compensating workflow). The service layer enforces them. The database guarantees them.

02 —

Three-layer architecture

Refactored from a monolithic API into three layers with hard separation of concerns. The repository layer handles data access — no HTTP exceptions, no business rules. The service layer enforces all business logic via domain-specific exceptions — no HTTP concepts. The router layer handles HTTP translation only — no business logic, exception mapping to status codes exclusively.

Five custom domain exceptions form the explicit contract between layers. The storage engine swapped from in-memory dictionaries to SQLite without touching the service or router layers. The architecture absorbed it.

03 —

Order state machine

Explicit directed graph with terminal states (shipped, cancelled) and valid transitions only: drafted → confirmed → shipped or cancelled. Invalid transitions return 409. The state machine maps directly to LangGraph node transitions — the business workflow and the agent workflow use the same logic.

04 —

Persistence and relational integrity

SQLite and SQLAlchemy replaced in-memory storage without touching the service or router layers. A supplier-product junction table encodes which suppliers can fulfill which SKUs. Order creation validates that the specified supplier supplies the requested product — the system rejects the pairing if it does not exist. Referential integrity is structural.

05 —

Agent with HITL interrupt

A LangGraph ReorderAgent runs four nodes: fetch products below threshold, propose reorders via ranked supplier recommendations, generate a plain-language HITL narrative via LLM, pause for operator approval before committing orders. The LLM executes only at judgment boundaries — unstructured input, no deterministic ground truth. Reorder calculation, stock comparison, status transitions, and referential validation run in Python.

The commit node does not execute without explicit operator approval. This is a design principle, not a prototype limitation. LangChain was rejected in favor of a provider-isolated interface — the agent is ignorant of which model is active.

06 —

External intelligence layer

Suppliers carry an ISO 3166-1 country field. A standalone script queries GDELT for risk-relevant news per country. The LLM receives structured supplier-country-news data and reasons across it — one API call per country, not per supplier. The LLM dismisses irrelevant articles rather than hallucinating risks. Verified against Taiwan cross-strait coverage tied to a specific supplier in the seed data.

Deliverable

Three-layer ERP system with validated data contracts, constrained REST API, and SQLite persistence. LangGraph ReorderAgent with HITL approval flow and swappable LLM provider. Shift report script. Geopolitical risk digest grounded in live GDELT data. Seed script with two products below threshold, supplier overlap within the recommendation window, and geopolitically relevant country assignments to trigger meaningful agent output on first run.

Business logic encoded in the system — via validation, state machines, least privilege, referential integrity, and explicit invariants — makes agent behavior observable, auditable, and correctable. A system that relies on human memory to enforce rules cannot safely delegate decisions to an agent.