Skip to main content
After this guide, each command your device accepts is a tool the model calls while the device is online, and you know what the model sees when a call fails. Declare commands on the device when the device owns its capabilities; declare them with defineDevice when you want timeouts, retries, and group fan-out under version control in the agent project. Verified against lua-cli 3.33.0. Before you begin
  • A device credential with the commands operation.
  • The Node or Python client installed, or lua-device from npm install -g @lua-ai-global/device-client for the defineDevice path.
1

Declare the commands

A command has a name matching ^[a-z][a-z0-9_]{0,63}$, a description the model reads as the tool description, and an optional JSON Schema inputSchema.
The list is sent at connect time; nothing is pushed. Change it and restart the device.
device.ts
2

Write the handlers

A handler receives the payload the model produced and returns the JSON the model gets back. A thrown error becomes { success: false, error: '<message>' }.
device.ts
3

Check the tools the model has

While the device is online the agent has device__label_printer__print_label, device__label_printer__paper_level, and device__label_printer__is_online; hyphens in the device name become underscores. Each command tool is described as [Device: label-printer] <description>. If the device is offline, this will return an error. When a self-describing device goes offline its command tools are removed on the next turn; a device declared with defineDevice keeps its tools, and calls return DEVICE_OFFLINE. Either way is_online stops answering { status: 'online' }.
4

Read the results

A successful call returns the device’s reply as { commandId, success: true, data }. Failures come back as { success: false, error, message } with one of these error values.A handler that throws returns success: false with the error message and is not retried.
5

Verify

Send one command by hand and read the reply and latency; the command name is prompted for.
lua devices test runs the command regardless of which declaration path you used. Under --ci it exits 1 at the prompt.

Options you may need

Retries and timeouts

timeoutMs sets how long the platform waits per attempt. retry: { maxAttempts, backoffMs } re-sends after a timeout or transport failure, waiting backoffMs × attempt between attempts; an offline or rate-limited device is never retried. Both fields work in the device’s command list and in defineDevice.

Group fan-out

Give several defineDevice declarations the same group and the agent also gets device__<group>__<command>__all, which sends the command to every registered device in the group and returns { total, succeeded, failed, results }; an offline member counts as failed. Membership is the group each device reports when it connects, so pass the same name to the client. Fan-out tools exist only for devices declared with defineDevice. To try a group without hardware, run the lua-device runner with a handlers file once per member. lua devices test sends one command to one connected device and can’t call the __all tool, and lua test has no device type, so exercise fan-out with lua chat -m.

Both declarations for one name

If a device connects with its own command list and a defineDevice declaration with the same name is pushed, the device’s list wins and the declaration’s commands are ignored for that device.

If it isn’t working

Its name doesn’t match ^[a-z][a-z0-9_]{0,63}$, its schema is over 4 KB, the device declared more than 128 commands, or the agent already has 128 device tools. Rename or trim, then reconnect.
Run lua devices status --device-name <name> --ci. offline or registered means the client isn’t connected; disabled means someone ran lua devices disable, so run lua devices enable --device-name <name>.
The agent has 100 commands waiting on replies. Handlers that never return hold a slot until the timeout; return or throw promptly.

Next steps

Handle device triggers

The other direction: events from the device.

defineDevice reference

Every field of a command and trigger declaration.

lua devices

List, status, enable, disable, test.