Skip to content

RishavAr/FactoryOps-AI-Agent

Repository files navigation

🏭 FactoryOps AI Agent

On-Site Manufacturing Co-Pilot — A local-first AI agent system deployed inside factories to help operators, supervisors, and managers make decisions in real time.

TypeScript Next.js SQLite License


📋 Table of Contents


🎯 Overview

FactoryOps is a production-grade manufacturing intelligence platform that combines:

  • Real-time monitoring of production lines, machines, and sensors
  • AI-powered incident analysis with root cause detection
  • Natural language chat interface for operators on tablets
  • Auto-generated executive briefs for managers
  • Offline-first architecture for factory reliability

The system is designed to run on-premise within factory networks, ensuring data security and low-latency responses even without internet connectivity.


💥 Core Capabilities

🧑‍🏭 Operator Chat (Tablet UI)

Operators report issues in plain English. The AI agent:

  • Asks clarifying follow-up questions
  • Logs incidents automatically
  • Suggests safe, immediate actions
  • Provides step-by-step troubleshooting

⏱️ Downtime Root Cause Analysis

"Why did Line 2 stop at 3:40 PM?"

The agent correlates:

  • Machine sensor logs
  • Shift schedules
  • Historical machine performance
  • Recent similar incidents

📊 Live Production Dashboard

Real-time visibility into:

  • Bottlenecks and delays
  • Machine efficiency by line
  • Cost impact of downtime
  • Sensor anomaly alerts

📋 Daily Manager Brief (Auto-Generated)

Every morning, managers receive:

  • Production summary vs. targets
  • Estimated loss calculations
  • Risk identification
  • Prioritized action items

🛠️ Tech Stack

Category Technology
Frontend Next.js 14 + React 18 + TypeScript
Styling Tailwind CSS + Custom Industrial Theme
State Management Zustand
Charts Recharts
Database SQLite (better-sqlite3)
Real-time Server-Sent Events (SSE)
AI Agent Custom reasoning engine (Plan → Act → Verify)

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                      FRONTEND (Next.js)                     │
├─────────────────────────────────────────────────────────────┤
│  Dashboard  │  Operator Chat  │  Incidents  │  Manager Brief│
├─────────────────────────────────────────────────────────────┤
│                    Zustand State Store                       │
│                    Custom React Hooks                        │
└───────────────────────────┬─────────────────────────────────┘
                            │
                   ┌────────▼────────┐
                   │   API Routes    │
                   │  (Next.js API)  │
                   └────────┬────────┘
                            │
        ┌───────────────────┼───────────────────┐
        │                   │                   │
        ▼                   ▼                   ▼
┌───────────────┐  ┌───────────────┐  ┌───────────────┐
│   SQLite DB   │  │   AI Agent    │  │   SSE Stream  │
│   (Machines,  │  │  (Reasoning   │  │  (Real-time   │
│   Incidents,  │  │   Engine)     │  │   Updates)    │
│   Downtime)   │  │               │  │               │
└───────────────┘  └───────────────┘  └───────────────┘

AI Agent Reasoning Loop

┌──────────────────────────────────────────────────────────────┐
│                    AGENT REASONING LOOP                      │
├──────────────────────────────────────────────────────────────┤
│                                                              │
│   ┌─────────┐   ┌─────────┐   ┌───────────┐   ┌──────────┐ │
│   │ OBSERVE │ → │ ANALYZE │ → │ CORRELATE │ → │RECOMMEND │ │
│   │         │   │         │   │           │   │          │ │
│   │ Gather  │   │ Pattern │   │ Cross-ref │   │ Generate │ │
│   │ context │   │ match   │   │ history   │   │ actions  │ │
│   └─────────┘   └─────────┘   └───────────┘   └────┬─────┘ │
│                                                     │       │
│                                                     ▼       │
│                                              ┌──────────┐   │
│                                              │  VERIFY  │   │
│                                              │          │   │
│                                              │Calculate │   │
│                                              │confidence│   │
│                                              └──────────┘   │
└──────────────────────────────────────────────────────────────┘

🚀 Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/yourusername/factoryops-ai-agent.git
cd factoryops-ai-agent

# Install dependencies
npm install

# Seed the database with sample data
npm run db:seed

# Start development server
npm run dev

Open http://localhost:3000 in your browser.

Production Build

npm run build
npm start

📁 Project Structure

