TEACHING SEVEN AGENTS TO WRITE PLC CODE

Pac-Forge
Year
2025 → present
Role
Sole engineer
Status
Primary focus
Stack
React 19 · Claude API · .NET 4.8
Pac-Forge is an internal productivity tool for industrial automation engineers. Its flagship module, Pac-ST, takes a natural-language control requirement and produces compilable Siemens Structured Control Language — the programming language of TIA Portal, which runs on a large share of factory automation hardware worldwide.
The challenge isn't generating plausible-looking SCL. Any capable model can do that. The challenge is generating SCL that compiles first-pass against a specific TIA Portal project, respects site-specific standards and IO mappings, passes a safety audit, and gets better over time as engineers correct it.
The problem
Automation engineers spend a disproportionate amount of time writing boilerplate SCL. Motor start sequences, valve control blocks, PID loops with handoff logic — the patterns are repetitive but the implementation details are site-specific enough that generic templates don't compile. Every project has its own IO list, naming conventions, and safety constraints. Copying code from a previous project is faster than writing from scratch, but it still requires careful adaptation and produces subtle bugs when the adaptation is wrong.
No commercial tool generates PLC code that's immediately compilable against a real TIA project — and none of them learn from corrections. Pac-Forge was built to close that gap.
The shape of the system
A React 19 front end communicates with a Supabase backend. When an engineer submits a requirement, it enters the pipeline above. Each agent operates on structured data — not raw text — with defined input and output schemas enforced by the orchestrator. The final output is a function block in SCL, ready to be compiled.
Compilation happens locally on the engineer's machine via a .NET bridge process that wraps TIA Openness. The bridge receives SCL over HTTP, imports it into the active TIA project, triggers a compile, and streams the error list back via WebSocket. The whole round-trip — generation to compile result — takes under two minutes on a warm run.
The hard bits
Orchestrating seven agents deterministically
The core problem: LLM outputs are non-deterministic, but PLC code must compile every time. Each agent has a defined interface — a structured input schema and a structured output schema — and the orchestrator enforces this contract. If an agent returns output that doesn't parse against the schema, the run fails fast rather than silently propagating garbage.
Agent sequencing uses a topological sort over a static dependency graph. The Pattern Librarian runs early so its output is available to the Code Architect; the Safety Auditor runs after IO validation so it can reason about real addresses. The orchestrator manages retries with exponential backoff and a maximum attempt ceiling per agent. Lease-based concurrency via Supabase row-level locking ensures only one pipeline can write to a given project at a time — preventing two engineers from stomping each other's in-flight runs.
Auto-learning from compile errors
Every compile result from TIA Portal gets ingested back into the system. A compile failure produces a structured error list — error code, line number, message. A deterministic diff engine compares the failed code against the engineer's manual correction to produce a WRONG/CORRECT example pair. These pairs are stored in the pattern library tagged by error type, involved function block, and originating agent.
When a new run starts, the Pattern Librarian queries the library for semantically similar examples and injects them into the Code Architect's context as few-shot guidance. The system gets measurably better at the specific patterns that have failed before — without retraining the model.
The TIA Openness bridge
TIA Portal has no REST API. The only programmatic interface is TIA Openness — a COM-style .NET library that ships with TIA Portal and requires a .NET Framework 4.8 process running on the same Windows machine as TIA Portal itself.
The bridge is a C# console app that wraps TIA Openness and exposes an HTTP + WebSocket server on port 5102. The web app sends compiled SCL blocks to this server; the bridge opens the TIA project, imports the blocks, triggers a compile, and streams the error list back via WebSocket. The bridge process launches on demand and shuts down on idle — so it doesn't hold the TIA Portal project open between runs.
Lease-based concurrency
Supabase Postgres handles concurrency coordination. Each pipeline run acquires a row-level lease on the target project with a 90-second TTL. Auto-renewing keepalives extend the lease while the run is active. If the client disconnects or the run exceeds the TTL without renewal, the lease expires and the project becomes available again.
This prevents two simultaneous pipeline runs from producing conflicting SCL for the same project — a scenario that would either overwrite good code or produce an unresolvable merge conflict in TIA Portal.
The result
Engineers produce compilable SCL from natural language descriptions in under two minutes on warm runs. The pattern library grows continuously as engineers correct output — the system has accumulated hundreds of WRONG/CORRECT pairs covering the most common error classes. First-pass compile success rates have improved significantly since launch.
Pac-ST is actively used in production. The secondary module, Pac-LAD — Ladder Logic diagram generation — is in development.