> Markdown version of https://www.imranjan.cn/projects/p-byof-agent for AI agents and other programs. It carries the same public information as the web page. Built 2026-11-30.

September 2026

# BYOF Agent

Production planning & exception management

NUS-ISS Show Me Your Agents (SMYA) Agentic AI Hackathon 2026

My teammates and I built a production-planning agent that works out the cost and delivery of each response when an order grows, material runs short or a machine stops. Once the manager approves one, it handles the resupply, reschedules production and tracks the factory’s confirmation.

Tags: Hackathon, AI Agent, Constraint Scheduling, LangGraph

![BYOF Agent](https://www.imranjan.cn/images/projects/byof-agent-2026/byof-logo.svg)

### Project resources

The full code is public on GitHub, with local setup steps in the README. The demo video and technical document open directly.

[Source code](https://github.com/narmi924/byof-agent)
[Watch the demo](https://www.youtube.com/watch?v=Ul6LUf-bLsM)
[Technical document](https://www.imranjan.cn/downloads/byof-agent-2026/technical-document.pdf)

## Team & Hackathon

#### Hackathon

NUS-ISS Show Me Your Agents (SMYA)
Agentic AI Hackathon 2026

- **Organizer**: Hosted by NUS-ISS (Institute of Systems Science, National University of Singapore), powered by AWS
- **Challenge**: Production planning: help a small factory’s production manager replan when an order grows, material runs short or a machine stops
- **Result**: Not in the top five
[Hackathon website](https://www.iss.nus.edu.sg/show-me-your-agents)

#### Team LIZZ

- [Me](https://github.com/narmi924) Lead
Overall approach and task split; scheduling, checking and the execution flow; the manager interface; the BYOF logo and intro film.
- [Li Jiaxing](https://github.com/liaboveall)
Setting up the AWS Lightsail server and the live deployment (byof.site); the early database environment.
- [Zhang Lingyue](https://github.com/Reality787)
SKF research and the domain specification; the reference factory’s database schema, baseline data and validation scripts; the rush-order scenario and solve checks across five disruption scenarios.
- [Zhu Pengxu](https://github.com/Robinsonson)
The first agent skeleton and runtime fixes; option comparison for demand and supply changes; factory data editing in the simulator; the DeepSeek adapter layer.
- **Time**: Three weeks

## Background

A production plan rarely survives the day. A customer adds to an order, a supplier is late, a machine stops, someone calls in sick. Small assembly plants usually have no planning department, so all of this lands on the production manager: check stock, reshuffle the sequence in a spreadsheet, then phone purchasing and the supervisors to find out what expediting would cost and how fast it could happen. When several things go wrong at once, they wait in line.

The hackathon problem statement was Production Planning. BYOF Agent takes this legwork off the manager. It reads the factory’s orders, stock, machines and staff to see which orders a change affects, then builds response options from resupply, expediting, overtime or a new due date. Each option is scheduled, checked and priced so the options can be compared side by side. Once the manager approves one, the system places the resupply, reschedules production and waits for the factory to confirm the new plan.

We held one line throughout: the language model understands the request, decides the next step and explains the result; quantities, times and money are computed by code, and only the manager can approve, on an option card. BYOF stands for Bring Your Own Factory: plug in your own factory’s data and it works. For the hackathon we built one reference factory, the bearing assembly shop described below.

### System architecture

On the left are two browser windows: the manager workbench, where the manager talks to the agent and approves options, and the simulator, which plays the shop floor and creates order changes, stoppages and absences. In the middle is BYOF itself: the business worker runs the agent and the execution flow, the solver worker schedules, checks and prices, and every record lives in PostgreSQL. On the right, the simulated factory keeps its own database, and BYOF can only read data and send commands through its interface. The orange line is the approval path: nothing executes until the manager approves an option card.

![BYOF system architecture and trust boundaries](https://www.imranjan.cn/images/projects/byof-agent-2026/architecture.jpg)

BYOF architecture. The whole stack runs on one host with Docker Compose, and each data store uses its own database role.

## Factory Model

Scheduling needs a concrete product and a concrete shop floor, and no public source gives you a real plant’s orders, stock and operation times. So we built a reference factory: product structure and assembly follow real documentation, while orders, stock, times and prices were set by the team.

Our first plan assumed a made-up plant assembling data-acquisition modules, but with a made-up product we couldn’t say where any number came from. So we looked for real products and compared two candidates:

### LulzBot Mini 2 3D printer

Not used

- Rich open-source assembly docs; the bill of materials ran to 502 lines including subassemblies
- Sources disagreed in 11 places
- No operation times

Researched by me

### SKF deep groove ball bearings

Chosen

- Dimensions of the 6202 to 6205 models matched SKF product pages
- Structure, lubrication, sealing and inspection covered by official SKF material
- Database schema, baseline data and validation scripts already done

Researched by Zhang Lingyue

The LulzBot bill of materials couldn’t be settled in time, while the SKF data was ready to use, so we chose the SKF bearing assembly scenario. Below is how it went from documents to data.

![Exploded view of a bearing unit from SKF documentation, showing the inner ring, balls, cage, seals and outer ring](https://www.imranjan.cn/images/projects/byof-agent-2026/skf-bearing-components.png)

Research source: exploded view from SKF, Insert bearings and ball bearing units, p. 7\. It shows a housed insert bearing; its inner ring, balls, cage, seals and outer ring match a deep groove ball bearing. Image © SKF.

### From parts to a bill of materials

We used four SKF sealed deep groove ball bearings, 6202, 6203, 6204 and 6205-2RS1, with dimensions from SKF product pages. Each bearing needs an inner ring, an outer ring, a ball set, a cage, two seals, a grease fill and a box: 25 materials across the four sizes.

All four share the same assembly equipment but use their own rings, balls and cages, so a busy order book creates real competition for machines and material. When an order grows or a delivery slips, the system uses this list to work out what is short and by how much.

[View the BOM data](https://github.com/narmi924/byof-agent/blob/main/database/seed/bom%5Fitems.csv)

![SKF manufacturing process chart for insert bearings, from ring heat treatment to marking and packaging](https://www.imranjan.cn/images/projects/byof-agent-2026/skf-manufacturing-reference.png)

Research source: the manufacturing process on p. 41 of the same publication. We used only the final assembly part. Image © SKF.

### From a process chart to eight operations

Page 41 of the same publication charts the process from ring heat treatment to packaging. We treated ring machining as bought in and kept only final assembly, as eight operations. A batch is 50 pieces; each operation takes 6 to 10 minutes and needs one machine type and one worker skill.

The shop has 8 machines and 8 workers. Two assembly cells can stand in for each other, while inspection, greasing and sealing have one machine each. The workers cover five skills, and one qualified worker runs an operation from start to finish.

1. Kitting and pre-assembly prep
2. Ring and ball assembly
3. Cage assembly
4. Pre-grease sealing check
5. Grease filling
6. Seal installation
7. Final inspection and release
8. Marking and packaging
[View the routing data](https://github.com/narmi924/byof-agent/blob/main/database/seed/routing%5Fsteps.csv)

### The demo shop

4bearing types

5,400pieces across 6 orders

864operations in 108 batches

5days, two shifts a day

Shifts run 8:30 to 12:00 and 13:00 to 17:30, with up to two hours of overtime after 17:30 if the manager agrees. Anything due to start within 60 minutes is frozen. These operating figures are ours, not SKF’s. The baseline has validation scripts and pinned hashes, and the system refuses to start if it changes, so development, tests and the demo all ran on the same factory.

![Data provenance diagram: public sources, the team’s planning model and synthetic data become a validated factory snapshot that feeds solving, checking and costing](https://www.imranjan.cn/images/projects/byof-agent-2026/data_provenance.jpg)

Where the numbers come from: (a) public sources shape the products and operations, the team sets the operating data, and validation turns it into a versioned factory snapshot; (b) each candidate set of measures is solved, checked and costed on its own copy of the snapshot; (c) every number on an option card comes from these records, and the language model only writes the explanation.

## Problems Solved

##### Stuck after a machine stop

**What happened**When we stopped machine KIT-01 for 20 minutes, the solver failed seven times in a row. The 60-minute freeze window stacked with the review buffer and left the affected operations nowhere to go. The agent also treated “the solve job finished” as “there is a feasible plan” and kept retrying until it had used all 40 model requests for the session.

**What we changed**We unfreeze only the operations the stoppage touches, never re-solve the same infeasible scenario, extended the checker, and taught the agent to tell a finished job from a feasible plan.

##### Options took too long

**What happened**With production running, comparing options after an order increase took 131 seconds and only one of five options was feasible. A late delivery was worse: 122 seconds and none.

**What we changed**The solver now starts from the current plan, stops after 4 seconds without improvement, and options run in parallel processes. Afterwards the order increase took 23 to 30 seconds with all five options feasible, and the late delivery 26 seconds with five of seven.

##### One option when a date slips

**What happened**Due dates started out as hard constraints, so when one couldn’t be met the only answer was “one day later”.

**What we changed**Options now propose a concrete new date, the first full hour at least 30 minutes after the checked completion, and leave every other order’s date alone. The manager has to confirm the customer agreed before approving.

##### The factory moved on during a correction

**What happened**While the model was being asked to fix a malformed action, the factory clock and data kept moving. A correction made on the old data would schedule against a stale factory snapshot.

**What we changed**Every correction first refreshes the factory data and hands the model the new snapshot. Corrections count against the turn’s model request budget, and once it runs out the turn stops without asking again.

## A Rush Order, Step by Step

The demo starts from a day plan already in progress. A customer raises order SO-003 for 6204 bearings from 1,200 to 1,500 pieces, with the same due date: 17:30 the next day.

The extra 300 pieces need 300 inner rings, outer rings, ball sets and cages, plus 600 seals. The shop keeps only a small stock of 6204 parts, so it is short 250 of each of the first four and 500 seals. The problem is material, so resequencing or overtime alone can’t fix it.

[![A frame from the BYOF intro film: order SO-003 grows by 300 pieces](https://www.imranjan.cn/images/projects/byof-agent-2026/intro-poster.jpg)Watch the 15-second introOpens on Google Drive](https://drive.google.com/file/d/1LNyLFClNoGxlhDMwQTrJYdFeDX87cZNl/view?usp=sharing)

The 15-second intro film I made for our submission tells this same story: 300 more pieces, the shortage, the resupply options, and five resupply orders confirmed after approval.

1. ### Spot the change
After the order is changed in the simulator, the manager’s header shows a new field change. When it is opened, the agent re-reads the factory data to confirm what is short, by how much, and whether other orders are affected.
2. ### Compare options
The solver service schedules, checks and prices each feasible combination of measures on its own copy of the factory, several in parallel. Options that only resequence or add overtime drop out because of the shortage.
3. ### Approve and execute
The manager can ask follow-up questions or approve straight away. After approval the system places five resupply orders, reschedules, releases the plan and waits for the factory to confirm.

![BYOF manager workbench with the agent’s analysis of SO-003 and the standard resupply option card](https://www.imranjan.cn/images/projects/byof-agent-2026/manager.png)

Manager workbench: the agent’s analysis and the recommended option. Completion time, new cash, profit impact and the five resupply measures on the card can all be traced in the execution log later.

__Four feasible options for this order change__
| Option                          | New cash (SGD) | Projected net contribution (SGD) | Delivery          |
| ------------------------------- | -------------- | -------------------------------- | ----------------- |
| Standard resupply (recommended) | 1,200.00       | 28,450.00                        | All 1,500 on time |
| Expedited resupply              | 1,587.50       | 28,062.50                        | All 1,500 on time |
| Immediate transfer              | 2,700.00       | 26,950.00                        | All 1,500 on time |
| Reduce the order to 1,200       | 0              | 26,700.00                        | 300 pieces short  |

Net contribution covers all six orders: revenue minus variable cost, added cost and lateness penalties. For standard resupply that is 87,000 revenue, 58,500 variable cost and 50 in freight for five deliveries, with no lateness: 28,450\. Prices come from our own catalog, not supplier quotes.

Standard resupply delivers everything on time for the least money, so it comes first. Expedited resupply and the immediate transfer deliver the same but cost more, and the card folds them away as not adopted. Reducing the order costs nothing new but needs a conversation with the customer. The recommended plan finishes at 14:58 the next day, two and a half hours before the due time, with no overtime.

Running locally, options appeared about 45 seconds after the manager opened the change. After approval, resupply, rescheduling, release and the factory’s confirmation took about 30 seconds.

The other demo scenario is a date that can’t be met: an order grows and is pulled forward to noon the same day. Every option then proposes a specific new due date, and the manager can approve only after confirming the customer agreed.

![Production timeline grouped by machine, showing the plan accepted by the factory](https://www.imranjan.cn/images/projects/byof-agent-2026/timeline.png)

Production timeline: each batch’s operations by machine, with an export of the day’s dispatch list.

![Execution log showing five resupply measures, SGD 1,200 of new cash and the accepted-by-factory status](https://www.imranjan.cn/images/projects/byof-agent-2026/execution.png)

Execution log: approval time, the five resupply measures, SGD 1,200 of new cash and the factory’s acceptance of the plan.

## Engineering

BYOF has one agent; everything else is deterministic services. Each turn the model returns a single JSON action chosen from 13 registered ones, such as querying data, comparing options or replying to the manager. The server validates the action before running it; if the format is wrong, the model is told only where the error is and gets one chance to correct it. Text coming back from the model is always treated as untrusted data and can’t change any record directly.

The agent runs on LangGraph with session state in PostgreSQL. While a solve is running the session is suspended, and it resumes when the result is written back. Model requests, time and solves per turn are all capped so the agent can’t loop forever.

### From a change to the factory’s confirmation

![Sequence diagram from a disruption to factory acceptance](https://www.imranjan.cn/images/projects/byof-agent-2026/disruption-flow.png)

Sequence diagram from our technical document: one change from investigation and approval to factory acceptance. Accepting a plan is not the same as finishing production.

1. #### Investigate and compare
When the manager opens a change, the business worker refreshes the factory data, takes a snapshot and asks the model for the next step. Option comparison goes onto the solver queue and the session saves a checkpoint and waits. When results are written back, the session wakes up and the model writes the recommendation.
2. #### Manager approval
An approval must pass role, CSRF and freshness checks; options older than 15 minutes have to be recomputed. Then the measures, spend and delivery scope are frozen and a queued entry is added to the execution ledger.
3. #### Execute and confirm
Execution moves in stages: re-read the shop floor and confirm nothing changed; send the resupply with a stable request ID; re-solve and require a passing check within the approved scope; release the plan and wait for the factory’s receipt. Any failure stops and goes back to the manager.

### Key design choices

##### An independent checker

Scheduling uses OR-Tools CP-SAT with constraints for operation order, full-batch material availability, no overlap on machines or workers, skills, shifts and the freeze window. The checker is a separate thousand-plus lines that never imports the solver and re-derives every constraint from the raw snapshot. Only a plan that passes can be approved or released.

[Read the checker](https://github.com/narmi924/byof-agent/blob/main/packages/planning/checker.py)

##### Approval separate from execution

Chat and approval are separate paths. Approval on an option card freezes the measures, spend and delivery scope. If the shop floor changes during execution, or the new schedule falls outside what was approved, the system stops instead of widening the scope.

[Read the execution flow](https://github.com/narmi924/byof-agent/blob/main/packages/agent/treatment%5Fexecution.py)

##### No double orders

Every execution stage is persisted. Commands to the factory carry a stable request ID, retries reuse it and the factory deduplicates on it. If a receipt is lost, the system looks up the original request instead of buying material twice.

[Read the recovery test](https://github.com/narmi924/byof-agent/blob/main/tests/test%5Fpublication%5Fretry%5Frecovery.py)

### Tech stack

#### Agent and backend

PythonFastAPILangGraphDeepSeek

#### Scheduling and data

OR-Tools CP-SATPostgreSQLSQLAlchemyAlembic

#### Frontend

ReactTypeScriptViteTailwind CSS

#### Deployment and testing

Docker ComposeAWS LightsailpytestGitHub Actions

The backend has about 1,870 test cases, with 45 test files running against a real PostgreSQL; the frontend has about 300\. Every push runs lint, type checks and the full test suite on GitHub Actions, then starts the whole container stack for a smoke test.

## My Role

As team lead I split the work and reviewed and merged code. On the development side I mainly looked after the following.

### Scheduling and checking

The CP-SAT scheduling model, covering operation order, full-batch material availability, machine and worker occupancy, shifts and the freeze window; and the checker that never imports the solver and re-checks every constraint from raw data.

### The simulated factory

The minute-by-minute factory simulator and its interface, where teammates could change orders, stop machines or mark workers absent to see how the agent reacted.

### Agent and execution

Added action validation and call budgets on top of the first agent skeleton; later the option pricing, approve-and-execute flow and execution ledger, and tracking down issues such as infeasible solves after a stoppage and slow option comparison.

### Interface and presentation

Designed the manager interface through several rounds of changes; designed the BYOF logo and made the 15-second intro film.

## Demo & Submission

The full demo video walks through the reference factory’s products, materials and operations, then the rush order and its resupply, and how the agent proposes a new due date when the original can’t be met.

[![BYOF factory simulator with order SO-003 changed to 1,500 pieces](https://www.imranjan.cn/images/projects/byof-agent-2026/simulator.png)Watch the full demoOpens on YouTube](https://www.youtube.com/watch?v=Ul6LUf-bLsM)

[Live demo: manager](https://byof.site/agent/chat)
[Live demo: factory simulator](https://byof.site/factory/facts)
[Business proposal (PDF)](https://www.imranjan.cn/downloads/byof-agent-2026/business-proposal.pdf)
[Technical document (PDF)](https://www.imranjan.cn/downloads/byof-agent-2026/technical-document.pdf)
[Letter of participation (PDF)](https://www.imranjan.cn/downloads/byof-agent-2026/participation.pdf)

The live demo needs both windows open: create a change in the simulator, then handle it as the manager. The demo environment may not stay online.

## Other pages

- [Home](https://www.imranjan.cn/index.md)
- [About me](https://www.imranjan.cn/about.md)
- [Projects](https://www.imranjan.cn/projects.md)
- [Photography](https://www.imranjan.cn/gallery.md)
- [LCIMS Cloud](https://www.imranjan.cn/projects/p-lcims.md)
- [imranjan.cn](https://www.imranjan.cn/projects/p-portfolio.md)
- [Open-source tools](https://www.imranjan.cn/projects/p-open-source.md)
- [Gatehouse](https://www.imranjan.cn/projects/p-gatehouse.md)
- [PlusOne](https://www.imranjan.cn/projects/p-plusone.md)
- [Gantry](https://www.imranjan.cn/projects/p-gantry.md)
- [Shopping Copilot by KI](https://www.imranjan.cn/projects/p-shopping-copilot.md)
- [Look2Act](https://www.imranjan.cn/projects/p-look2act.md)
- [AccessAudit - On-Chain Access Approval & Audit System](https://www.imranjan.cn/projects/p-accessaudit.md)
- [Eye Touch - Real-time Eye Tracking and Gaze Control System](https://www.imranjan.cn/projects/p-eyetouch.md)
- [China Collegiate Computer Competition—Mobile Application Innovation Contest](https://www.imranjan.cn/projects/p-yigui.md)
- [Nilufar Restaurant Expense Management System](https://www.imranjan.cn/projects/p-nilufar.md)
- [Voice-Interactive LED Light Panel](https://www.imranjan.cn/projects/p-led.md)
- ["Mengsheng Cup" Electronic Design Competition](https://www.imranjan.cn/projects/p-msb.md)
- [NUS SOC SWS 2024](https://www.imranjan.cn/projects/p-nus.md)

中文版本：https://www.imranjan.cn/zh/projects/p-byof-agent.md
