Agentic AICrews + Flows: Combining CrewAI Patterns for Production-Grade Manufacturing Agents
CrewAI's basic crew pattern handles most simple manufacturing workflows. But production-grade deployments need more: conditional branching, parallel execution, error recovery, and state persistence. CrewAI Flows provide these capabilities.
Beyond Basic Crews
A basic CrewAI crew executes tasks sequentially or hierarchically. This works for:
- Linear diagnostic workflows (collect -> analyze -> act)
- Simple inspection pipelines (capture -> classify -> report)
But manufacturing reality is more complex:
- What if the diagnosis requires different actions for different root causes?
- What if multiple inspections need to run in parallel?
- What if a failure in one step requires restarting from an earlier step?
- What if the workflow needs to pause and wait for human approval?
Flows solve these problems.
CrewAI Flows Architecture
What Is a Flow?
A Flow chains multiple crews together with:
- Conditional routing -- Different paths based on crew outputs
- Parallel execution -- Multiple crews running simultaneously
- State management -- Persistent state shared across crews
- Error handling -- Retry logic, fallback paths, and graceful degradation
- Human-in-the-loop -- Pause points for human input or approval
Flow Components
- Start -- Entry point with initial state
- Crew nodes -- Each node is a crew that processes its tasks and produces output
- Router nodes -- Decision points that route to different crews based on conditions
- Join nodes -- Merge points that combine outputs from parallel crews
- Listen nodes -- Event-driven triggers that activate crews based on external events
Manufacturing Flow Patterns
Pattern 1: Diagnostic Flow with Branching
A maintenance diagnostic workflow that branches based on failure type:
Step 1: Symptom Collection Crew
- Data Agent reads all relevant sensor data
- History Agent queries maintenance records
- Output: Symptom package with all relevant data
Step 2: Diagnosis Crew
- Analysis Agent processes symptom package
- Output: Diagnosis with failure category (mechanical, electrical, process)
Step 3: Router -- Branch based on failure category:
- Mechanical -> Mechanical Repair Crew
- Electrical -> Electrical Repair Crew
- Process -> Process Adjustment Crew
Step 4: Specialized Crews
- Each crew follows domain-specific procedures
- Creates appropriate work orders or adjustments
- Output: Action plan with timeline and resource requirements
Step 5: Verification Crew
- Monitors post-action sensor data
- Verifies the issue is resolved
- If not resolved: routes back to Step 2 with additional context
Pattern 2: Parallel Quality and Maintenance
Monitoring that runs quality and maintenance assessments in parallel:
Parallel Crews:
- Quality Crew: Inspects current production for defects
- Maintenance Crew: Assesses equipment health
- Energy Crew: Evaluates current energy efficiency
Join Node:
- Combines findings from all three crews
- Identifies conflicts (e.g., quality wants higher speed, maintenance wants lower speed)
Arbitration Crew:
- Resolves conflicts based on priority rules
- Generates unified action plan
Pattern 3: Shift Management Flow
A comprehensive flow managing an entire production shift:
Start Trigger: Shift start event
Step 1: Shift Planning Crew
- Reviews production orders for the shift
- Checks equipment status and maintenance schedules
- Creates optimized production sequence
Step 2: Continuous Monitoring (Listen nodes)
- Equipment Health Listener: Triggers maintenance crew when anomaly detected
- Quality Alert Listener: Triggers quality investigation crew when SPC breach occurs
- Schedule Deviation Listener: Triggers re-scheduling crew when behind plan
Step 3: Shift End Crew
- Calculates shift KPIs (OEE, quality, energy)
- Creates handover report
- Identifies carryover items for next shift
State Management
Flows maintain persistent state across crews:
State Types
- Flow state -- Global context available to all crews (current production order, shift objectives, equipment status)
- Crew state -- Local context within a crew (intermediate analysis results, tool call history)
- Persistent state -- Saved to database for recovery after restarts (critical for 24/7 manufacturing operations)
State Best Practices
- Keep state minimal -- only store what downstream crews need
- Use typed state objects -- prevent runtime errors from missing or incorrect state
- Version state schemas -- enable backward-compatible updates
- Log state transitions -- essential for debugging and audit trails
Error Handling in Manufacturing Flows
Manufacturing flows must handle errors gracefully:
Retry Logic
- Network errors (OPC-UA timeout, API failure): Retry 3 times with exponential backoff
- LLM errors (rate limit, timeout): Retry with fallback to a different model
- Tool errors (sensor offline, database unavailable): Retry with cached data
Fallback Paths
- If the diagnosis crew fails, fall back to rule-based alarm handling
- If the scheduling crew fails, maintain the current schedule
- If the quality crew fails, alert human quality inspectors
Recovery
- Persistent state enables flow recovery after system restarts
- Checkpoint state at key decision points
- On recovery, resume from the last checkpoint rather than restarting the entire flow
Performance Optimization
- Use smaller models for routing -- Router nodes do not need GPT-4o; a fast model like Gemini Flash makes routing decisions in milliseconds
- Cache frequently accessed data -- Equipment metadata, maintenance schedules, and product specifications rarely change
- Parallel tool calls -- Within a crew, enable parallel tool execution for independent data fetches
- Async crew execution -- Use async patterns for parallel crews to maximize throughput
- Batch processing -- Combine multiple small decisions into batch crew runs during low-activity periods
Frequently Asked Questions
Related Solutions
Improve OEE/OLE and delivery with real-time control + smart scheduling.
Digitize SOPs, approvals, and action closure with role-based workflows.
Digitize inspections, reduce defects, and make quality audit-ready.