Content
# Manufacturing Quality Analysis NLP Agent
**Manufacturing Intent Routing, MCP Tools, Evidence, and FastAPI**
> A manufacturing data analysis agent project that classifies natural language questions into intents and executes necessary analysis tools to return **answers and evidence**.
<p>
<img src="https://img.shields.io/badge/Python-3.11-3561D8?style=flat-square&logo=python&logoColor=white" alt="Python">
<img src="https://img.shields.io/badge/FastAPI-Agent%20API-21AFC4?style=flat-square&logo=fastapi&logoColor=white" alt="FastAPI">
<img src="https://img.shields.io/badge/LangGraph-Workflow-151F32?style=flat-square" alt="LangGraph">
<img src="https://img.shields.io/badge/FastMCP-4%20Tools-3561D8?style=flat-square" alt="FastMCP">
<img src="https://img.shields.io/badge/Docker-GitHub%20Actions-5F6675?style=flat-square&logo=docker&logoColor=white" alt="Docker and GitHub Actions">
</p>
---
## Why This Project
Manufacturing site questions are input in natural language, but each question requires different data and calculation methods.
- Defect rate questions require aggregating production volume and defective quantity.
- Sensor anomaly questions require checking temperature, vibration, and pressure records.
- Line status questions require summarizing productivity and quality information together.
- Cause candidate questions combine defect rate and sensor anomaly information without determining the actual cause.
## Project Overview
| Category | Content |
|---|---|
| **Period** | 2026.04–05 |
| **Type** | Personal project |
| **Goal** | Connect manufacturing natural language questions to analysis functions and return answers with evidence data |
| **Scope** | Sample manufacturing data, rule-based intents, router, LangGraph, 4 analysis tools, FastMCP server, FastAPI, JSONL trace, PyTorch model endpoint, Docker, GitHub Actions, pytest |
| **NLP Scope** | Classify natural language questions into 4 intents and determine processing paths |
| **Technologies** | Python, FastAPI, Pydantic, LangGraph, MCP FastMCP, pandas, SQLite, PyTorch, Docker, GitHub Actions |
| **Implementation Results** | 4 intents, 4 agent tools, 4 MCP tools, 3 API endpoints, 9 core tests |
---
## Problem → Implementation → Result
| Problem | Implementation | Result |
|---|---|---|
| Different calculation methods for each question | Separate intents and routers for functional tools | Connect 4 question types to 4 manufacturing analysis functions |
| Difficulty verifying answers alone | Tools return summaries and evidence rows | Confirm answers and calculation evidence in API responses |
| Multiple purposes can change routing | Apply classification priorities for cause, productivity, defect, and sensor | Specify complex question processing rules in code |
| Confusion between agent API and MCP | Agent directly calls Python tools, MCP exposes same functions as separate interfaces | Separate internal execution and external tool interface responsibilities |
| Rule-based tools and model endpoints seem integrated | Independent configuration of `/agent/query` and `/model/sensor-anomaly` | Distinguish data aggregation and PyTorch inference scopes |
| Difficulty verifying execution environments | Configure sample data generation, pytest, Docker, and GitHub Actions | Provide local, container, and CI execution paths |
---
## System Overview
<img src="./docs/assets/mcp-system-overview.png" alt="Manufacturing Quality Analysis NLP Agent System Configuration" width="100%">
### Responsibility Separation
| Layer | Responsibility |
|---|---|
| **Intent** | Classify question purposes into `defect_rate`, `machine_anomaly`, `line_performance`, `quality_issue_candidates` |
| **Router** | Connect intents to Python tool function names |
| **Manufacturing Tool** | Execute CSV loading, date filtering, grouping, and aggregation |
| **Answer Builder** | Use tool summaries as final answers |
| **Evidence** | Structure calculation rows and aggregation results |
| **JSONL Trace** | Record question, intent, tool, evidence count, and status |
| **FastMCP Server** | Expose same 4 tool functions as MCP interfaces |
| **Model API** | Return reconstruction error and anomaly status for 3 sensor values |
### Scope Clarification
- Basic data paths for agent tools are CSV files.
- SQLite schema and loader are included but not connected to current agent tool execution paths.
- Current answers are not generated by external LLMs but use verified tool summaries.
- PyTorch model endpoint is independent of agent's `machine_anomaly` tool.
---
## Practical Evaluation Criteria
The agent project should be evaluated based on **routing, tool contracts, evidence, execution tracing, and interface responsibility separation**, rather than a single accuracy metric.
| Practical Perspective | Evaluation Criteria | Project Evidence |
|---|---|---|
| **Routing Consistency** | Representative questions connected to correct intents and tools | 4 intent-based agent flow tests |
| **Tool Result Stability** | Each tool returns summaries and evidence | 4 manufacturing analysis tool tests |
| **Response Verifiability** | Answers can be verified with evidence | Structured `question`, `intent`, `tool_name`, `answer`, `evidence` |
| **Tool Contract Clarity** | MCP tool names, descriptions, and inputs are distinguished | FastMCP 4 tools, `days` argument |
| **Execution Tracing** | Questions are processed by specific tools | `logs/agent_trace.jsonl` |
| **Responsibility Separation** | Actual call relationships between agent, MCP, and model are accurate | Direct agent calls, separate MCP server, independent model endpoint |
| **Reproducibility** | Sample data and tests can be executed under same conditions | Python 3.11 CI, Docker, GitHub Actions |
| **Scope Explanation** | Rule-based classification and cause candidates are not exaggerated | No external LLM, candidate expression, model limitations stated |
> Current public tests include 4 agent flow tests, 4 tool tests, and 1 PyTorch service test. FastAPI endpoint integration tests and MCP protocol integration tests are not implemented.
---
## Intent and Tool Mapping
| Intent | Agent Tool | MCP Tool | Question Example |
|---|---|---|---|
| `defect_rate` | `get_defect_rate_by_line` | `defect_rate_by_line` | What is the line with the highest defect rate in the last 7 days? |
| `machine_anomaly` | `detect_machine_anomalies` | `machine_anomalies` | Are there any sections with abnormally high temperature, vibration, or pressure? |
| `line_performance` | `summarize_line_performance` | `line_performance` | Summarize line productivity and quality status. |
| `quality_issue_candidates` | `infer_quality_issue_candidates_tool` | `quality_issue_candidates` | Provide data-based evidence for potential quality issue causes. |
### Routing Priority
```text
01. Cause, candidate, why + defect, quality, anomaly
→ quality_issue_candidates
02. Productivity, production volume, line-wise, summary, performance
→ line_performance
03. Defect, defect rate
→ defect_rate
04. Temperature, vibration, pressure, sensor, anomaly
→ machine_anomaly
05. No match
→ line_performance
```
---
## Agent Workflow
<img src="./docs/assets/mcp-agent-workflow.png" alt="Manufacturing Quality Analysis NLP Agent Workflow" width="100%">
| Step | Actual Processing |
|---|---|
| **Question** | FastAPI receives natural language questions |
| **Classify** | `classify_intent()` determines rule-based intents |
| **Route** | `tool_map` connects intents to Python tool functions |
| **Analyze** | Selected tools execute with `days=7` for CSV aggregation |
| **Return** | Summaries are used as answers, and aggregation rows are used as evidence, with trace records |
> `PromptTemplate` structures answer policies but does not currently call external LLMs. If there is no evidence, a lack of evidence notice is returned.
---
## Technical Details
<details open>
<summary><b>01 | Agent State and LangGraph</b></summary>
<br>
```text
question
→ intent
→ tool_name
→ tool_result
→ answer
→ evidence
```
```text
route_question
→ call_tool
→ build_answer
→ END
```
Currently, intents are rule-based and do not involve LLM training or final numerical answer generation.
</details>
<details>
<summary><b>02 | Manufacturing Data and Tools</b></summary>
<br>
| Data | Purpose |
|---|---|
| `production_logs.csv` | Line-wise production volume and operating time |
| `quality_inspection.csv` | Inspection quantity, defective quantity, and defect type |
| `machine_sensor_logs.csv` | Temperature, vibration, and pressure sensor records |
```text
CSV Loading
→ Date Range Filtering
→ Line Grouping
→ Sum and Mean Aggregation
→ Defect Rate Calculation
→ Threshold-based Sensor Check
→ Evidence Row Construction
```
Quality issue candidates do not determine actual causes but suggest priority checks by combining defect rates and sensor anomalies.
</details>
<details>
<summary><b>03 | FastMCP Server</b></summary>
<br>
```python
mcp = FastMCP("manufacturing-mcp-agent")
@mcp.tool()
def defect_rate_by_line(days: int = 7) -> dict:
return get_defect_rate_by_line(days=days)
@mcp.tool()
def machine_anomalies(days: int = 7) -> dict:
return detect_machine_anomalies(days=days)
@mcp.tool()
def line_performance(days: int = 7) -> dict:
return summarize_line_performance(days=days)
@mcp.tool()
def quality_issue_candidates(days: int = 7) -> dict:
return infer_quality_issue_candidates_tool(days=days)
```
The MCP layer uses the same Python tool functions without duplicating analysis logic.
</details>
<details>
<summary><b>04 | Independent PyTorch Model API</b></summary>
<br>
```text
temperature, vibration, pressure
→ Linear(3 → 2)
→ ReLU
→ Linear(2 → 3)
→ Reconstruction Error
→ Threshold 1000.0
→ is_anomaly
```
The `SensorAutoEncoder` is currently generated with default initialization without trained weights. This endpoint demonstrates a minimal model serving structure and response schema, but it does not imply verified anomaly detection performance.
</details>
<details>
<summary><b>05 | Validation and CI</b></summary>
<br>
```text
tests/test_agent_flow.py 4 cases
tests/test_tools.py 4 cases
tests/test_torch_model.py 1 case
```
GitHub Actions perform dependency installation, sample data generation, and pytest execution in a Python 3.11 environment.
</details>
---
## API
| Method | Endpoint | Role |
|---|---|---|
| `GET` | `/` | Service status and endpoint guidance |
| `POST` | `/agent/query` | Connect natural language questions to intents and tools |
| `POST` | `/model/sensor-anomaly` | Calculate reconstruction error for 3 sensor values |
### POST `/agent/query`
```json
{
"question": "Find the line with the highest defect rate over the last 7 days."
}
```
```json
{
"question": "Find the line with the highest defect rate over the last 7 days.",
"intent": "defect_rate",
"tool_name": "get_defect_rate_by_line",
"answer": "The line with the highest defect rate over the last 7 days is LINE_C.",
"evidence": [
{
"line_id": "LINE_C",
"output_qty": 1234,
"defect_qty": 54,
"avg_defect_rate": 0.0439
}
]
}
```
### POST `/model/sensor-anomaly`
```json
{
"temperature": 95.7,
"vibration": 5.6,
"pressure": 2.4
}
```
```json
{
"temperature": 95.7,
"vibration": 5.6,
"pressure": 2.4,
"anomaly_score": 1023.5,
"threshold": 1000.0,
"is_anomaly": true,
"model": "SensorAutoEncoder",
"note": "Reconstruction error based anomaly result"
}
```
> API example values are for illustrating the Response structure.
## Run and Verify
```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r .\requirements.txt
python .\scripts_generate_sample_data.py
python -m uvicorn app.main:app --reload
```
MCP Server:
```powershell
python -m app.mcp_server.server
```
Tests:
```powershell
python -m pytest .\tests -q
```
Docker:
```powershell
docker compose up --build
```
## Project Structure
```text
manufacturing-mcp-agent/
├── .github/workflows/ci.yml
├── app/
│ ├── agent/
│ ├── db/
│ ├── mcp_server/
│ ├── models/
│ ├── services/
│ ├── config.py
│ └── main.py
├── data/
├── docs/assets/
├── langflow/
├── tests/
├── Dockerfile
├── docker-compose.yml
├── pytest.ini
├── requirements.txt
├── scripts_generate_sample_data.py
└── README.md
```
## Current Scope and Limitations
### Current Scope
- Public manufacturing sample data
- Rule-based 4 Intent Classification
- LangGraph 3 Node Workflow
- pandas-based manufacturing data aggregation
- Answer and Evidence Response
- FastMCP Server 4 Tools
- JSONL Agent Trace
- FastAPI Agent Endpoint
- Independent PyTorch Model Endpoint
- Docker and GitHub Actions
### Limitations
- Does not call external LLM
- No Intent evaluation Dataset and Confusion Matrix
- Analysis period of `/agent/query` is fixed to `days=7`
- Agent API does not call MCP Server through MCP Client
- SQLite is not connected to the current Agent Tool execution path
- PyTorch AutoEncoder does not use trained weights
- No integrated test for FastAPI and MCP Protocol
- No authentication, authorization, timeout, audit, and monitoring
- Cause candidates are rule-based inspection targets, not actual cause diagnosis
### Next Steps
1. Add Intent answer Dataset and Confusion Matrix
2. Compare rule-based Intent and LLM Structured Intent
3. Extend `days` and Tool Argument to Request Schema
4. Add integrated test for FastAPI, MCP Protocol, and Docker Build
5. Connect SQLite to Tool Data Source or execution history
6. Implement Model Training, Scaling, and Validation Threshold
7. Add Tool Timeout, Audit Log, and access control
## What This Project Demonstrates
- Experience with classifying natural language manufacturing questions into rule-based Intent
- Experience with separating processing steps using LangGraph State and Node
- Experience with separating responsibilities of Intent, Router, Tool, and Answer Builder
- Experience with pandas-based manufacturing data filtering and aggregation
- Experience with designing API Response that distinguishes Answer and Evidence
- Experience with reusing the same Python Tool in Agent and MCP Interface
- Experience with distinguishing actual scope of Agent API and Model Endpoint
- Experience with configuring execution and verification paths using JSONL Trace, Docker, and GitHub Actions
## Contact
- Developer:
- GitHub: https://github.com/lightleaping
- Email: workingskyroad@gmail.com
MCP Config
Below is the configuration for this MCP Server. You can copy it directly to Cursor or other MCP clients.
mcp.json
Connection Info
You Might Also Like
No recommendations available