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
2024-10-18
Abstract:In industrial control systems, the generation and verification of Programmable Logic Controller (PLC) code are critical for ensuring operational efficiency and safety. While Large Language Models (LLMs) have made strides in automated code generation, they often fall short in providing correctness guarantees and specialized support for PLC programming. To address these challenges, this paper introduces Agents4PLC, a novel framework that not only automates PLC code generation but also includes code-level verification through an LLM-based multi-agent system. We first establish a comprehensive benchmark for verifiable PLC code generation area, transitioning from natural language requirements to human-written-verified formal specifications and reference PLC code. We further enhance our `agents' specifically for industrial control systems by incorporating Retrieval-Augmented Generation (RAG), advanced prompt engineering techniques, and Chain-of-Thought strategies. Evaluation against the benchmark demonstrates that Agents4PLC significantly outperforms previous methods, achieving superior results across a series of increasingly rigorous metrics. This research not only addresses the critical challenges in PLC programming but also highlights the potential of our framework to generate verifiable code applicable to real-world industrial applications.
Software Engineering
What problem does this paper attempt to address?
The problem that this paper attempts to solve is the key challenge of automatically generating and verifying Programmable Logic Controller (PLC) code in industrial control systems. Specifically, the paper points out that although large - language models (LLMs) have made progress in automated code generation, there are still deficiencies in providing code correctness guarantees and supporting PLC programming. These problems mainly include: 1. **Insufficient data**: Due to the proprietary and professional nature of PLC code, it is difficult to collect enough data to fine - tune specialized models. 2. **Functional correctness guarantee**: Control code is used to manage the operation of the industrial sector, so it is crucial to ensure its functional correctness, which is more challenging than generating executable code. 3. **Limitations of existing methods**: Existing PLC code generation methods (such as LLM4PLC) have carried out syntactic and functional verification at the design level, but the correctness of the generated code is still in doubt, and they lack flexibility and cannot achieve full - process automation. To address these challenges, the paper proposes a new framework named Agents4PLC, which not only automatically generates PLC code but also performs code - level verification through an LLM - based multi - agent system. The main contributions of the paper include: - Establishing a comprehensive benchmark, from natural language requirements to formal specifications, and then to manually - verified reference PLC code, to promote future research in the field of PLC code generation. - Introducing Agents4PLC, which is the first fully - automated multi - agent system for PLC code generation. It goes beyond pure LLM methods, emphasizes code - level verification rather than design - level verification, and can flexibly integrate various basic code generation models and tools. - By implementing techniques such as Retrieval - Augmented Generation (RAG), advanced prompt engineering, and chain - of - thought strategies, the adaptability and effectiveness of agents in PLC code generation are enhanced. - Rigorously evaluating Agents4PLC on the largest benchmark, demonstrating its superior performance on a series of increasingly strict metrics, and deploying and verifying the generated code in multiple practical scenarios, highlighting its potential for generating verifiable PLC code in actual industrial control systems.