Inspiration

In an automotive-component plant, the end-of-line (EOL) test is the last gate before a part ships. When one tester's failure rate suddenly jumps from about 2 % to about 18 %, a quality engineer has to answer a hard question quickly: are the parts really bad, is the tester measuring wrong, or did the product mix on that tester simply change?

The data needed to answer it is spread across separate systems: MES for orders, serial numbers and recipes, equipment monitoring for tightening torque, angle and program versions, and EOL test for measurements and reference samples. Engineers export spreadsheets and correlate them by hand. The costly mistake is not a missing chart. It is a confident early verdict that scraps good parts or ships bad ones.

Most "AI for manufacturing" demos stop at explaining what might have happened. We wanted an assistant that also says what to check next, waits for the engineer's approval, and changes its mind when the evidence says so.

What it does

Factory CSI investigates an EOL quality anomaly on a fictional production line (Factory Alpha, Line A: ST-10 → ST-20 → ST-30 → EOL-A / EOL-B):

  1. Detects the anomaly statistically. For each tester it compares the last 3 hours with the first 2 hours of the shift: $$\text{flag}(t) \iff p_{\text{Fisher}}(t) < 0.01 \;\wedge\; r_{\text{window}}(t) \ge 2\cdot\max\big(r_{\text{baseline}}(t),\,0.5\%\big)$$
  2. Collects cross-system evidence through MCP. Our Industrial MCP Server exposes the simulated MES / equipment / EOL systems as 8 tools. The agent's tool calls are visible live in the UI.
  3. Grounds every claim in evidence. Deterministic Python computes the statistics: Fisher, Kolmogorov–Smirnov, Mann–Whitney, OLS trends, stratification by product model and mix shift. Each finding becomes an Evidence item (EV-007) that links to raw records. The LLM may only cite existing Evidence IDs.
  4. Proposes the Next Best Verification. It ranks up to three simulated checks (cross retest on the other tester, reference sample check, process configuration audit) and states how each possible outcome would support or contradict each hypothesis.
  5. Human in the loop. The engineer approves, rejects all with a reason, or concludes. Approved checks run in the simulator, return new evidence, and the agent records an explicit judgment change such as Tester drift: Medium → High, because EV-019.
  6. Writes a traceable 10-section report with timeline, evidence, verifications, judgment changes and the suspected affected product scope. It always uses "suspected" or "evidence-supported" wording, never "confirmed root cause".

How we built it

  • Kiro, spec-driven. We wrote 7 specs (simulator, MCP server, investigation engine, verification loop, API, UI, delivery) with 144 EARS requirements, then a cross-spec consistency pass. That pass found real conflicts before any code existed. For example, Scenario C's signal was too weak for our own detector to fire, and an LLM budget of 25 calls allowed only one verification round in the worst case. Steering files hold the rules: no fallback text, ground-truth isolation, citation rules. Three hooks run related tests and ruff on every Python save, tsc and eslint on every frontend save, and a secret guard on every save. The same MCP server is registered for Kiro's own agent.
  • Simulator with a hidden truth. A seed-reproducible generator writes three artifacts per scenario:
    • factory.db, the observable systems;
    • world_state.json, the hidden physics, read only by the verification engine;
    • ground_truth.json, the answer key for tests and evaluation only.

Import-linter contracts make it impossible for the backend or MCP server to import the answer key. Measurements follow a normalized model: $$z = \frac{v - m}{h},\qquad z_{\text{meas}} = z_{\text{true}} + b_{\text{tester}}(t) + \varepsilon,\quad \varepsilon \sim \mathcal{N}(0,\,0.1^2)$$ Here $m$ is the midpoint and $h$ the half-width of the limits ($|z|\le 1$ passes). Tester drift is $b(t)=\beta\,\max(0,\,t-t_0)$.

  • Agent: a LangGraph StateGraph with 11 nodes, interrupt()-based approval and SQLite checkpoints. LiteLLM provides model access (default deepseek/deepseek-flash; switching provider only means editing .env). The model returns JSON validated by Pydantic, with at most 2 repair attempts.
  • Guardrails in code, not just prompts:
    • unknown citations trigger a repair, then are dropped;
    • High needs a verification result;
    • Medium or above needs evidence that directly shows the mechanism;
    • budgets of 20 MCP calls, 40 LLM calls and 3 verification rounds;
    • if the LLM fails, the case pauses and can resume from its checkpoint. No canned text is ever shown.
  • App: FastAPI with Server-Sent Events, a React + TypeScript + ECharts workspace (English / Chinese) and Docker Compose.

Challenges we ran into

  • Designing ambiguity on purpose. Each scenario had to be statistically detectable but still need verification. Scenario C's apparent tester problem is really a product-mix shift with a missing reference sample. We added a "no-flip" rule (measurement noise never changes the pass/fail class of $z_{\text{true}} + b$) and searched seeds against the spec's own acceptance criteria.
  • Keeping the LLM honest. Our first full evaluation put one Scenario C run at Process deviation: Medium based only on the failure-rate rise. We fixed it in code: every finding now carries a mechanism tag, and support of Medium or higher requires one. After that, all 9 runs ended in an acceptable conclusion.
  • New SDK versions. MCP Python SDK 2.x renamed FastMCP to MCPServer, and LangGraph 1.x was new to us. We probed both APIs with small scripts before building on them.
  • Real bugs found by real runs:
    • an SSE stream that never closed because one event followed completed;
    • a LangGraph node wrapper that returned a coroutine;
    • an over-long LLM answer that tested our retry-from-checkpoint path for us.

Accomplishments that we're proud of

  • The full loop works end to end with a real LLM: anomaly → MCP evidence → hypotheses → next best verification → human approval → simulated check → judgment change → traceable report.
  • The agent cannot cheat. The answer key and hidden physics are isolated by import contracts and an audit-hook test, so the agent only knows what the MCP tools return.
  • It knows when to say "not enough evidence". In Scenario C it never claims a tester or process cause with high support.
  • One command to run: make docker-up. The UI is in English and Chinese.

On 3 scenarios × 3 runs with the real DeepSeek API, scored against the hidden answer key:

  • anomaly detection 9/9;
  • acceptable conclusion 9/9;
  • complete reports 9/9;
  • citation validity 1.0;
  • verification outcomes matching ground truth 1.0;
  • about 1 minute and about US$0.012 per investigation.

The test suite has 66 deterministic tests, 11 frontend tests and 4 real-LLM tests. This is a small synthetic benchmark, not evidence of production-grade accuracy.

What we learned

  • Splitting the work so that code computes and the model interprets is what makes an industrial agent auditable.
  • The most useful thing an assistant can say is often "run this check next, and here is what each result would mean", not "the root cause is X".
  • Writing requirements first, including measurable acceptance criteria for the simulator, turned "make the demo convincing" into tests we could actually run.

What's next for FactoryCSI

Connect real MES / QMS / test systems through MCP, add more failure modes (fixture wear, firmware changes, material lots), produce AI output in Chinese with matching guardrails, and add authentication for a hosted demo.

Built With

Share this project:

Updates

Submission history