Two Sides of a Trigger
A device trigger has two sides:- Device side — the device fires the trigger using
client.trigger()ordevice.trigger() - Agent side — you define what happens when the trigger arrives using
defineDeviceTrigger()
Think of it as:
A doorbell. The device presses it (fires the trigger). Your agent-side code decides what to do when it rings (the execute function).
Device Side: Firing Triggers
Node.js
trigger() method resolves when the server acknowledges receipt. It does not wait for the agent to finish processing.
MicroPython
Agent Side: Handling Triggers
On the agent side, create a device trigger primitive usingdefineDeviceTrigger(). This is a standalone file that gets compiled, pushed, and deployed like any other Lua primitive.
The trigger
name on the agent side uses hyphens (e.g., low-stock). The trigger name on the device side uses underscores (e.g., low_stock). The gateway maps between the two conventions automatically.Both Sides Together
Deploying Device Triggers
Device triggers are compiled and pushed like other Lua primitives:LuaDeviceTriggerConfig Reference
Trigger name. Lowercase with hyphens (e.g.,
paper-low, temperature-alert).Description of when this trigger fires. Helps with debugging and documentation.
Zod schema for validating the trigger payload. The payload is validated before
execute runs.The function that runs when the trigger fires. Receives the validated payload and a context object.
Execute Context
Theexecute function receives a context object:
| Property | Type | Description |
|---|---|---|
agent | object | Agent context. Call agent.chat() to send messages or invoke tools. |
device | { name: string } | Information about the device that fired the trigger. |
Trigger Result Listening (Optional)
On the device side, you can optionally listen for the result of trigger execution:Next Steps
Agent Tools
How the other direction works — agent sending commands to devices
Self-Describing Commands
How devices declare their command capabilities
Warehouse Example
Full example with triggers for low stock alerts
Industrial Sensor
MicroPython trigger example for vibration anomalies

