Everything K-culture — comebacks to K-beauty, straight to your inboxGet it in your inbox

METAL MEDIA

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

arXiv:2608.185652026-08-18

AI-written factory control code needs to be actually run, not just compiled, to prove it works

SemaPLC is an agent harness that makes a large language model keep working on industrial control code until three external checks - a specification audit, compilation, and live runtime execution - all confirm success, instead of letting the model decide for itself when it's done. It was tested on 117 standalone code-generation tasks and 65 tasks that require the generated logic to compile and run inside real, existing plant projects, across seven different backbone models. While methods looked similar under static, text-only checks, running the code on a live controller revealed SemaPLC was far more reliable than existing baselines.

METAL MEDIA explanatory visual

AI-written factory control code needs to be actually run, not just compiled, to prove it works

  1. 01SemaPLC generates code for programmable logic controllers (PLCs), the industrial computers that run plants, and refuses to declare a task finished until logged external checks - a specification review, compilation, and execution on a live PLC runtime - all pass, rather than trusting the model's own judgment.
  2. 02It was evaluated on two tracks: 117 independent code-unit tasks from an existing benchmark, and 65 tasks built from ten real industrial plants where generated logic must integrate into and run inside an existing project.
  3. 03On the standalone-unit track, SemaPLC achieved the highest strict verified pass rate on all seven models (72.6% average), 17.3 points higher than the same setup with the harness stripped out.
  4. 04On the project-integration track, it had the best average compile success rate (89.4%); static, text-only checks showed only small gaps between methods, but when logic was actually deployed and its execution trace compared to a reference, SemaPLC scored 52.2 on average versus at most 31.4 for other methods.
  5. 05Its advantage narrowed on the strongest model tested (GPT-5.5), and because the runtime tests use a fixed, pre-derived set of scenarios, performance under unseen operating conditions remains unmeasured.
An explanatory diagram made by METAL MEDIA, not a figure supplied by the paper's authors.

What they did

  1. SemaPLC generates code for programmable logic controllers (PLCs), the industrial computers that run plants, and refuses to declare a task finished until logged external checks - a specification review, compilation, and execution on a live PLC runtime - all pass, rather than trusting the model's own judgment.
  2. It was evaluated on two tracks: 117 independent code-unit tasks from an existing benchmark, and 65 tasks built from ten real industrial plants where generated logic must integrate into and run inside an existing project.
  3. On the standalone-unit track, SemaPLC achieved the highest strict verified pass rate on all seven models (72.6% average), 17.3 points higher than the same setup with the harness stripped out.
  4. On the project-integration track, it had the best average compile success rate (89.4%); static, text-only checks showed only small gaps between methods, but when logic was actually deployed and its execution trace compared to a reference, SemaPLC scored 52.2 on average versus at most 31.4 for other methods.
  5. Its advantage narrowed on the strongest model tested (GPT-5.5), and because the runtime tests use a fixed, pre-derived set of scenarios, performance under unseen operating conditions remains unmeasured.
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

Why it matters

PLCs control factories, power plants, and water treatment facilities, and code that merely compiles can still hide timer errors or wrong state transitions that only show up during actual operation - a serious safety concern. For engineers considering AI-generated control code, this shows that static checks alone can't tell reliable systems from unreliable ones; real execution testing is necessary.

Terms in this paper

  • PLC (Programmable Logic Controller) · An industrial computer that automates control of machinery and plant equipment
  • POU (Program Organization Unit) · A self-contained function or block that makes up part of a PLC program
  • Structured Text (ST) · A text-based programming language used for PLCs
  • MCP (Model Context Protocol) · A standardized way for AI models to call external tools
  • dynamic/runtime validation · Checking correctness by actually running the code and comparing its live behavior to a reference

Original abstract (English)

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.

Authors · Yanlun Tu

Read on arXiv

Latest papers

All papers →

Latest from METAL MEDIA

Figures: Yanlun Tu et al., arXiv:2608.18565, CC BY 4.0