K-文化的一切——从回归到 K-美妆,发送到您的邮箱订阅邮件

METAL MEDIA

SemaPLC: A Project-Grounded, Verification-Gated Agent Harness for PLC Code Generation

arXiv:2608.185652026-08-18

AI写的工厂控制代码光能编译还不够,必须真正运行起来才算过关

SemaPLC是一套智能体工作框架,让大模型在生成工业控制代码时不能自己说了算,必须等规范审查、编译、真实运行环境执行这三项外部检查都确认通过才算完成任务。研究者在117个独立代码片段任务和65个需要接入真实工厂项目并实际运行的任务上,用七种不同大模型做了测试。结果显示,在只看代码文本的静态检查中各方法差别不大,但一旦把代码真正部署到运行环境中比对执行结果,SemaPLC明显领先于其他方法。

METAL MEDIA 解读图

AI写的工厂控制代码光能编译还不够,必须真正运行起来才算过关

  1. 01SemaPLC为可编程逻辑控制器(PLC,即控制工厂设备的工业计算机)生成代码,不允许模型自行判断任务完成,而是要求规范审查、编译、真实运行环境执行这三种外部检查都记录在案并通过才算完成。
  2. 02评测分两条赛道:一是基于现有基准的117个独立代码单元任务,二是取自十个真实工业工厂、要求生成代码接入并运行于现有项目的65个任务。
  3. 03在独立代码单元任务上,SemaPLC在全部七个模型上都取得最高的严格验证通过率(平均72.6%),比去掉整套验证框架的裸版本高出17.3个百分点。
  4. 04在项目集成任务上,SemaPLC平均编译成功率最高,达到89.4%;仅看代码文本的静态检查中各方法差距不大,但把代码真正部署到实时PLC运行环境并对比执行轨迹后,SemaPLC平均得分52.2,远高于其他方法最高31.4分。
  5. 05在测试中表现最强的模型(GPT-5.5)上,SemaPLC的优势有所缩小;而且动态测试所用的场景是预先设定好的,代码在未见过的运行状况下表现如何仍无法确认。
这是 METAL MEDIA 制作的解读图,并非论文作者提供的原图。

他们做了什么

  1. SemaPLC为可编程逻辑控制器(PLC,即控制工厂设备的工业计算机)生成代码,不允许模型自行判断任务完成,而是要求规范审查、编译、真实运行环境执行这三种外部检查都记录在案并通过才算完成。
  2. 评测分两条赛道:一是基于现有基准的117个独立代码单元任务,二是取自十个真实工业工厂、要求生成代码接入并运行于现有项目的65个任务。
  3. 在独立代码单元任务上,SemaPLC在全部七个模型上都取得最高的严格验证通过率(平均72.6%),比去掉整套验证框架的裸版本高出17.3个百分点。
  4. 在项目集成任务上,SemaPLC平均编译成功率最高,达到89.4%;仅看代码文本的静态检查中各方法差距不大,但把代码真正部署到实时PLC运行环境并对比执行轨迹后,SemaPLC平均得分52.2,远高于其他方法最高31.4分。
  5. 在测试中表现最强的模型(GPT-5.5)上,SemaPLC的优势有所缩小;而且动态测试所用的场景是预先设定好的,代码在未见过的运行状况下表现如何仍无法确认。
