In 2023, a mid-size electronics manufacturer was spending 12 hours per week manually scheduling production across 6 assembly lines. Their production planner, a 25-year veteran, was retiring. The spreadsheet he built had 47 tabs, hidden macros, and fragile dependencies. One wrong cell paste crashed the entire schedule.
We swapped that spreadsheet for an AI-driven production planning system built with Python 3.12, PostgreSQL 16, and OpenAI's gpt-4o. The new system reduced weekly planning time from 12 hours to 2 hours. Late orders dropped by 40%. Overtime costs fell 25% in the first quarter.
This is not a theoretical framework. This is the architecture, code patterns, and real numbers from a system shipping in production today.
- Data Layer: PostgreSQL 16 with TimescaleDB extension. Stores order data, machine states, shift calendars, and material inventory. 500,000+ rows processed per scheduling run.
- Constraint Engine: Python 3.12 with OR-Tools 9.10. Modeled 47 constraints including machine availability, worker skillsets, material lead times, and changeover durations.
- AI Agent Layer: LangChain 0.3 + Anthropic Claude 3.5 Sonnet. Three specialized agents handle constraint relaxation, exception handling, and human handoff for trade-offs.
Week 1-2: Audit and Schema Design
Spend 2 weeks mapping every constraint that exists in your factory. Interview the planner, the floor leads, the maintenance team. You will find constraints nobody documented. Design your PostgreSQL schema. Set up TimescaleDB for time-series machine data.
Week 3-5: Constraint Solver MVP
Build the basic OR-Tools model with the top 10 constraints. Get it running on historical data. Validate the output against the planner's manual schedule from last month. Expect 80% agreement at this stage.
Week 6-8: AI Agent Integration
Add the LangChain agents for constraint relaxation and exception handling. Build the Slack integration. Set up the override log table. Start the feedback loop. Run in shadow mode (AI produces a schedule, planner sees it but also builds their own). Compare outputs.
Week 9-10: Parallel Run
AI system runs in production alongside the manual process. The planner uses the AI schedule as the default but can override anything. Measure override rate, planning time, and planner satisfaction. Fix bugs and tune prompts.
Week 11-12: Full Cutover and Monitoring
Retire the old spreadsheet. The AI system is the source of truth. Set up the Grafana dashboard with override rate, schedule quality score, and solver runtime. Schedule a monthly review to update constraints and retrain agent prompts.
- 1Interview your production planner for 4+ hours. Record everything. You will discover constraints they never wrote down.
- 2Write a data quality report on your MES/ERP export. Flag missing BOMs, null due dates, and duplicate order numbers.
- 3Set up PostgreSQL 16 with TimescaleDB. Create hypertables for machine status, shift logs, and order status history.
- 4Build the OR-Tools CSP model with the top 10-15 constraints. Do not add AI until this base model validates against history.
- 5Implement the constraint sanity check: reject any AI-generated date, duration, or quantity more than 3 standard deviations from historical norms.
- 6Wire up the override log table. Track planner_id, original_value, new_value, reason, and timestamp.
- 7Deploy the Slack-first UI. Do not build a dashboard. Ship in the tool your planner already uses 11 hours a day.
- 8Set up Grafana with the override rate, solver runtime, and schedule confidence score metrics.
- 9Schedule the weekly review with the planner and floor leads. Review the top 5 overrides and update the model accordingly.
- 10Write a rollback plan. The old spreadsheet stays accessible (as read-only) for 30 days after cutover.
The Tech Stack (Why We Chose What We Chose)
Python 3.12 because OR-Tools and LangChain both have first-class Python support. The entire system runs as a single Python process triggered by a cron job (and on-demand via Slack commands). We use Pydantic v2 for schema validation on every data point entering the system.
PostgreSQL 16 with TimescaleDB was an easy call. Manufacturing data is inherently temporal. Machine status changes, shift start/end times, order completion timestamps. Hypertables give automatic partitioning by time, and continuous aggregates give us 30-second rollups for the dashboard. The constraint solver reads materialized views built from these aggregates.
We chose Anthropic Claude 3.5 Sonnet over GPT-4. The planner ran 150 test scenarios through both models. Claude generated more conservative, plausibly correct constraint relaxations. GPT-4 was twice as creative but hallucinated impossible timelines 12% of the time. For a system that schedules real factory lines, conservative is correct.
LangChain 0.3 is the glue. It handled the conversation memory, tool binding, and agent orchestration. We wrote custom tools for database queries (parameterized SQL via psycopg2), constraint model re-runs (subprocess call to the OR-Tools script), and Slack message posting. The agent framework saved us roughly 2 weeks of plumbing code.
The Results After 90 Days in Production
After 90 days, the AI production planning system was processing an average of 185 orders per week across 6 assembly lines. The constraint solver generated the initial schedule in 47 seconds (p95). The AI agent layer handled 73% of exception cases without human intervention. The remaining 27% were escalated to the planner via Slack, and the planner resolved them in an average of 4 minutes.
The override rate stabilized at 8.3% by week 10. The top override reasons were: rush orders from the CEO's favored customer (28%), machine breakdowns not yet in the system (22%), and material shortages from a supplier (18%). Each of these became a prompt update or a data pipeline improvement.
The factory reduced its finished goods buffer by 18% because the schedule was more predictable. That freed up $240,000 worth of floor space and carrying costs. The planning team expanded their scope from just scheduling to doing scenario analysis: 'What if we add a third shift on line 4?' or 'What if we drop the slow-moving SKUs?' They ran 5-8 what-if scenarios per week, something they never had time for before.
The retiring planner stayed an extra 3 months to train his successor. His final words: 'I wish I had this 20 years ago.'
Ship It, Don't Overthink It
AI production planning is not about replacing planners. It is about removing the busywork so planners can focus on the hard problems: trade-offs, exceptions, and strategic improvements. The technology is ready today. Open-source constraint solvers give you provably optimal schedules. LLM agents give you the flexibility to handle the messy real world. PostgreSQL gives you the storage layer you already know.
If you are an engineering leader managing a manufacturing operation with 2-20 production lines, you can build this system in 8-12 weeks with a team of 2-3 senior engineers. The ROI is clear: 10 hours saved per week per planner means you pay for the project in less than 6 months on labor efficiency alone.
IRPR has shipped similar systems for factories in the US, Mexico, and Germany. If your team needs help designing the architecture, writing the constraint model, or integrating the AI agents, book a discovery call. We will tell you if you are ready, and if you are not, what is missing.
The IRPR engineering team ships production software for 50+ countries. Idea → Roadmap → Product → Release. 200+ products live.
About IRPR