# Architecting an Agent-Based Fault Diagnosis Engine for IEC 61499 Industrial Cyber-Physical Systems
## 3 Architecting the Engine
### Managing Agent Beliefs
Before the diagnostic goals are assigned, a second belief structure is made available to the agent that provides knowledge about the FB application and its structure. Figure 10 shows the implementation of this belief structure created by restructuring the FB application as a Directed Graph. This is referred to as the System-Under-Diagnosis belief structure. **Definition 6** (**System-Under-Diagnosis belief**). : _A belief \(b=\langle\bigtriangleup,v\rangle\) is called a system-under-diagnosis belief when \(\bigtriangleup\) is described by the triple \(\langle FB_{1},trg,FB_{2}\rangle\). \(FB_{1}\) where:_  
* \(FB_{2}\) _are function block instances in the system under diagnosis, and_
* \(trg\) _represents the conditions (events and variable values) under which a transition can be triggered by the agent from_ \(FB_{1}\) _to_ \(FB_{2}\)_._  
The fault diagnostic engine adopts a model-based rather than a machine-learning approach. Manually creating models is labour and time-intensive, since models need to be calibrated [41; 45]. IEC 61499 offers a formally-defined application structure file that allows the engine to autonomously construct an in-memory model of the function block application it has been assigned to monitor and diagnose. As engineers change their designs, the engine is able to update its model using its domain knowledge of the IEC 61499 architecture. IEC 61499 Application Definition files are optimized to work with development IDEs such as 4 diac [6] and nxtCONTROL [85]. However, the XML structure of these files is hard for an agent to navigate dynamically since the parameters for each FB are stored in different parts of the file. The five FB instances are stored as \(FunctionBlock\) nodes and the connections between them as directed edges stored in the \(Connections\) object. The name of an edge corresponds to the output event or data output on the FB the node describes. This structure is easier for the agents to navigate when rewiring the FBs to insert DPs. Agents  
Figure 9: Capturing and triggering Diagnostic Points. are also able to access this belief structure during fault finding by referencing a single node where all its details are available as properties. The \(FunctionBlockApp\) class provides an \(update()\) method so that, if changes are made to the copy of the function block or the connection, the entry in the list of block nodes can be updated. This architectural approach using an indexed list of objects means that new methods and data can be added to the structure without complicated changes to the interface. Each node of this belief structure provides the agent with detailed knowledge to allow it to reliably interact with each FB. Agents are responsible for determining by themselves how to interact with a particular FB, verifying input and output data types so they can provide type-safe test values. The Directed Graph structure also allows agents to navigate fault paths autonomously, making decisions about the next possible fault location they should investigate. System beliefs are dynamic, providing the agents with a way to remember the result of diagnosing a FB as they traverse the FB application and update their beliefs about what they have observed. During the design phase, an engineer will create a package of information that identifies the DPs that are available for each FB. These _Diagnostic Packages_ contain sets of test values associated with data pathways through the FB that can be used during diagnosis to determine if the FB is performing correctly. The agent interprets these diagnostic packages while iterating each FB as it builds its application belief structure. A _Diagnostic Harness_ is then created by inserting all the DP instances into the function block using the agents' \(rewire()\) interaction belief. Model-based approaches rely on techniques of fault-finding that involve invalidating one or more aspects of the model.