R&D prototype · open/synthetic data

Multi-Agent Manufacturing QC

TL;DR. An R&D system on one principle — the LLM orchestrates but never guards. Eleven LLM-driven agents inspect casting images and equipment-sensor data through a two-tier pipeline (a deterministic Fast Path for clear cases, a Goal-Driven ReAct loop for the rest); a rule-based guardrail — not another LLM — catches cross-agent contradictions and routes disagreement through a 2-round deliberation, escalating unresolved cases to a human, all on-prem on Ollama + RTX 3060 (one env var swaps to Claude or Gemini). Scope is stated up front: a single-machine architecture demo validated entirely on synthetic and open datasets — the engineering target is the orchestration, guardrails, and human-in-the-loop trace, not the underlying ML models.
11 LLM agents two-tier pipeline, one guardrail
1,150 passing tests 1,168 collected
~18k lines of code ~15k Python · ~3k TypeScript
$0 recurring API cost on-prem Ollama default
System architecture: 11 agents, 4-tier safety pipeline
System architecture — the 11 agents and the two-tier pipeline (Fast Path + Goal-Driven ReAct) all funnel into one deterministic guardrail, the only component that can route a case to PASS, deliberation, or a human. On-prem by default (Ollama qwen2.5:7b on an RTX 3060), one env var swaps to Claude or Gemini; agents communicate over MCP Streamable HTTP.

Problem

Manufacturing QC sits between two unsatisfying extremes: rule-based systems that go brittle as defect modes multiply, and end-to-end ML models that produce verdicts an operator cannot audit. What a real line needs is in between: a system that uses multiple narrow ML tools (PatchCore, AnomalyCLIP, XGBoost RUL) but treats their outputs as evidence to be cross-examined, not ground truth, and that escalates instead of silently choosing a tiebreaker when the tools disagree. That is the gap this project fills.

Positioning: rule-based vs end-to-end ML vs the cross-examined-evidence approach
Where this sits — rule-based QC goes brittle and end-to-end ML is unauditable; this project treats narrow ML tools (PatchCore, AnomalyCLIP, XGBoost RUL) as evidence to cross-examine, escalating to a human on disagreement.

What I built

  • Built end-to-end as the sole developer: the 11-agent orchestration, the guardrail and deliberation layers, the LLM-provider abstraction, the ML-tool wiring, and the React/TypeScript dashboard (the design choices behind each are below).
  • ML-tool wiring as evidence, not verdicts: PatchCore / AnomalyCLIP / Grounded-SAM2 for vision and XGBoost / Chronos for RUL, each wrapped as a tool whose output the agents cross-examine rather than trust.
  • Reviewable trace surfaced through a dashboard (ReAct Timeline, Cross-Agent Graph, Guardrail Log, Deliberation Trace, HITL queue, Metrics) so every verdict can be audited end to end.

Design decisions

  1. LLM is the orchestrator, never the guardrail

    Guardrail violations (physical_inconsistency, cross_agent_contradiction, low_confidence, tool_anomaly, cost_time_exceeded) are evaluated by deterministic Python rules in shared/guardrail.py. An LLM judging an LLM has no error floor; a rule does. Keeping the safety net separate from the agent layer is non-negotiable. The same principle shapes the feedback loop: the Learning agent observes HITL approvals/rejections and suggests threshold deltas via analyze_hitl_history + suggest_threshold_adjustment, but the suggestion is never auto-applied. There is no DB write, no config write, no consumer that mutates state from a model output. An operator manually applies the change, which then takes effect in the next inspection's guardrail evaluation. The loop is half-closed on purpose: parameters adapt, rules and write-paths stay human-authored. Verified by grep: suggest_threshold_adjustment is referenced in only 6 files, all of them tests / stub / the tuner itself / the agent registry, with no consumer applying the suggestion.

    5 deterministic guardrail rules
    All five rules evaluated outside the LLM in shared/guardrail.py. Action column is the routed outcome (retry / deliberation / hitl / force_stop).
    HITL to Learning adaptive loop (half-closed)
    Half-closed feedback loop: Learning agent suggests, operator applies. No code path writes thresholds from a model output (verified by grep: suggest_threshold_adjustment has 6 references, all in tests / stub / tuner itself / agent registry, no consumer applies the suggestion).
  2. Two-tier speed: Fast Path before ReAct

    When an ML tool returns a confident result (PatchCore score > 0.9 or < 0.2, sensor |z-score| < 2), the agent skips the LLM entirely and returns the deterministic verdict in milliseconds. The expensive ReAct loop only fires when tools alone don't resolve the case. This collapses the median latency of clear cases without giving up the long-tail reasoning. The cheap path runs first by design, not as a fallback.

    ReAct Timeline showing tool failure recovery
    Case 2 - Tool failure recovery mid-loop: Plan -> Execute (patchcore_score) fails (model checkpoint missing) -> Replan -> Execute (anomaly_clip_classify) succeeds (scratch 0.7618) -> Execute (grounded_sam2_segment) -> Respond DEFECT 76% confidence.
    Two-tier execution funnel: Fast Path to ReAct to Deliberation to HITL
    Captured run on the inspection DB (N=10): 1 Fast Path (cold-start 113s), 4 Goal-Driven ReAct (2.3-26s), 4 Deliberation (5.3-33s), 6 reached HITL. The cheap path runs first by design, not as a fallback. Warm Fast Path latency is not yet benchmarked separately.
  3. Disagreement is a first-class state, not a failure

    When Recognition reports DEFECT and Prediction reports NORMAL, the system does NOT pick a tiebreaker. It enters a 2-round Deliberation Protocol: Round 1 each agent re-states a position with evidence; Round 2 each rebuts the other's claims; a synthesis node decides if there is consensus or escalates to HITL. The dashboard shows the full trace.

    Live Deliberation Trace from dashboard
    Live trace from the dashboard for the case above - NO CONSENSUS badge top-right.
    Deliberation Protocol: 2 rounds, no tiebreaker
    Deliberation Protocol for Case 3 — Recognition reported DEFECT and Prediction reported NORMAL, each at 0.95 confidence. Across 2 rounds neither agent moved, so synthesis returned NO CONSENSUS and escalated to a human; the live trace is the next screenshot.
  4. On-prem first

    Default config is Ollama running qwen2.5:7b locally on a 12 GB GPU, so inspection data never leaves the machine. The same code path swaps to Claude or Gemini by changing one env var (LLM_PROVIDER=claude|gemini|ollama). Data sovereignty is the constraint manufacturers in this domain raise most often, so positioning it as the default rather than the option was deliberate.

  5. Goal in the prompt, not how-to

    Every system prompt across all 11 agents follows the same skeleton: Domain -> Goal -> Available tools -> Constraints -> JSON output. Notably absent: instructions like 'if score > 0.5 then call SAM2', 'first call A then call B', or 'if confidence > 0.9 return early'. The LLM picks tools, sequence, and stop point, guided only by the goal text, the constraint list, and the tool results it observes. When the toolchain shifts (PatchCore -> FastFlow), only the Available tools block changes; the orchestration logic stays untouched. One mild exception: the Automation agent carries a single soft-ordering constraint (CRITICAL priority actions require HITL approval before execution).

    Goal-driven prompt anatomy: Recognition agent verbatim
    Recognition agent's SYSTEM_PROMPT dissected by region (Domain / Goal / Tools / Constraints / JSON). All 11 agents share this skeleton; one mild exception (Automation has a single line of soft sequencing). The right panel lists what is not in any prompt: no procedural branching, no tool ordering, no control flow.

