defineDevice and connected with the lua-device runner instead of a custom script. Because they share a group, the agent gets a fan-out tool that sends a notice to every connected floor in one call. The hardware is simulated; you need Node 18 and an agent created with lua init. The runner with a handlers file stands in for the hardware. lua devices test sends one command to one connected device and can’t call the fan-out tool, and lua test has no device type, so you’ll exercise the group with lua chat -m.
Verified against lua-cli 3.45.0.
What you’ll build
office-floor-3andoffice-floor-4in the groupoffice-floors, with four commands each.- The fan-out tool
device__office_floors__show_notice__all. - A handler module the runner loads on each floor’s machine.
1
Declare the devices
Both declarations share one
commands object. The runner sends no command list, so these declarations are the only source of the tools.src/devices/FloorControllers.ts
2
Register and push
Devices are pushed one by one and are not part of an agent version. A pushed
defineDevice declaration reaches the runtime on the agent’s next turn whether or not you publish it; --auto-deploy only records it as the active version. A standalone defineDeviceTrigger runs only after its pushed version is published, with --auto-deploy or the push prompt.src/index.ts
3
Write the handler module
The runner loads a CommonJS module whose
commands map one handler per command name. The same file runs on both floors; it reads the floor from an environment variable.handlers.cjs
4
Create two credentials and connect
Each device needs its own credential, bound to its name, with The files sit outside the agent project so they are never committed. Then run one runner per floor, each in its own terminal; each prints
commands. Issue one per floor from the agent project:Connected as 'office-floor-3' to agent '<id>' and Listening for commands... (Ctrl+C to stop).5
Broadcast a notice
From the agent project, ask for a notice on every floor. The model calls
device__office_floors__show_notice__all once; the result lists total, succeeded, failed, and one entry per device.6
Verify
List the group and check each device.Stop the floor-4 runner and ask again: the fan-out result reports
total: 2, succeeded: 1, failed: 1, because every registered member of the group is addressed and the offline one fails.What you learned
defineDeviceputs the command contract in the agent project under version control; the runner needs no code. See defineDevice and defineDeviceTrigger.- A
groupon declared devices producesdevice__<group>__<command>__all; self-describing devices don’t get fan-out tools. See Expose device commands as tools. - One credential binds one device name; a fleet needs one credential per device. See Create a device credential.
Next steps
Warehouse station
A self-describing Node device with a trigger.
lua devices
List by group, enable, disable, test.

