Challenge

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
Challenge brief

What you are building

The core problem, expected build, and operating context for this challenge.

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

Delivery guide

How work is evaluated

Evaluation

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

Datasets

Shared data for this challenge

Review public datasets and any private uploads tied to your build.

Evaluation rubric

How submissions are scored

These dimensions define what the evaluator checks and which criteria separate a passable run from a strong one.

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

What you should walk away with

  • 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 and assets

Reference links and supporting material

Dataset notes

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

How this agent runs

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

Checks for
  • Ensure zero safety policy violations detected by Patronus
  • Percentage of generated code blocks compiling without errors • target: 1 • range: 0-1
Proof of success
  • Benchmark: PLC Industrial Code Modernization (PLC-MOD-2025)
  • Syntax Compilation Rate target: 100%
  • 1 public reference case
Runtime evidence
  • JavaScript execution harness
  • javascript sandbox (unavailable on Versalist)
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

Recipe state

This is a preview. The configuration can change before the evaluation recipe is locked.

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