Architecture Overview
The Device Gateway sits between your physical devices and the Lua agent runtime. It handles authentication, connection management, command routing, and trigger delivery.Self-Describing Flow
When a device connects, it does not need any server-side configuration. The device tells the gateway what it can do, and the gateway tells the agent.1
Device connects with command manifest
The device client sends its
commands array during the Socket.IO auth handshake or MQTT online status message. Each command includes a name, description, and optional JSON Schema for input parameters.2
Gateway registers device
The gateway validates the device credential, its exact agent and device binding, and the permitted operations. It then registers the device and stores the permitted command manifest.
3
Agent discovers tools
When the agent processes a user message, it queries connected devices and merges their commands into the tool list. Each device command appears as a tool named
device__{deviceName}__{commandName}.4
Device disconnects, tools disappear
When a device goes offline (intentional disconnect, network loss, or missed heartbeats), its tools are removed from the agent. No stale tools remain.
Command Delivery Path
When the agent decides to use a device tool, the command flows through the gateway: Each command carries a uniquecommandId for idempotency. If the device receives the same command twice (due to retry or redelivery), it returns the cached response.
Trigger Flow
Triggers go in the opposite direction — from device to agent:Triggers are fire-and-forget from the device’s perspective. The device gets an acknowledgment that the gateway received the trigger, but does not wait for the agent to finish processing it.
Transport Comparison
Security Model
Bound device credentials
New installations use a credential bound to one agent, one device name, and selected device operations. Existing non-dotted legacy keys remain supported indefinitely.
Agent Scoping
A device can only interact with the agent it authenticates against. Cross-agent communication is not possible.
TLS Encryption
All transports use TLS. Socket.IO connects over HTTPS. MQTT connects over port 443 (WebSocket) with TLS.
Heartbeat Monitoring
The gateway expects a heartbeat every 30 seconds. Missed heartbeats trigger disconnect detection. MQTT additionally uses Last Will and Testament (LWT) for instant offline notification.
Connection Lifecycle
- Socket.IO
- MQTT
auth.apiKey property and MQTT password remain the protocol fields for both device credentials and existing legacy keys. The Node.js client uses deviceCredential for new provisioning. Published Python and MicroPython clients continue to use api_key with existing legacy keys. See Device credentials.
Next Steps
Self-Describing Commands
Deep dive into how devices declare their capabilities
Triggers
Understand device-to-agent event flow
MQTT Transport
Configure MQTT for constrained devices
Agent Tools
How device commands become agent tools

