Skip to main content

Overview

The Device Definition API gives you two helpers for declaring how your agent talks to a physical or virtual device:
  • defineDevice(config) — declares a device, its commands, and (optionally) its built-in triggers.
  • defineDeviceTrigger(config) — declares a standalone trigger primitive (versioned, pushed independently).
For the device-side client library (the code that runs on the device itself — Node, MQTT, MicroPython), see Device Client and the Devices tab.

defineDevice(config)

Declares a device. Devices have commands (agent → device) and optionally triggers (device → agent).

Configuration — LuaDeviceConfig

string
required
Unique device name. Used in lua devices and addressing from agent code.
string
Human-readable description shown in the admin dashboard.
string
Optional group label for organizing devices (e.g. 'printers', 'sensors'). lua devices list --group <name> filters by this.
Record<string, DeviceCommandConfig>
required
Map of command name → command config. Each command is a callable the agent can invoke on the device.
Record<string, DeviceTriggerConfig>
Map of trigger name → trigger config. Built-in triggers tied to this device. For triggers shared across devices, use defineDeviceTrigger instead.

Command Shape — DeviceCommandConfig

string
required
What this command does. Used by the agent’s LLM to decide when to invoke.
ZodSchema
required
Zod schema for the command’s input. Validated before the command leaves the agent.
number
Per-command timeout in milliseconds. Defaults to the device-wide timeout (30000).

Trigger Shape — DeviceTriggerConfig

string
required
What this trigger represents. Used in trigger discovery and admin UI.
ZodSchema
required
Zod schema for the trigger payload. Validated when the device fires the trigger.
(payload, ctx) => Promise<void>
required
Handler invoked when the trigger fires. Receives the validated payload and a context with agent (for invoking the agent) and device (the device that fired).

defineDeviceTrigger(config)

Declares a standalone device trigger as a first-class primitive. Use this when a trigger isn’t bound to a single device — for example, a trigger that any device in a group can fire, or a trigger that’s pushed/versioned independently from its associated device.
Standalone triggers are pushed via lua push device-trigger (or as part of lua push all) and managed through the standard CLI surfaces.

Configuration — LuaDeviceTriggerConfig

string
required
Unique trigger name. Allowed characters: a-z, 0-9, _, -. Must start with a letter.
string
required
What this trigger represents.
ZodSchema
required
Zod schema for the trigger payload.
(payload, ctx) => Promise<void>
required
Handler invoked when the trigger fires.

Wiring Up to an Agent

Invoking Commands from Tools

Inside a skill tool, address a device by name and call its command:

Local Testing

Use lua devices test and lua devices test-trigger to exercise commands and triggers without involving real hardware: