Skip to main content
Loading navigation

Software-Driven PLC Refactoring Agent using Mastra AI and Patronus AI

Transitioning proprietary legacy Ladder Logic to IEC 61131-3 Structured Text is slow and prone to syntax bugs. Build an automated code refactoring agent using Mastra AI and Patronus AI guardrails that transforms legacy PLC ladder diagrams into verified Structured Text. Pass 100% of static automated code policy safety assertions without breaking sequence logic.

EngineeringHosted by Vera

What you are building

Construct a Mastra AI workflow with Patronus AI automated guardrail evaluations to translate and validate industrial ladder logic into structured control code.

How work is evaluated

Evaluation

Evaluates generated Structured Text code against syntax correctness and Patronus safety policies.

Datasets

Public datasets, plus the private datasets you have access to.

How submissions are scored

Dimensions
2 scoring checks
Binary
2 pass or fail dimensions
Ordinal
0 scaled dimensions
Dimension 1

patronus_guardrail_pass

Ensure zero safety policy violations detected by Patronus

Binary check

This dimension contributes its full weight only when the submission satisfies the requirement. Partial credit is not awarded.

Dimension 2

syntax_compilation_rate

Percentage of generated code blocks compiling without errors • target: 1 • range: 0-1

Binary check

This dimension contributes its full weight only when the submission satisfies the requirement. Partial credit is not awarded.

Learning goals

  • Build Mastra AI TypeScript workflows for parsing Structured Text from Ladder AST representations

  • Embed Patronus AI security and safety assertions into code generation evaluation loops

  • Ensure zero safety lock-out violations in generated PLC automation blocks

Resources

Dataset notes

Dataset of 40 standard Ladder Logic control rung configurations and corresponding verified IEC 61131-3 reference snippets.

Challenge setup

Evaluates generated Structured Text code against syntax correctness and Patronus safety policies.

Challenge input

JSON representing ladder logic rungs and contacts

Mastra AI

Offers type-safe agent step composition and workflow execution in TypeScript.

Patronus AI

Provides strict domain assertion checks on LLM code generation outputs.

Evaluated output

String containing valid IEC 61131-3 Structured Text code

Evaluation checks
  • Ensure zero safety policy violations detected by Patronus
  • Percentage of generated code blocks compiling without errors • target: 1 • range: 0-1
Configured evaluation evidence
  • Benchmark: PLC Industrial Code Modernization (PLC-MOD-2025)
  • Syntax Compilation Rate target: 100%
  • 1 public reference case
Configured runtime
  • JavaScript execution harness
  • javascript sandbox (unavailable on Versalist)

Shows the first task, up to three tools, and up to three evidence items.

View technical recipe

Configured tools

Action Space
  • Mastra AI · Required
Reward / Eval
  • Patronus AI · Optional
Safety / Guardrails
  • Patronus AI · Optional
Orchestration
  • Mastra AI · Required

Evaluation contract

  • patronus_guardrail_pass · Weight 1
  • syntax_compilation_rate · Weight 1

Metrics

  • syntax_compilation_rate · Target 1

Benchmarks

  • PLC Industrial Code Modernization (PLC-MOD-2025)
  • general

Reference cases

  • 1 public reference case

Workflow tasks

  1. Task 1

    Input: JSON representing ladder logic rungs and contacts

    Output: String containing valid IEC 61131-3 Structured Text code

    Execution harness: JavaScript

Evaluation tools

  • Mastra AI · Agent & Workflow Engine
  • Patronus AI · AI Guardrails Platform

Recipe freeze marker

No recipe freeze time is recorded.

Frequently Asked Questions about Software-Driven PLC Refactoring Agent using Mastra AI and Patronus AI