Case study · Proof of concept
An Agent Harness for the Factory Floor
One AI agent per employee at a simulated manufacturer. It spots supply problems before they stop a production line, proposes a fix, and acts only after a human approves it. Built in a 3-day time box.
- Built
- Sep 2026 · 3-day time box
- Size
- ~8,200 lines of Python, ~1,000 lines of SQL
- Tests
- 29 tests, no network or model needed
The brief
Build an extendable agent harness for enterprise work: give every employee at a manufacturer a personal AI agent. I had three days. My answer is a working proof of concept against a simulated manufacturer, Northfield Manufacturing. It has an ERP, an email system and calendars, and a day simulator that feeds problems in one day at a time.
The insight: the hard part is the join
In a factory, the scarce resource isn't reasoning. It's the join. The purchase order is in the ERP. The supplier's email saying it will be four days late is in someone's inbox. The production schedule that depends on that part lives somewhere else. The ERP can answer "given these arrival dates, am I short?" Nobody is answering "what are the *real* arrival dates?"
So I gave the agent one measure of success: does a production order start on time over the next 14 days? Every check, proposal and alert has to trace back to that question.
Design principle: rules eliminate, the model chooses
I didn't want a model with credentials making judgment calls on purchase orders. The work is split three ways:
- Deterministic detectors find problems: netting shortfalls, allocations to held lots, overdue receipts, and suppliers not qualified for a part.
- Hard rules remove bad options. An unqualified supplier never reaches the model, however cheap it is.
- The model reads claims out of messy email prose, picks among options that are equally good on cost and lead time, and drafts the messages. It has no credentials and can only recommend.
What the agent is allowed to do depends on coverage, not on how confident the model sounds. If a versioned workflow covers the situation, the agent proposes it. If only a check fired, it raises an alert. Otherwise it stays quiet.
Architecture: five planes, three keys
- World: Supabase Postgres with
erp,mailandcalschemas. Row-level security decides who sees and writes what, so a quality manager's inbox is hidden from purchasing by the database itself, not by app code. - Day simulator: owns the clock and injects each day's events. It is the only component holding the service-role key.
- Provider gateway: gives each user a session with ERP, mail, calendar, event and write providers, all under that user's own token. Every write checks scope, requires an approval reference and an idempotency key, re-reads its preconditions, then writes, logs and emits an event.
- Harness: a reactor wakes the agent on Realtime "doorbell" ticks, day changes, decisions or a 30-minute heartbeat. Then it runs detect → plan (a LangGraph tool loop that must end in exactly one commit tool) → verify → gate → execute, keeping its state in SQLite.
- Approval UI: Streamlit is the *only* path to approval. The store refuses any decision without a click receipt.
Walking through it
Scenario A: a late supplier. A supplier emails Dana in purchasing to say a purchase order is slipping to September 8th. The agent joins that email to the PO, the part and the production order that needs it, rules out a tempting supplier that isn't qualified for the part, and proposes a reroute workflow to a qualified one. The new PO's price pushes it over Dana's $25K approval limit, so the gate sends it to her manager. If he hasn't decided by end of day and his calendar shows him out tomorrow, it goes to his backup. Once approved, an 8-step workflow runs:
confirm_order → confirm_qualified → confirm_lead_time → create_po
→ cancel_original → draft_notice → notify_production → schedule_arrival_check
The final step books a follow-up as a database row, not a timer, so it survives restarts. On the follow-up day the part still hasn't arrived, so the agent opens a new session and proposes the next move.
Scenario B: a quality hold. A lot gets placed on hold. Ellen in quality has no purchasing permissions, so the agent looks for another lot to reallocate. If none covers the gap, it escalates rather than inventing an action she isn't allowed to take.
The simulated world is also full of deliberate traps. There is a cheap unqualified supplier, emails that almost match a real issue, a payment-redirect email from a lookalike domain, a shortage with no email at all, an order outside the 14-day window, and a day where nothing arrives.
Making writes safe
- Inside a workflow the model cannot reorder, skip or add steps. It only drafts text from facts the engine gives it.
- Every write is idempotent, replayed from a write log, and needs an approval reference. If a step fails, earlier steps are undone in reverse order.
- Workflows are checkpointed with LangGraph's SQLite checkpointer and pick up where they left off if the process is killed.
- Five versioned workflows (PO reroute, additional PO, supplier chase, reschedule request, quality recall and quarantine) sit on nine write actions, and each action needs exactly one scope.
- Every run is traced in Arize Phoenix via OpenInference and recorded as a trajectory file you can replay.
What I cut, and why it's honest to say so
This is a proof of concept. I deliberately left out real SSO and token exchange (static tokens stand in), workflow version migration, alert ranking, an event bus with retries, and an HTTP approval endpoint. Most of these are designed in the notes but not built. There are known rough edges. Scenario A depends on the model choosing the workflow, which weaker models sometimes miss. The recorded runs show a handful of tool-call validation errors from the model provider, which the planner recovers from. An escalation isn't yet routed to the escalated person's console.
The biggest trade-off is philosophical, and I wrote it into the design notes: a harness built this way can only find problems someone wrote a check for, and it doesn't automatically get smarter as models improve. I took that deal on purpose. In a factory, an agent you can audit is worth more than one that is occasionally brilliant.
What I'd build next
- OIDC SSO with RFC 8693 token exchange, so each agent acts with its employee's real identity.
- Postgres LISTEN/NOTIFY with leased workers, to scale from one process to many.
- Evaluation metrics: minutes from first signal to proposal, how often humans approve proposals as-is, and missed shortages per simulated month.
- A Microsoft Graph adapter so the mail and calendar providers can point at a real tenant.