Figure 1: Overview of the SemaPLC agent harness: a model-agnostic agent core, grounded in the task or project context, acts through a shared PLC MCP tool layer, and a verification gate decides completion.
Figure 1: Overview of the SemaPLC agent harness: a model-agnostic agent core, grounded in the task or project context, acts through a shared PLC MCP tool layer, and a verification gate decides completion.
Table 1: Function track: strict verified pass rate (%, denominator 117; inconclusive and empty generations count as failure). All methods are graded by the same held-out judge. bare is SemaPLC with the harness stripped from the same backbone (no skills and tools); full is the complete harness. DS = DeepSeek.
SemaPLC
ModelLLM4PLCAutoPLCAgents4PLCbarefull
MiniMax-M2.722.249.653.839.369.2
MiniMax-M315.465.055.660.769.2
Qwen3.5-Plus13.767.567.562.475.2
DS-V4-Flash41.054.754.734.267.5
DS-V4-Pro43.661.562.455.669.2
GLM-5.230.859.074.463.276.1
GPT-5.544.479.578.671.882.1
Mean30.262.463.955.372.6
Worst13.749.653.834.267.5
Table 2: Project-context track (0–100, best per column in bold): integrated-project compile rate, assertion-oracle static score, and live-runtime dynamic score, all over the full 65-task denominator. Worst/Best/Mean summarize each method over the seven models.
MiniMaxMiniMaxQwen3.5DeepSeekDeepSeek
MethodM2.7M3PlusV4-FlashV4-ProGLM-5.2GPT-5.5WorstBestMean
Integrated compilation
LLM4PLC47.753.816.960.052.380.0100.016.9100.058.7
AutoPLC69.295.458.458.595.495.498.558.498.581.5
Agents4PLC47.769.240.075.478.589.298.540.098.571.2
SemaPLC81.595.480.084.689.295.4100.080.0100.089.4
Static behavior
LLM4PLC76.176.774.570.369.277.186.369.286.375.7
AutoPLC68.973.568.976.266.575.588.866.588.874.0
Agents4PLC63.473.577.671.464.562.888.662.888.671.7
SemaPLC74.984.979.978.081.288.084.174.988.081.6
Dynamic behavior
LLM4PLC3.026.16.618.413.934.654.53.054.522.4
AutoPLC4.043.519.823.945.721.961.14.061.131.4
Agents4PLC4.530.811.428.328.844.663.64.563.630.3
SemaPLC31.352.143.154.157.461.965.431.365.452.2
Table 3: Project-track verification-layer ablation on DeepSeek-V4-Flash (65 tasks), adding checks cumulatively. Comp./Static/Dyn. use the Table 2 metrics; Tok./Reqs. are mean tokens and model requests per task.
Verification layersComp.StaticDyn.Tok.Reqs.
None (generate only)64.671.523.134k8.9
+ Spec70.874.030.360k14.6
+ Compile83.177.843.774k25.5
+ Runtime (full)84.678.054.1129k47.8
Table 4: Outcome shares (%) of the 3,590 golden-reference scenario–port value checks (65 project-track tasks, DeepSeek-V4-Flash) under the cumulative arms of Table 3. The Correct row equals the Dyn. column of Table 3; subshares may not sum exactly to the totals due to rounding.
OutcomeNone+Spec+Compile+Runtime
Check failed76.969.756.345.9
not built/run33.424.519.73.3
port missing41.335.720.018.2
wrong value (normal)0.93.04.97.1
wrong value (breach)1.26.511.717.3
Correct23.130.343.754.1
Table 5: Function-track formal-verification coverage of the held-out pipeline, pooled over 1,293 delivered programs from SemaPLC runs. Conclusive means satisfied or violated.
Program groupProgramsProps.Concl. %Inconcl. %
No REAL/timer916465375.724.3
With REAL345184587.013.0
With timer (TON)321740.0100.0
Table 6: Interaction cost per task against the strongest baseline: requests and end-to-end wall-clock seconds. Values are per-model per-task aggregates (means for requests, medians for times) averaged over the seven models, with across-model ranges in parentheses. Both methods call the same endpoints.
MethodRequests / taskTime / task (s)
Function track
Agents4PLC6.3 (4.4 – 7.2)454 (241 – 688)
SemaPLC6.5 (5.5 – 7.6)71 (41 – 156)
Project track
Agents4PLC6.9 (6.8 – 7.0)344 (47 – 917)
SemaPLC34.1 (16.4 – 60.4)347 (25 – 1380)
Table S1: PLC tools exposed over the Model Context Protocol.
ToolFunction
plc_checkSyntax/semantic check of a bare POU with the same compiler as the evaluation
plc_compileFull ST compilation with structured, line-anchored diagnostics
plc_detectIOExtract the located-I/O surface (addresses, types, directions)
plc_uploadUpload the compiled program to the runtime and return build logs
plc_buildAndRunCompile, upload, and start in one call with per-stage results
plc_startStart the loaded program
plc_stopStop the running program
plc_statusRuntime state query
plc_getLogsRuntime logs with an error flag
plc_readVariablesRead live variable values over the debug protocol
plc_forceVariablesForce or release input values to simulate external signals
plc_traceSample variables over time (timers, state machines, counters)
plc_recordFetch the per-scan recording of transitions for scan-precise sequences
plc_waitForPoll one variable until a comparison holds or times out
plc_verifyBehaviorAtomic force, expect, and release check of a downstream effect
plc_buildSimulationBuild an animated process-simulation scene for the running program
Table S2: Command-line entry points of the same tool server.
CommandFunction
verifyRun a declarative verify plan (build, drive cases, assert, clean up) and emit a JSON verdict envelope
compileCompile an ST file and print the structured result
buildAndRunCompile, upload, and start: the full deploy loop from the shell
detectIOExtract the located-I/O map from an ST file
genModbusConfigGenerate the Modbus slave configuration from the located I/O
readVariablesRead runtime variable values
forceForce or release runtime variables to simulate inputs
traceSample variables over time
waitForPoll a variable until the comparison holds or times out
genSceneSuggest a process-simulation scene from the located I/O
statusQuick runtime status check
serveStart the MCP stdio server under a chosen tool profile
Table S3: The skill library, one skill per verification layer. Skill names are abbreviated.
SkillRole
spec-reviewRequirement-to-logic checklist run before delivery, covering named devices and signals, function-block instance calls, and published-variable drivers
fix-compile-errorRepair the earliest diagnostic only, recheck, at most two rounds, then report stuck
benchmark-verifyRuntime behavior check: build an injectable test copy, deploy it, drive self-derived scenarios, assert published outputs
Table S4: Information seen by the agent during generation versus information used for final scoring.
Information / resultSeen by method?Scores result?
Requirement + contextYesNo
Compiler diagnosticsYesYes
Agent’s own audit feedbackYesNo
Held-out function judgeNoYes
Project assertion oracleNoYes
Golden reference / traceNoYes

