NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Agents4PLC: Automating Closed-loop PLC Code Generation and Verification in Industrial Control Systems using LLM-based Agents

Zihan Liu, Ruinan Zeng, Dongxia Wang, Gengyun Peng, Jingyi Wang, Qiang Liu, Peiyu Liu, Wenhai Wang

TL;DR

Agents4PLC is an LLM-based multi-agent framework that fully automates both the generation and code-level verification of Programmable Logic Controller (PLC) code. By combining specialized agents for planning, coding, verification, and debugging into a closed-loop system, it ensures functional correctness for safety-critical industrial automation while significantly outperforming existing methods.

What Problem Does This Paper Address?

Programmable Logic Controllers (PLCs) are the backbone of industrial control systems, regulating everything from power grids to manufacturing lines. Writing the code that runs them—typically in languages like Structured Text (ST)—is highly specialized and time-consuming.

While Large Language Models (LLMs) excel at mainstream languages like Python or C++, they struggle with PLC code due to a lack of public training data and the proprietary nature of industrial software. More importantly, industrial systems are safety-critical; a single logical bug can cause catastrophic physical damage. Existing automated solutions either lack full automation or only verify code at the design specification level, leaving the actual generated code unverified and potentially unsafe.

Methods

The authors introduce Agents4PLC, a closed-loop multi-agent framework built using advanced architectures like LangGraph and MetaGPT. Instead of relying on a single LLM to write perfect code on the first try, Agents4PLC distributes the workload across five specialized agents:

  1. Retrieval Agent: Uses Retrieval-Augmented Generation (RAG) to query internal vector databases for relevant PLC documentation, standards, and code samples.
  2. Planning Agent: Formulates structured, automata-like step-by-step plans to solve the prompt.
  3. Coding Agent: Translates the plans into Structured Text (ST) code, guided by domain-specific syntax hints embedded in its prompts.
  4. Validation Agent: Acts as the gatekeeper. It first runs a syntax check using open-source compilers (like MATIEC or RuSTy). If it passes, it translates the ST code into formal verification languages (like SMV) using tools like PLCverif, and runs model checkers (like nuXmv) to mathematically prove functional correctness against safety properties.
  5. Debugging Agent: If the code fails compilation or functional verification, this agent uses Chain-of-Thought (CoT) reasoning to analyze the error logs, pinpoint the faulty code lines, and provide precise fixing advice back to the Coding Agent.

This iterative loop continues automatically until the code passes all verification checks or hits a predefined loop threshold.

Fig. 2: Overview of Agents4PLC.

Datasets

Because no comprehensive dataset existed for verifiable PLC code generation, the authors constructed a new benchmark. It consists of 23 distinct programming tasks categorized by difficulty:

  • Easy Problems: 16 tasks with 58 verification properties (53 non-trivial).
  • Medium Problems: 7 tasks with 43 verification properties (38 non-trivial).

The benchmark covers real-world industrial scenarios including Logical Control, Mathematical Operations, Real-time Monitoring, and Process Control.

Key Insights and Ideas

  • Code-Level vs. Design-Level Verification: Verifying the design specification isn't enough because bugs can still be introduced during code generation. Directly verifying the generated ST code using formal model checkers bridges the trust gap for deployment in real physical systems.
  • The Power of Syntax Hints: Ablation studies revealed that providing explicit syntax rules and compiler constraints within the prompt was far more effective for low-resource languages like ST than providing "one-shot" code examples.
  • CoT is Vital for Complex Debugging: While simple syntax errors can be fixed easily, Chain-of-Thought reasoning in the Debugging Agent proved critical for resolving complex functional verification failures in medium-difficulty tasks.

Key Results

Agents4PLC was evaluated against state-of-the-art baselines like LLM4PLC and ChatDev across multiple base models (GPT-4o, GPT-4o-mini, DeepSeek V2.5, and CodeLlama 34B).

  • Syntax Compilation: When paired with modern LLMs (GPT-4o, DeepSeek), Agents4PLC achieved a 100% syntax compilation success rate on both Easy and Medium problems, drastically reducing the need for manual code corrections.
  • Functional Correctness: On Easy problems, Agents4PLC paired with GPT-4o achieved a 68.8% verifiable rate and a 50% pass rate, vastly outperforming LLM4PLC (which scored 0% and 12.5% respectively on the same model).
  • Efficiency: Efficiency evaluations showed that Agents4PLC frequently generated correct, compilable code on the very first attempt when using GPT-4o or DeepSeek V2.5, minimizing expensive iterative API calls.

Limitations and Future Work

While highly effective, Agents4PLC currently only supports Structured Text (ST). Real-world industrial environments frequently use graphical PLC languages like Ladder Diagrams (LAD) or Function Block Diagrams (FBD). The authors note that expanding the framework to support these visual languages and integrating direct user feedback mechanisms to refine the multi-agent interactions are critical next steps.

Summary updated

BibTeX
@article{liu2026agents,
  author = {Zihan Liu and Ruinan Zeng and Dongxia Wang and Gengyun Peng and Jingyi Wang and Qiang Liu and Peiyu Liu and Wenhai Wang},
  title = {{Agents4PLC: Automating Closed-loop PLC Code Generation and Verification in Industrial Control Systems using LLM-based Agents}},
  journal = {IEEE Trans. Software Eng.},
  year = {2026},
  doi = {10.1109/tse.2026.3667895},
}
Figure