AI-Assisted Architectural Transformation of CATio#
Overview#
A single developer, working with GitHub Copilot as an AI pair programmer over two weeks, performed a radical re-architecture of the fastcs-CATio project.
The major new features are as follows.
Terminal Definitions#
YAML files describing each terminal (EtherCAT slice) type replace individual python classes. The YAML is entirely autogenerated from XML published by Beckhoff.
This allowed the replacement of hand coded python classes for 29 terminal types with automatic support for all possible terminal types from Beckhoff, including future types yet to be released.
Web GUI#
An entirely new Web GUI supports developers implementing CATio IOCs.
The GUI allows them to import terminal types directly from Beckhoff.
It then presents them with an overview of the configurable features of those terminals so they can choose settings and specify which symbols the IOC should monitor.
This serves not only as a configuration tool, but as an educational tool for browsing the symbols exposed by terminals and understanding the supported modes for each terminal.
CATio Hardware Simulation#
The first task was to build a complete simulator that can clone any existing physical EtherCAT chain.
This simulator allowed for the implementation of comprehensive system tests, allowing high confidence when verifying radical architectural changes.
Documentation#
Comprehensive documentation was added where none existed before. This includes tutorials to familiarize developers with the simulator and new GUI. See Tutorials
How AI Accelerated Development#
Background#
This was the developer’s first production project using AI. They also had very little background in CATio or knowledge of the existing state of the project.
Assistance#
The AI pair programmer helped in multiple areas:
rapid understanding of a new codebase
help in understanding Beckhoff TwinCAT and the ADS protocol
discussing ideas for radical architecture changes
investigating in depth the huge and complex XML files from Beckhoff
to discover what could be extracted from them (ans: all details of all terminal types)
to work out how to parse them into simpler YAML for a specified subset of terminals
validating understanding of the meaning of various symbols and modes in DLS terminal types
help designing a Model-View-Presenter pattern GUI app
help choosing the best python libraries for various capabilities
heavy lifting on writing 12000 lines of python for the new GUI and dynamic classes
the majority of code was written by AI during 1 week of iteration
all the code was then reviewed in depth by the developer, taking one work day
the primary feedback from the review was restructuring into smaller modules and occasional refactor of repeated code
exemplary help in diagnosing and fixing any issues with code/docs/infrastructure/tools
excellent support in learning how to use agents themselves
generally being able to learn about any subject that you need help with
fastcs-catio was an initial foray into AI and represents early learning about prompting only (stage 1 below). Nevertheless there was a performance improvement of 10x or more over traditional practices.
Further Improvements#
AI skills can be categorized into 4 levels that build upon each other:
Prompt engineering – knowing how to frame your conversation with the AI.
Context engineering – knowing how to keep the context lean, clean and focused on the current task. Keeping global instructions small, loading skills at the right time, distributing tasks to multiple agents.
Intent engineering – understanding how to keep the agent on task and focused on your goal. Being extremely clear about your intent.
Spec engineering – very clearly specifying the desired outcome so that it is possible to leave a team of agents running long term to iterate on plan-execute-verify until your spec is met.
Since the fastcs-catio project, reasonable progress in 2 and 3 has been made in other projects. For example see builder2ibek which uses skills and multi-agent workflows in order to convert traditional xmlBuilder IOCs to epics-containers. Learning these additional skills makes AI even more powerful and efficient.
Learn More#
Architecture Overview – full architecture with diagrams showing the dynamic controller generation pipeline
Terminal YAML Definitions – complete YAML schema, how to add new terminals, and GUI editor usage
FastCS EPICS IOC – dynamic controller generation details and runtime attribute creation