factoryops/
├── src/
│   ├── agents/
│   │   └── factory-agent.ts    # AI reasoning engine
│   ├── components/
│   │   ├── Dashboard.tsx       # Real-time metrics dashboard
│   │   ├── OperatorChat.tsx    # Tablet-friendly chat UI
│   │   ├── IncidentsView.tsx   # Incident list & detail
│   │   ├── ManagerBrief.tsx    # Auto-generated daily report
│   │   └── Layout.tsx          # App shell with navigation
│   ├── db/
│   │   ├── index.ts            # Database operations
│   │   └── seed.ts             # Sample data generation
│   ├── hooks/
│   │   └── useData.ts          # Custom data hooks + SSE
│   ├── pages/
│   │   ├── api/
│   │   │   ├── machines/       # Machine CRUD
│   │   │   ├── incidents/      # Incident management
│   │   │   ├── chat/           # AI chat endpoint
│   │   │   ├── metrics/        # Dashboard data
│   │   │   ├── downtime/       # Downtime tracking
│   │   │   ├── brief/          # Daily brief generation
│   │   │   └── events/         # SSE endpoint
│   │   ├── _app.tsx
│   │   ├── _document.tsx
│   │   └── index.tsx
│   ├── styles/
│   │   └── globals.css         # Industrial dark theme
│   ├── types/
│   │   └── index.ts            # TypeScript definitions
│   └── utils/
│       └── store.ts            # Zustand state management
├── package.json
├── tsconfig.json
├── tailwind.config.js
└── README.md

📡 API Reference

Machines

Endpoint Method Description
/api/machines GET List all machines
/api/machines?id={id} GET Get machine by ID
/api/machines PATCH Update machine status

Incidents

Endpoint Method Description
/api/incidents GET List incidents (with filters)
/api/incidents?id={id} GET Get incident details
/api/incidents POST Create new incident
/api/incidents PATCH Update incident

Chat

Endpoint Method Description
/api/chat POST Send message to AI agent

Request Body:

{
  "message": "Machine is making a grinding noise",
  "incidentId": "optional-existing-id",
  "machineId": "optional-machine-id"
}

Response:

{
  "success": true,
  "data": {
    "message": "I've noted your report...",
    "thoughts": [...],
    "suggestedActions": ["Check bearings", "Verify lubrication"],
    "incidentId": "created-incident-id",
    "incidentCreated": true
  }
}

Metrics

Endpoint Method Description
/api/metrics GET Dashboard metrics
/api/metrics?type=lines GET Line statuses
/api/metrics?type=trend&hours=24 GET Production trend

Real-time Events

Endpoint Method Description
/api/events GET (SSE) Subscribe to real-time updates

Event Types:

  • metrics - Updated dashboard metrics
  • lines - Line status changes
  • incidents - New/updated incidents
  • alert - System alerts

Daily Brief

Endpoint Method Description
/api/brief GET Get today's brief
/api/brief?date=YYYY-MM-DD GET Get brief for date
/api/brief POST Generate new brief

🤖 AI Agent System

The FactoryOps AI Agent uses a Plan → Act → Verify reasoning loop:

1. OBSERVE

  • Gather incident context
  • Extract keywords from operator reports
  • Identify relevant machine and sensor data

2. ANALYZE

  • Match against known failure patterns:
    • Temperature issues
    • Vibration anomalies
    • Pressure problems
    • Electrical faults
    • Mechanical failures
    • Quality defects

3. CORRELATE

  • Cross-reference with machine history
  • Identify time-based patterns (shift correlation)
  • Analyze sensor readings for anomalies

4. RECOMMEND

  • Generate prioritized actions
  • Assign to appropriate personnel
  • Estimate impact of each recommendation

5. VERIFY

  • Calculate confidence scores
  • Assess risk levels
  • Generate summary for stakeholders

⚡ Real-Time Updates

The system uses Server-Sent Events (SSE) for real-time dashboard updates:

// Client-side subscription
const eventSource = new EventSource('/api/events');

eventSource.addEventListener('metrics', (event) => {
  const data = JSON.parse(event.data);
  updateDashboard(data);
});

eventSource.addEventListener('alert', (event) => {
  const alert = JSON.parse(event.data);
  showNotification(alert);
});

Updates are pushed every 5 seconds for:

  • Production metrics
  • Machine status changes
  • New alerts and incidents

📴 Offline-First Design

FactoryOps is built for factory reliability:

  1. Local SQLite Database - All data stored on-premise
  2. Service Worker Ready - Can cache critical assets
  3. Offline Queue - Actions queued when connectivity lost
  4. Sync on Reconnect - Automatic synchronization

The UI shows connection status and gracefully degrades when offline.


📸 Screenshots

Dashboard

Real-time production metrics with efficiency tracking, line status, and bottleneck identification.

Operator Chat

Tablet-optimized chat interface with suggested actions and incident tracking.

Incidents

Detailed incident view with AI analysis, root causes, and recommendations.

Manager Brief

Auto-generated daily report with KPIs, trends, and action items.


🔮 Future Enhancements

  • Integration with PLC/SCADA systems
  • Predictive maintenance ML models
  • Multi-factory support
  • Mobile app for on-the-go access
  • Voice input for operators
  • Shift handoff automation

📄 License

MIT License - see LICENSE for details.


🙏 Acknowledgments

Built with ❤️ for manufacturing excellence.

"Making factories smarter, one incident at a time."

About

On-Site Manufacturing Co-Pilot — A local-first AI agent system deployed inside factories to help operators, supervisors, and managers make decisions in real time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors