Vendor-Aware Industrial Agents
- Vendor-aware industrial agents are domain-adapted AI coding assistants that generate proprietary PLC code with precision using retrieval-augmented generation and vendor-specific constraints.
- They integrate a segmented knowledge base, multi-model orchestration, and real-time compiler-in-the-loop feedback to deliver high-quality Structured Text code for IEC 61131-3 environments.
- The approach emphasizes enterprise privacy and security through on-premise deployment, encryption, and strict adherence to vendor-specific syntax and operational rules.
Vendor-aware industrial agents are domain-adapted AI coding assistants designed for secure, on-premise programmable logic controller (PLC) code generation, with explicit awareness of proprietary control dialects such as those from Mitsubishi Electric. These agents implement retrieval-augmented generation (RAG), multi-model orchestration, and compiler-in-the-loop bug correction to enable high-quality Structured Text (ST) code synthesis for IEC 61131-3 environments, even in restrictive, low-data settings. Emphasizing enterprise privacy and operational security, vendor-aware agents are engineered to satisfy the industrial requirements of air-gapped deployment, deterministic code behavior, and compliance with domain-specific constraints (Kersting et al., 12 Nov 2025).
1. System Architecture and Information Flow
The architecture of vendor-aware industrial agents integrates a segmented knowledge base, retrieval-augmented LLM pipelines, multi-model orchestration, and an automated compilation/diagnostic feedback loop. Central to the solution is a local vector database (e.g., ChromaDB) configured with persistent volumes and organized into three discrete, indexed segments:
- Function Block Definitions: Provides machine-augmented iQ-R CPU series block documentation with explicit handling of proprietary suffix semantics (
_P,_U, EN/ENO). - ST Specifications: Encapsulates vendor ST syntax, reserved words, and POU templates, derived from official Mitsubishi Electric documentation.
- Auxiliary Context: Stores user-uploaded example code, chat history, and project-specific artifacts.
Embeddings for efficient retrieval are computed using OpenAI's text-embedding-3-large or, in fully offline mode, a local sentence-transformer. Metadata fields (vendor, document type, instruction category) support directed retrieval, narrowing context access to vendor- and task-specific subspaces.
The RAG pipeline operates via optional query expansion, vector and keyword retrieval across the three segments, meticulous prompt assembly—including hard constraints and canonical examples—and delivery to a model orchestration layer. This orchestrator invokes, in parallel, cloud (Azure GPT-4.1 RAG/Standard) and local (quantized GGUF, fine-tuned) LLMs, aggregating initial outputs before adhering to the user’s model preference for ongoing interactions. Compiler-in-the-loop capability is delivered through a GX Works3 server integration, supporting real-time code validation and structured error feedback.
2. Vendor Awareness and Domain Encoding
Vendor adaptation is realized through explicit encoding of both syntactic and behavioral nuances in function block definitions and ST dialect constraints. For instance, machine-augmented description prompts enumerate suffix conventions (_P for rising-edge, _U for unsigned, EN/ENO block signaling), and these enriched representations are indexed for retrieval. Critical domain rules—such as the prohibition of inline VAR...END_VAR blocks in Mitsubishi’s GX Works3, or blacklisting reserved identifiers (SYSTEM, %I, etc.)—are encoded as JSON/YAML fragments, injected as hard constraints within every prompt construction.
Retrieval queries may leverage metadata filters (e.g., source:library AND instruction:TON_P), precisely targeting vendor-specific elements and minimizing contextual pollution from IEC 61131-3 dialectal variants.
3. Retrieval-Augmented Generation and Prompt Engineering
Code generation proceeds through hybrid context retrieval: vector similarity (cosine) and keyword indexing combine for robust pre-selection of relevant fragments. The similarity metric is defined as:
Prompt templates enforce domain constraints and inject retrieved snippets under labeled sections (function blocks, syntax rules, canonical POU examples). Sanity checks and minimal working examples are included to prime appropriate code style, alongside explicit “Error if:” statements for critical syntax rules. Retrieved context is sanitized and bounded to prevent prompt flooding or the presence of forbidden tokens.
4. Multi-Model Orchestration and Bug Correction
Initial code generation executes concurrently across three model backends: Azure GPT-4.1 RAG, Azure GPT-4.1 Standard, and a local RAG-augmented, fine-tuned quantized GGUF model. Outputs are compared for compilation success, number of diagnostics returned, and inference latency. Path selection may further incorporate “confidence” proxies, such as log-probability sums for local models.
Bug detection and iterative repair are fully automated, following a diagnostic-guided loop (up to three iterations). Raw compilation diagnostics (e.g., undeclared variables, reserved-word violations) are embedded in repair prompts, which instruct the model to preserve syntactically or semantically validated code while patching only the failing regions. This minimizes destructive edits and accelerates convergence toward compiling solutions.
Pseudocode for the loop:
1 2 3 4 5 6 7 8 |
for attempt in range(3): compile_result = compile(code) if compile_result.success: return code, compile_result else: prompt = build_repair_prompt(code, compile_result.errors) code = model.generate(prompt) return code, compile_result |
5. Fine-Tuning on Synthetic Corpora
Fine-tuning employs a low-data, synthetic corpus generated with the system’s RAG+prompt pipeline operating in high-temperature “generator mode.” Approximately 10,000 task–solution pairs are sampled across diverse personas (e.g., control engineer, electrician) and functional requirements (timers, PID, arrays), with compilation gating to ensure only valid, meaningful examples are retained. The fine-tuning target is a quantized DeepSeek-Coder-v2-Lite model (~16B parameters, GGUF format).
Training employs standard next-token cross-entropy loss:
The schedule incorporates a 10% warm-up phase, linear learning rate decay (peak ), batch size of 8, and three epochs.
6. Compilation Feedback and Evaluation Metrics
Compilation is conducted through an MCP REST/SSE interface to a GX Works3 server, which returns structured diagnostics in JSON payloads. The web interface (Streamlit-based, “GeneriST”) visually aligns code output and compile results, supporting auto- or manual compilation modes.
Key evaluation metrics include one-shot compilation success rate, post-repair rate, average number of repair iterations, latency, and expert user ratings (1–5 stars). A study with 100 diverse queries spanning device I/O, timers, communication, and PID revealed:
| Model | Compiled % | Repaired % |
|---|---|---|
| Azure GPT-4.1 RAG | 73 | +23 |
| Azure GPT-4.1 Standard | 38 | +5 |
| Azure GPT-5 RAG | 87 | +14 |
| Local Fine-Tuned RAG | 86 | +27 |
| Local Standard (tuned) | 73 | +22 |
| Baselines (non-tuned) | 23–25 | +12–17 |
Fine-tuning and RAG augmentation nearly double compilation success versus non-RAG baselines. The local fine-tuned agent matches GPT-4.1 RAG performance and approaches GPT-5 when tuned, indicating RAG plus domain-tuned LLMs suffice for competitive on-prem agent performance (Kersting et al., 12 Nov 2025).
7. Security, Deployment, and Data Privacy
Security is foundational: all proprietary code, embeddings, and models reside on-prem with no external network transmission, except for configurable outbound calls to Azure OpenAI endpoints (disabled in fully offline mode). The vector database and chat logs are encrypted at rest. File-type whitelisting and payload sanitization prevent introduction of malicious code, and firewall rules enforce unidirectional flow for server integration.
Containerization supports enterprise OT/IT segmentation, and audit logging is comprehensive—capturing every retrieval, code generation, and compilation event. This design addresses the trust requirements of industrial environments where customer code and operational data must remain internal under compliance mandates.
Vendor-aware industrial agents, as instantiated in this architecture, establish a reference design for secure, enterprise-grade AI coding assistants capable of synthesizing proprietary PLC code with domain precision, robust validation, and privacy preservation (Kersting et al., 12 Nov 2025).