SemaPLC: A Project-Grounded, Verification-Gated Agent Harness for PLC Code Generation
공장 제어 코드를 AI가 짜면, 컴파일만 되면 끝이 아니라 실제로 돌려봐야 진짜 검증이다
SemaPLC는 대형언어모델(LLM)이 산업 설비용 제어 코드(PLC용 구조화 텍스트)를 짤 때, 스스로 '됐다'고 판단하면 끝내는 게 아니라 명세 검토, 컴파일, 실제 런타임 실행이라는 세 가지 외부 검증을 모두 통과해야 완료로 인정하는 에이전트 틀이다. 독립된 코드 조각 117개 과제와, 기존 프로젝트에 통합돼 실제로 돌아가야 하는 65개 과제 두 트랙에서 일곱 개 모델을 대상으로 테스트했다. 정적 검사에서는 방법들 간 차이가 크지 않았지만, 실제 실행 결과를 비교하는 동적 검사에서는 SemaPLC가 다른 방법들을 크게 앞섰다.
METAL MEDIA 해설 도표
공장 제어 코드를 AI가 짜면, 컴파일만 되면 끝이 아니라 실제로 돌려봐야 진짜 검증이다
01PLC(산업 설비를 제어하는 프로그래머블 로직 컨트롤러)용 코드를 생성할 때, 모델이 스스로 판단해 멈추지 않고 명세 감사·컴파일·실제 런타임 실행이라는 외부 검증 3종을 모두 통과해야만 작업을 완료로 처리하는 '검증 게이트'를 도입했다.
02독립 함수 단위 코드 117개 과제(기존 벤치마크 기반)와, 실제 산업 설비 10곳에서 뽑은 기존 프로젝트에 코드를 통합해 돌려야 하는 65개 과제, 두 트랙으로 나눠 평가했다.
03독립 함수 과제에서 일곱 개 모델 전부에서 가장 높은 '엄격 검증 통과율'(평균 72.6%)을 기록했고, 이는 도구와 검증 절차를 뺀 맨몸 버전보다 평균 17.3점포인트 높은 수치다.
04프로젝트 통합 과제에서는 컴파일 성공률 평균 89.4%로 1위였고, 정적 검사(코드 텍스트만 보는 검사)에서는 근소한 차이만 있었지만, 실제로 라이브 PLC 런타임에 배포해 정답과 실행 궤적을 비교하는 동적 검사에서는 SemaPLC가 평균 52.2점으로 다른 방법들(최고 31.4점)을 크게 앞질렀다.
05다만 가장 성능 좋은 모델(GPT-5.5)에서는 우위가 좁아졌고(동적 점수 65.4 대 63.6), 동적 검사도 사전에 정해진 시나리오 안에서만 이뤄져 낯선 상황에 대한 일반화는 확인되지 않았다.
METAL MEDIA이 원문을 바탕으로 재구성한 해설 도표이며, 논문 저자의 원문 figure가 아닙니다.
무엇을 했나
PLC(산업 설비를 제어하는 프로그래머블 로직 컨트롤러)용 코드를 생성할 때, 모델이 스스로 판단해 멈추지 않고 명세 감사·컴파일·실제 런타임 실행이라는 외부 검증 3종을 모두 통과해야만 작업을 완료로 처리하는 '검증 게이트'를 도입했다.
독립 함수 단위 코드 117개 과제(기존 벤치마크 기반)와, 실제 산업 설비 10곳에서 뽑은 기존 프로젝트에 코드를 통합해 돌려야 하는 65개 과제, 두 트랙으로 나눠 평가했다.
독립 함수 과제에서 일곱 개 모델 전부에서 가장 높은 '엄격 검증 통과율'(평균 72.6%)을 기록했고, 이는 도구와 검증 절차를 뺀 맨몸 버전보다 평균 17.3점포인트 높은 수치다.
프로젝트 통합 과제에서는 컴파일 성공률 평균 89.4%로 1위였고, 정적 검사(코드 텍스트만 보는 검사)에서는 근소한 차이만 있었지만, 실제로 라이브 PLC 런타임에 배포해 정답과 실행 궤적을 비교하는 동적 검사에서는 SemaPLC가 평균 52.2점으로 다른 방법들(최고 31.4점)을 크게 앞질렀다.
다만 가장 성능 좋은 모델(GPT-5.5)에서는 우위가 좁아졌고(동적 점수 65.4 대 63.6), 동적 검사도 사전에 정해진 시나리오 안에서만 이뤄져 낯선 상황에 대한 일반화는 확인되지 않았다.
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
Model
LLM4PLC
AutoPLC
Agents4PLC
bare
full
MiniMax-M2.7
22.2
49.6
53.8
39.3
69.2
MiniMax-M3
15.4
65.0
55.6
60.7
69.2
Qwen3.5-Plus
13.7
67.5
67.5
62.4
75.2
DS-V4-Flash
41.0
54.7
54.7
34.2
67.5
DS-V4-Pro
43.6
61.5
62.4
55.6
69.2
GLM-5.2
30.8
59.0
74.4
63.2
76.1
GPT-5.5
44.4
79.5
78.6
71.8
82.1
Mean
30.2
62.4
63.9
55.3
72.6
Worst
13.7
49.6
53.8
34.2
67.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.
MiniMax
MiniMax
Qwen3.5
DeepSeek
DeepSeek
Method
M2.7
M3
Plus
V4-Flash
V4-Pro
GLM-5.2
GPT-5.5
Worst
Best
Mean
Integrated compilation
LLM4PLC
47.7
53.8
16.9
60.0
52.3
80.0
100.0
16.9
100.0
58.7
AutoPLC
69.2
95.4
58.4
58.5
95.4
95.4
98.5
58.4
98.5
81.5
Agents4PLC
47.7
69.2
40.0
75.4
78.5
89.2
98.5
40.0
98.5
71.2
SemaPLC
81.5
95.4
80.0
84.6
89.2
95.4
100.0
80.0
100.0
89.4
Static behavior
LLM4PLC
76.1
76.7
74.5
70.3
69.2
77.1
86.3
69.2
86.3
75.7
AutoPLC
68.9
73.5
68.9
76.2
66.5
75.5
88.8
66.5
88.8
74.0
Agents4PLC
63.4
73.5
77.6
71.4
64.5
62.8
88.6
62.8
88.6
71.7
SemaPLC
74.9
84.9
79.9
78.0
81.2
88.0
84.1
74.9
88.0
81.6
Dynamic behavior
LLM4PLC
3.0
26.1
6.6
18.4
13.9
34.6
54.5
3.0
54.5
22.4
AutoPLC
4.0
43.5
19.8
23.9
45.7
21.9
61.1
4.0
61.1
31.4
Agents4PLC
4.5
30.8
11.4
28.3
28.8
44.6
63.6
4.5
63.6
30.3
SemaPLC
31.3
52.1
43.1
54.1
57.4
61.9
65.4
31.3
65.4
52.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 layers
Comp.
Static
Dyn.
Tok.
Reqs.
None (generate only)
64.6
71.5
23.1
34k
8.9
+ Spec
70.8
74.0
30.3
60k
14.6
+ Compile
83.1
77.8
43.7
74k
25.5
+ Runtime (full)
84.6
78.0
54.1
129k
47.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.
Outcome
None
+Spec
+Compile
+Runtime
Check failed
76.9
69.7
56.3
45.9
not built/run
33.4
24.5
19.7
3.3
port missing
41.3
35.7
20.0
18.2
wrong value (normal)
0.9
3.0
4.9
7.1
wrong value (breach)
1.2
6.5
11.7
17.3
Correct
23.1
30.3
43.7
54.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 group
Programs
Props.
Concl. %
Inconcl. %
No REAL/timer
916
4653
75.7
24.3
With REAL
345
1845
87.0
13.0
With timer (TON)
32
174
0.0
100.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.
Method
Requests / task
Time / task (s)
Function track
Agents4PLC
6.3 (4.4 – 7.2)
454 (241 – 688)
SemaPLC
6.5 (5.5 – 7.6)
71 (41 – 156)
Project track
Agents4PLC
6.9 (6.8 – 7.0)
344 (47 – 917)
SemaPLC
34.1 (16.4 – 60.4)
347 (25 – 1380)
Table S1: PLC tools exposed over the Model Context Protocol.
Tool
Function
plc_check
Syntax/semantic check of a bare POU with the same compiler as the evaluation
plc_compile
Full ST compilation with structured, line-anchored diagnostics
plc_detectIO
Extract the located-I/O surface (addresses, types, directions)
plc_upload
Upload the compiled program to the runtime and return build logs
plc_buildAndRun
Compile, upload, and start in one call with per-stage results
plc_start
Start the loaded program
plc_stop
Stop the running program
plc_status
Runtime state query
plc_getLogs
Runtime logs with an error flag
plc_readVariables
Read live variable values over the debug protocol
plc_forceVariables
Force or release input values to simulate external signals
plc_trace
Sample variables over time (timers, state machines, counters)
plc_record
Fetch the per-scan recording of transitions for scan-precise sequences
plc_waitFor
Poll one variable until a comparison holds or times out
plc_verifyBehavior
Atomic force, expect, and release check of a downstream effect
plc_buildSimulation
Build an animated process-simulation scene for the running program
Table S2: Command-line entry points of the same tool server.
Command
Function
verify
Run a declarative verify plan (build, drive cases, assert, clean up) and emit a JSON verdict envelope
compile
Compile an ST file and print the structured result
buildAndRun
Compile, upload, and start: the full deploy loop from the shell
detectIO
Extract the located-I/O map from an ST file
genModbusConfig
Generate the Modbus slave configuration from the located I/O
readVariables
Read runtime variable values
force
Force or release runtime variables to simulate inputs
trace
Sample variables over time
waitFor
Poll a variable until the comparison holds or times out
genScene
Suggest a process-simulation scene from the located I/O
status
Quick runtime status check
serve
Start the MCP stdio server under a chosen tool profile
Table S3: The skill library, one skill per verification layer. Skill names are abbreviated.
Skill
Role
spec-review
Requirement-to-logic checklist run before delivery, covering named devices and signals, function-block instance calls, and published-variable drivers
fix-compile-error
Repair the earliest diagnostic only, recheck, at most two rounds, then report stuck
benchmark-verify
Runtime 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 / result
Seen by method?
Scores result?
Requirement + context
Yes
No
Compiler diagnostics
Yes
Yes
Agent’s own audit feedback
Yes
No
Held-out function judge
No
Yes
Project assertion oracle
No
Yes
Golden reference / trace
No
Yes
왜 중요한가
공장, 발전소, 정수처리장을 돌리는 PLC 코드가 AI로 자동 생성될 때, 컴파일만 통과한 코드도 타이머 오류나 잘못된 상태 전환처럼 실제 운전 중 사고로 이어질 결함을 숨길 수 있다는 점을 보여준다. 코드 생성 AI를 산업 현장에 적용하려는 개발자나 안전 담당자에게, 정적 검사만으로는 신뢰성을 판단할 수 없고 실제 실행 검증이 필수라는 실무적 기준을 제시한다.
이 논문의 용어
PLC(프로그래머블 로직 컨트롤러) · 공장 설비나 기계를 자동으로 제어하는 산업용 소형 컴퓨터
POU(프로그램 조직 단위) · PLC 프로그램을 구성하는 독립된 함수·블록 단위 코드 조각
Structured Text(ST) · PLC를 프로그래밍하는 텍스트 기반 언어 중 하나
MCP(모델 컨텍스트 프로토콜) · AI 모델이 외부 도구를 표준화된 방식으로 호출할 수 있게 하는 통신 규격
동적 검사(runtime validation) · 코드를 실제로 실행시켜 정답 코드와 실행 결과(변수 값 변화 등)를 비교하는 검증 방식