为什么重要

PLC控制着工厂、发电厂和水处理设施,仅仅能编译通过的代码仍可能隐藏定时器错误或状态切换错误等问题,只有在实际运行时才会暴露,这类隐患关系到安全生产。对于考虑用AI生成工业控制代码的工程师来说,这项工作说明只做静态检查无法区分可靠与不可靠的方法,真正的运行测试必不可少。

本文术语

  • PLC(可编程逻辑控制器) · 用于自动控制工厂设备和机械的工业专用计算机
  • POU(程序组织单元) · 构成PLC程序的独立函数或功能块代码片段
  • Structured Text(ST,结构化文本) · 一种用于编写PLC程序的文本类编程语言
  • MCP(模型上下文协议) · 让AI模型能以标准化方式调用外部工具的通信规范
  • 动态/运行时验证 · 通过实际运行代码并将执行结果与参考答案对比来判断是否正确的检验方式

论文原文摘要(英文)

Programmable logic controllers (PLCs) run industrial plants, and large language models can already generate independent program organization units (POUs) for them. Whether such logic integrates into an existing PLC project and then runs correctly has been checked only in limited tests. We present SemaPLC, a project-grounded and verification-gated agent harness assembled from conventional tools but governed by a strict completion rule. Rather than stopping when the model judges its own output adequate, SemaPLC declares a task complete only when logged external checks confirm it. Those checks cover the specification, the compilation, and the behavior on a live runtime. On 117 independent-POU tasks matching existing benchmarks, it attains the highest strict verified pass rate on all seven models (72.6\% mean). On a project-context track of 65 tasks whose generated logic must compile and run inside a real project, it attains the highest mean on integrated compilation, static behavior, and dynamic behavior. Of the three layers, dynamic behavior is the most revealing. We measure it by deploying the generated and the reference logic to a live PLC runtime and comparing their executed traces. All methods fall within 10 static points of one another, whereas dynamic scores separate them sharply, from 22.4 to 31.4 for the baselines against 52.2 for SemaPLC. Overall, our verification-gated harness raises the mean at every layer and most sharply at runtime. Execution, not static scoring, is the faithful test of whether generated control logic actually works. SemaPLC is open-sourced at https://github.com/midea-ai/SemaPLC.

作者 · Yanlun Tu

在 arXiv 阅读

最新论文

全部论文 →

METAL MEDIA 最新报道

图片来源: Yanlun Tu et al., arXiv:2608.18565, CC BY 4.0