Not open yet. Device tools do not work end to end yet: their server side is not on in any environment, and the device-tool API is not in a released ESP32 SDK. This page shows how they will work. Until they open, leave the board's device tools off (step 3 below); your calls work as before.
During an AI Agent call the Agent can ask your board to do something, such as turn the speaker up or set an alarm. These are the board's device tools. The Agent can also answer from cloud tools, such as the weather, which need nothing on the board. This page shows how a board offers its tools, how OneSay authorizes each request, and what happens when a request fails.
This is a preview. It needs ESP32 SDK v0.1.10 or later, and the server side of device tools must be on for your environment; until it is, leave the board's device tools off (step 3 below), and your calls work as before. For a first call without tools, see Talk to an AI Agent on an ESP32-S3-BOX-3.
How it works
- The board declares its methods once per boot, before its first call: a short list of names such as
app.volume.set. The declaration grants nothing by itself. - The board registers a handler for each method before it joins the call's Room.
- OneSay authorizes the call. When the call starts, OneSay issues the Agent permission to call exactly the declared methods that your environment allows, and only on this board; the board may receive them only from this Agent. LiveKit's media server enforces both sides on every request. When both sides are in place, OneSay marks the board's own participant metadata, and only then offers the tools to the Agent.
- The Agent calls a method when the user asks for it ("turn the volume up"), the board's handler runs and replies, and the Agent tells the user the result.
The calls are LiveKit RPC: the board is the callee, using the RPC support of LiveKit's ESP32 SDK as the OneSay ESP32 SDK ships it. Firmware can be read and copied, so nothing the board says is a permission: what the Agent may call, and on which board, is decided by OneSay for each call.
What you need
- ESP32 SDK v0.1.10 or later, and its
box3_agent_callexample, which implements two tools: the speaker volume and alarms. - A board that already makes calls with the BOX-3 quickstart.
- An environment where device tools are on. Ask your OneSay contact; until then, keep step 3's setting off.
1. Declare the board's methods
onesay_esp32_control_publish_rpc_methods (the publishDeviceRPCMethods operation, PUT /devices/{device_id}/rpc-methods) replaces
the Device's list of methods:
static const char *const names[] = {"app.volume.set", "app.volume.get", "app.alarm.set", "app.alarm.list"};
onesay_err_t result = onesay_esp32_control_publish_rpc_methods(context, device_secret, device_secret_length, names, 4U);-
At most 4 names (
ONESAY_CONTROL_RPC_METHODS_MAX). Each name starts withapp., followed by dot-separated parts of ASCII letters, digits,_and-(each part starts with a letter or digit), 5 to 64 bytes in all. An empty list withdraws every method. -
The Device's long-lived secret is used only for a fresh token exchange, as for
onesay_esp32_control_publish_capabilities. -
The declaration has no expiry, so the example sends it once per boot, before the first call, and prints the result:
TextONESAY_BOARD_RPC_DECLARE {"declared":true,"result":0,"http_status":200}A refusal is printed with its error and HTTP status, and the call goes on without tools.
2. Register a handler for each method
Register the handlers once, after the call's session is prepared and before connect_audio, with the receive mode that OneSay
authorizes (server_authorized = true):
onesay_rtc_rpc_receive_config_t rpc = {.method_count = 4U, .max_reply_bytes = 64U, .context = NULL, .server_authorized = true};
for (size_t i = 0; i < 4U; i++) {
memcpy(rpc.methods[i].method, names[i], strlen(names[i]) + 1U);
rpc.methods[i].handler = handlers[i];
}
onesay_err_t result = onesay_esp32_rtc_prepare_rpc_receive(session, &rpc);A handler has this form:
onesay_err_t handler(void *context, const onesay_rtc_rpc_request_t *request, onesay_rtc_rpc_reply_t *reply);request->payloadis the Agent's JSON, at most 64 bytes in this mode (ONESAY_RTC_RPC_SERVER_AUTHORIZED_MAX_BYTES). Write your reply intoreply->payload, setreply->length, and returnONESAY_OK. Any other return sends one fixed application error and no data.- Each accepted request gets exactly one reply. A repeated request ID is never run again.
- Handlers run on the SDK's receive thread: keep them short, never block, and never call SDK functions from them.
- In this mode a handler sees an empty
participant_idand no local deadline: who may call is decided by the server, not by the handler.
In the agent_call examples the place for this is the configuration's prepare_rpc hook, which the example calls with the prepared
session before connect_audio; the BOX-3 example prints:
ONESAY_BOARD_RPC {"methods":4,"prepared":0}3. Turn the tools on in the example
The BOX-3 example's device tools are off unless the board's settings say otherwise. Add two rows to your nvs.csv (see the example's
README, "Configuration"):
vol_rpc,data,string,1
tz,data,string,CST-8vol_rpc1declares the four methods at boot and registers their handlers for each call. Leave the row out, or set0, to make calls without tools.tzis the board's timezone as a POSIX TZ string;CST-8is UTC+8 (China),JST-9is UTC+9 (Japan). Alarms need it; without it the Agent says that the device has no timezone set.
Then write the settings image to the board, in a terminal where ESP-IDF's environment is active:
python make_nvs.py nvs.csv nvs.bin
python -m esptool --chip esp32s3 write-flash 0x9000 nvs.bin4. How the board knows OneSay authorizes it
The receive mode stays off until OneSay marks the board's own LiveKit participant metadata, which it does only once both sides of the call's tools are in place:
{"onesay.rpc_receive_authority":"server"}- The SDK reads this itself, at the join and on every later update of the board's own participant; you write no code for it. The metadata may hold other keys.
- While the mode is off, every request gets the fixed application error and no handler runs.
- The board's token cannot change its own metadata, so firmware cannot turn the mode on.
- A whole reconnect brings a new participant with empty metadata, so the mode is off again for the rest of that call; the Agent stops offering the board's tools when the board's participant leaves.
- Each change is logged once, with the tag
onesay_rtc_rpc:RPC receive on (server authority present), orRPC receive off (server authority absent or not "server").
5. The example's tools
| Ask the Agent | Method | The board's answer |
|---|---|---|
| "Turn the volume up", "set the volume to 40" | app.volume.set with {"level":n}, 0 to 100 | The new level, kept in spk_volume |
| "How loud is it?" | app.volume.get with {} | The current level |
| "Wake me at seven tomorrow", "an alarm at 7:30 every weekday" | app.alarm.set with {"h":H,"m":M,"r":"once"|"daily"|"weekdays"} ("d":1 for tomorrow), or {"cancel":n} / {"all":true} to cancel | The alarm's number and next ring time |
| "What alarms do I have?" | app.alarm.list with {"i":k} | One alarm at a time, by ring time |
Alarms are kept in the board's storage across restarts, at most 8, in the board's own timezone. An alarm rings on the speaker for up to
60 seconds; BOOT stops it. An alarm that falls due during a call waits until the call ends. The source is the example's
components/box3_board/volume_rpc.c and alarm_rpc.c; on your own board, the clock, timezone and storage are yours.
6. Cloud tools: weather and music
Cloud tools run on OneSay's side: the board does nothing but play the Agent's voice, and no board setting or code is involved. Which Agents may use them is part of each environment's Agent configuration, and each tool needs its data source configured for that environment. Ask your OneSay contact which are on for yours.
- Weather: "What's the weather in London tomorrow?" The Agent looks up a forecast for today or up to six days ahead and says it.
- Music: "Play something relaxing." The Agent plays a matching track from the environment's music catalog through the call; speaking interrupts it, as it interrupts the Agent.
7. When something fails
The call always goes on. What the user hears and what a developer sees:
| What happened | The user hears (the Agent says it in the user's language) | A developer sees |
|---|---|---|
| The board did not answer in time, or OneSay refused the request (for example a method this call may not use) | "The device did not answer, so the volume may not have changed." | In the Agent's RPC, error 1501 (CONNECTION_TIMEOUT) after about 7 seconds: a refused request is dropped before it reaches the board, so it looks like a board that did not answer |
| The board has no handler for the method | "This device does not support that. Nothing was changed." | RPC error 1400 (UNSUPPORTED_METHOD) |
| The board left the call | "The device is not connected right now. Nothing was changed." | RPC error 1401 or 1503 |
| The receive mode is off, or the handler returned an error | "The device did not answer, so the volume may not have changed." | The SDK's fixed application error; no handler ran (mode off), or yours returned an error |
| The board answered something unreadable | "The device's answer could not be read, so the volume may not have changed." | Your reply was not the expected JSON |
Alarms without tz | "The device has no timezone set, so no alarm was set." | The board answered {"e":"tz"} |
| Weather lookup failed | "The weather service is not available right now." | Nothing on the board |
If the board printed ONESAY_BOARD_RPC_DECLARE with "declared":false, or ONESAY_BOARD_RPC with a non-zero prepared, the call runs
without tools; the Agent never offers them.
8. Check it works
- Add the two rows of step 3 and write the settings image.
- Reset the board and start a call as in the BOX-3 quickstart, section 5.
- Look for, in order:
ONESAY_BOARD_RPC_DECLARE {"declared":true,...}at boot,ONESAY_BOARD_RPC {"methods":4,"prepared":0}before the board joins, andRPC receive on (server authority present)once the call's tools are in place. - After the chime, say "set the volume to 40". The speaker changes and the Agent confirms.
- Say "wake me at seven tomorrow", then "what alarms do I have?". The Agent tells you the alarm's time.
JavaScript
Device tools are a Device feature of the ESP32 SDK: the JavaScript SDK has no Device side for Agent calls. Inside your own app, the JavaScript SDK's session RPC lets your app's participants call each other's methods under the Room's packet policy; see the JavaScript SDK reference.