This application demonstrates real-time AI agent inference using MQTT messaging. It consists of a message producer that generates simulated data, an MQTT broker that handles message routing, and an AI agent that processes the data and returns predictions.
- MQTT-based messaging system for real-time data processing
- Dockerized setup with multiple services
- Automated message generation for testing
- Real-time agent predictions
- Support for MQTT monitoring tools
├── Dockerfile # Dockerfile for the agent service
├── Dockerfile.producer # Dockerfile for the message producer
├── model/ # Directory for the trained model
│ └── agent.json # Trained model file
├── agent_inference.py # Main agent service that processes MQTT messages
├── mqtt_producer.py # Script that generates test messages
├── docker-compose.yml # Docker compose configuration
├── mosquitto/ # Mosquitto broker configuration
│ ├── config/
│ │ └── mosquitto.conf # MQTT broker configuration
│ ├── data/ # Persistent storage for MQTT messages
│ └── log/ # Broker logs
├── .env # Environment file (for license key)
├── requirements.txt # Python dependencies for agent service
├── producer_requirements.txt # Python dependencies for producer
└── README.md
- Docker
- Docker Compose
- Python 3.10.x
- MQTT Explorer (optional, for monitoring)
- Clone the Repository
git clone https://github.com/composabl/agent-mqtt-app.git
cd agent-mqtt-app
- Set up Mosquitto Configuration Create the necessary directories and configuration:
mkdir -p mosquitto/data mosquitto/log
Create mosquitto/config/mosquitto.conf
with:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_type all
- Environment Variables
Make sure to add your COMPOSABL_LICENSE key in the
.env
file:
COMPOSABL_LICENSE=your_license_key_here
- Start the Services
docker-compose up --build
This will start:
- MQTT Broker (Mosquitto)
- Agent Service
- Message Producer
- Download and install MQTT Explorer from mqtt-explorer.com
- Connect to broker:
- Host: localhost
- Port: 1883
- Subscribe to topics:
- agent/observation (input data)
- agent/action (agent predictions)
You can publish test messages using mosquitto_pub:
mosquitto_pub -h localhost -t "agent/observation" -m '{
"observation": {
"T": 311.0,
"Tc": 292.0,
"Ca": 8.56,
"Cref": 8.56,
"Tref": 311.0,
"Conc_Error": 0.0,
"Eps_Yield": 0.0,
"Cb_Prod": 0.0
}
}'
Subscribe to responses:
mosquitto_sub -h localhost -t "agent/action" -v
{
"observation": {
"T": 311.0,
"Tc": 292.0,
"Ca": 8.56,
"Cref": 8.56,
"Tref": 311.0,
"Conc_Error": 0.0,
"Eps_Yield": 0.0,
"Cb_Prod": 0.0
}
}
{
"action": [10.0]
}
If you prefer to run the services locally:
- Install Mosquitto broker:
# Ubuntu/Debian
sudo apt-get install mosquitto
# MacOS
brew install mosquitto
- Install Python dependencies:
pip install -r requirements.txt
pip install -r producer_requirements.txt
- Start the services:
# Terminal 1: Start Mosquitto
mosquitto -c mosquitto/config/mosquitto.conf
# Terminal 2: Start the agent
python agent_inference.py
# Terminal 3: Start the producer
python mqtt_producer.py
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f composabl-mqtt-broker
docker-compose logs -f composabl-agent-mqtt
docker-compose logs -f composabl-mqtt-producer
The message producer supports several command-line arguments:
# Custom interval (e.g., 2 seconds between messages)
python mqtt_producer.py -i 2
# Verbose logging
python mqtt_producer.py -v
- The MQTT broker is configured for development use. Additional security measures should be implemented for production.
- The message producer generates random data within realistic ranges for testing.
- MQTT QoS level 2 is used for guaranteed message delivery.
Make sure you have a valid license for the AI agent (COMPOSABL_LICENSE), as this is required for the app to work.
Feel free to contribute by submitting pull requests or opening issues!