In operation

HITL queue card for the escalated case
HITL queue card - both agent positions, sensor context, escalation rule, and Approve / Reject controls.
Operations page
Operations - inspection history, KPI strip, HITL approval queue. Each row is a real call against the running orchestrator on :8000.

Engineering foothold

ClaimEvidence
Pipeline agents: 11agents/{recognition,prediction,automation,spc,learning,optimization,safety,scheduling,supply_chain,communication,generation}/ — `ls -d agents/*/` returns exactly 11 directories
Tests: 1,150 passing (1,168 collected)Static count: 1,140 `def test_` functions across 42 test files + parametrize expansions = 1,168 collected; README states 1,150 passing (the remaining 18 skip because they need a live LLM).
Python source: ~15,000 LOC`find shared agents orchestrator -name '*.py' | xargs cat | wc -l` = 14,966 (117 files)
TypeScript source: ~3,000 LOC`find dashboard/src -name '*.ts' -o -name '*.tsx' | xargs cat | wc -l` = 3,011 (33 files)
Guardrail rules: 5 deterministic rulesshared/guardrail.py — _check_physical_inconsistency, _check_cross_agent_contradiction, _check_low_confidence, _check_tool_anomaly, _check_cost_time_exceeded (lines 52-193)
LLM provider abstraction: 3 (Claude / Gemini / Ollama)shared/llm_client.py — ClaudeLLMClient (anthropic.AsyncAnthropic, default claude-sonnet-4-20250514), GeminiLLMClient (google-genai), OllamaLLMClient; selectable via LLM_PROVIDER. (A StubLLMClient also exists for offline tests but is not a production provider.)
ML-tool benchmarks on synthetic/open dataresults/phase1_kpi.json — PatchCore AUROC 1.0000 and AnomalyCLIP AUROC 0.9850 on the synthetic casting set, XGBoost F1 0.9851 on the open AI4I-2020 dataset, Chronos-2 RMSE 40.29 on the open NASA C-MAPSS FD001 set.
Recurring API cost: $0 (Ollama on-prem default).env.example — LLM_PROVIDER=ollama, OLLAMA_MODEL=qwen2.5:7b (local, no API billing)
End-to-end captures: 8 dashboard verifications8 multi_agent_*.png in repo root (cross_agent_trace, deliberation, docker_ps, hitl, metrics, ops, react_trace, tech)
Benchmark scoreboard: PatchCore AUROC 1.0000 and AnomalyCLIP 0.9850 on a synthetic casting set, XGBoost F1 0.9851 on open AI4I-2020, Chronos-2 RMSE 40.29 on open NASA C-MAPSS FD001.
ML-tool benchmarks (results/phase1_kpi.json) on synthetic and open datasets — recorded honestly, because the engineering target is the orchestration layer, not these underlying models.
Metrics page
Metrics - agent confidence gauges (all 11 agents reported), latency distribution by tier, API cost trend, tier distribution.

Tech stack

Orchestration
LangGraph (StateGraph, conditional edges, checkpointing)
Inter-agent protocol
MCP Streamable HTTP, max_depth=2, call-stack circular detection
LLM
Ollama qwen2.5:7b (default, RTX 3060), Claude, Gemini (single-env-var swap via LLM_PROVIDER)
Vision
PatchCore (anomalib), AnomalyCLIP (open_clip ViT-B/32), Grounded SAM2
Time-series / RUL
XGBoost (AI4I-2020, open), Chronos (chronos-forecasting; C-MAPSS, open)
Vector DB
ChromaDB PersistentClient (embedded per-agent, no separate server)
API & runtime
FastAPI, uvicorn, async-everywhere, websockets
Frontend
React 18, TypeScript, Tailwind CSS, Recharts, Vite
Storage
SQLite (inspections, defect history)

Gallery

← All projects