# Building XAI-Based Agents for IoT Systems
## 2 Agent-Based Method for Building Explainable IoT Systems
### Reference Architecture for an Agent-Based IoT System  
Figure 1 illustrates the reference architecture of an agent-based Internet of things (IoT) system, which consists of two main components: the virtual and physical environments. The system is composed of software agents, designated with the letter A, that operate in the virtual environment and interact with physical components, such as sensors and actuators, in the physical environment. Physical sensors, which are deployed in the field to collect data on parameters such as temperature, presence, and humidity, can range in complexity from simple, reactive data collection and transmission devices to more advanced devices with onboard processing and storage capabilities. Actuators, on the other hand, are used to perform physical actions, such as opening or closing valves, turning motors on or off, or activating lights. Each physical sensor and actuator is associated with corresponding sensors and actuator agents in the virtual environment. Real-time data from the physical sensors are constantly acquired by sensor agents and passed to data collection agents, which act as intermediaries between the lowest-level sensor/actuator agents and higher-level decision support agents. Data collection agents pre-process the data and, when certain  
predetermined thresholds are exceeded, forward the information to decision support agents for further analysis and inference. The users, depicted in Figure 1, represent the domain expert and end users of the system. The domain expert, who is typically the developer of the system, is responsible for defining the system's behavior rules, providing the necessary data, and specifying user preferences. This is accomplished using the Expert Intelligence Toolkit, a component used to convert knowledge into control rules for the IoT rule execution engine. The IoT rule execution engine is a major component of the system and is based on underlying decision agents. It is responsible for collecting data from sensors, processing the data, and transmitting control settings to the actuators based on the established control rules. Additionally, the rule execution engine can perform other functions, such as device management and security. It can be hosted on a public cloud service such as Amazon Web Services or on a private server located on-premises. The rule execution engine typically includes a database for data storage and tools for data visualization. The explanation interface is software used for user interaction with the system. It provides the necessary information and explanations of the system's decisions to the end users, allowing them to understand the actions taken by the system. A web-based interface is recommended to maximize accessibility through a variety of user-owned devices such as computers, tablets, and smartphones. After receiving  
Figure 1: Agent-based IoT system architecture. the verbal explanation, users can provide feedback through the Expert Intelligence Toolkit, allowing the system to adapt to their current needs. The denoted system components are connected through a network, which can be both wired and wireless. The network infrastructure will depend on the requirements of the IoT system, such as the type and amount of data being transmitted, the required reliability and latency, and the availability of a network infrastructure in the deployment area. Communication messages are transmitted through MQTT (Message Queuing Telemetry Transport)--a lightweight publish/subscribe messaging protocol that is commonly used for IoT applications because of its low overhead and good support for intermittent and low-bandwidth networks. Compared to similar approaches which use services or microservices, the proposed method stands out in several ways:  
Explainability: the method focuses on building agent-based IoT systems that are explainable, meaning that the system's behavior can be understood and traced back to specific actions of individual agents.