Skip to content
OneSay Developers

Guides

Talk to an AI Agent on an ESP32-S3-BOX-3

This guide turns an ESP32-S3-BOX-3 into the microphone and speaker of a OneSay AI Agent. You speak to the board, and the Agent answers through its speaker. It is a pre-production preview.

This guide turns an ESP32-S3-BOX-3 into the microphone and speaker of a OneSay AI Agent. You speak to the board, and the Agent answers through its speaker. It is a pre-production preview.

There are two ways to set up the board. The first needs only a browser: the OneSay Cloud Console's Flash BOX-3 page flashes the firmware and answers the board's requests during the call. The second builds the example yourself with ESP-IDF.

Where this stands. We have run the call that a person starts on our own board, on an earlier version of the service. The call the board starts itself has not been verified on a board with a released SDK yet. For the ESP-IDF way, the helper scripts (tools/partner/partner-helper.mjs, with tools/sdk/device-rtc-local.mjs) are provided with the SDK preview on request, for the steps around the board: they write the board's NVS rows, answer the board's Consent and Delegation requests during the run, and start and stop the Agent as you in the call that a person starts. On OneSay's service today, the Agent does not hear the board in a call that a person starts (ESP32 SDK 0.1.9 and earlier). Their README gives each command, the full NVS key table, how to build and flash the NVS image, and the 15-minute window from the AppSession step to the run.

How it works

Two sides take part:

  • The board joins a Room, publishes its microphone and plays the Agent's voice. It starts the Agent call itself (the device-initiated call, available since SDK 0.1.9), under the standing Delegation you created for it and with device-initiated calls switched on for your Environment. In the call a person starts (SDK 0.1.9 or earlier) it never starts or stops an Agent. On OneSay's service today, the Agent does not hear the board in a call that a person starts (ESP32 SDK 0.1.9 and earlier).
  • You, signed in, create that standing Delegation once with your own Consent. In the call a person starts you start the Agent with the board's microphone as its input from your own app, and allow each step that needs your Consent.

The Room holds only the board and the Agent, because the board plays every audio track in the Room. How an AI Agent talks through an ESP32 board explains why it is built this way.

What has been verified

On one ESP32-S3-BOX-3, on the pre-production environment, on an earlier version of the service, in calls that a person started:

CheckResult
The board joins the Room and publishes its microphonePassed
A person at the board hears a clear, complete replyPassed
Several turns, using recorded speech played to the boardPassed
A call of several minutesPassed; the longest ran about 14 minutes (826 s, on an earlier SDK version)
The board ends a live call itself, while a reply playsPassed once, with no crash

Not yet verified on a device: the call the board starts itself (with a released SDK), interrupting the Agent while it speaks, a live conversation with several turns, and longer calls. Treat them as untested.

These calls are not yet reliable: the server may end a call early, and we are looking into why.

Flash from the Console

This way cannot hold a conversation today. The page makes the call that a person starts. On OneSay's service today, the Agent does not hear the board in a call that a person starts (ESP32 SDK 0.1.9 and earlier). Use the page to flash the board and to see it join; to talk, build the example as below and let the board start the call. A call made from the page is still paid from your allowance.

You need Chrome or Edge on a computer (the page reaches the board through Web Serial), an ESP32-S3-BOX-3, a USB cable, and a OneSay account on the pre-production environment with an Agent allowance and a Device that OneSay has set up for calls.

  1. Sign in to the OneSay Cloud Console and open Flash BOX-3 (/cloud-classic/devices/flash-box3/).
  2. Choose the Device, with its Project, Environment and Application.
  3. Enter the board's Wi-Fi name and password. The password stays in the page and is written only to the board.
  4. Select Prepare. The page creates the provisioning code, the Device secret, the microphone Source, the Room and the two Delegations for the first call.
  5. Connect the board by USB, select Connect and flash and choose its serial port. The page checks the firmware (the ESP32 SDK v0.1.11 box3_agent_call example) and writes it with the board's settings. The board restarts.
  6. The board asks for each step of the call. Allow each request in the page; nothing is allowed for you. The page starts the Agent; once connected, the board hears it through LiveKit's own subscription. When the page says the board is in the call, the board can play the Agent's voice, but the Agent does not hear what you say (see above).
  7. Select Stop the Agent to end the call. Keep the page open and the board connected until then.

Console describes the page. To change the example or bring up your own board, use the ESP-IDF way below.

Build with ESP-IDF: what you need

  • An ESP32-S3-BOX-3 and a USB cable.
  • ESP-IDF 6.0.2 exactly. Other versions are refused at build time.
  • idf-component-manager 3.1.2, the version we tested: 3.0.3 fails to solve the RTC dependencies. Before idf.py set-target, in ESP-IDF's Python environment: python -m pip install idf-component-manager==3.1.2.
  • A OneSay account and project on the pre-production environment, with money left in its allowance. Each run is paid from that allowance for what it uses.

1. Set up the resources

In the OneSay Cloud Console, or through the API:

  1. Create a Device and take its provisioning code. Device Provisioning explains the code.
  2. Create a Source for its microphone.
  3. Create a Room and an AppSession for the board. Let nobody else join the Room.

The Device needs the permissions and pair Grants listed in A Device as the Agent's microphone and speaker. The board's actions need your Consent: joining the Room and publishing its microphone. You allow each one for that exact request. Once connected, the board hears the Agent through LiveKit's own subscription, which asks for nothing more.

2. Get the firmware

The SDK's reference example for this board is examples/box3_agent_call. It has two parts:

  • the agent_call flow, which runs the call and contains no board code;
  • the BOX-3 board layer, which adds the microphone with echo cancellation against the speaker, the speaker, Wi-Fi, trusted time and credential storage.

This is a reference example, not product support for the board. Audio quality on your own hardware stays yours. It runs on Espressif chips only: Espressif's components are fetched at build time, not included.

Access. The SDK's repository is private. To ask for access, write to sdk@onesay.com with your GitHub account name; the README's commands below fetch it with a Git credential of that account. If Git answers Repository not found, your account does not have the access yet, or your Git credentials are not that account's.

Open a terminal where the environment of ESP-IDF 6.0.2 is active (installed with Espressif's Get Started guide for v6.0.2; a plain shell may have no python). First export the two addresses of the environment you use:

Terminal
export ONESAY_CONTROL_API_URL="<CONTROL_API_URL>"
export ONESAY_REALTIME_URL="<REALTIME_URL>"

Replace <CONTROL_API_URL> and <REALTIME_URL> with the addresses of the environment you use; on the pre-production environment (Staging) they are https://api.staging.onesay.com/v1 and wss://realtime.staging.onesay.com/v1. Production and more regional nodes will follow, each with its own addresses.

Then, in the same terminal, open examples/box3_agent_call/README.md in the SDK you received and run the block of its Build and run section as it is, without its last line (idf.py -p <port> flash monitor, which needs the board; section 4). That block clones the SDK, copies the example to ~/my_call with the SDK at components/onesay, installs idf-component-manager 3.1.2, writes the two addresses to the project's sdkconfig.defaults (they must be there before idf.py set-target), fetches the codec component the board layer needs from the ESP Component Registry, and builds. It can run again as it is: it skips a clone or a copy that is already there and replaces the two address lines it wrote before. If an address is not exported, the shell names it and writes nothing; export it and run the block again.

Inside the block the order matters. The two addresses go into the project's sdkconfig.defaults first, as these two lines with the addresses you exported in place of the placeholders:

Text
CONFIG_ONESAY_CUSTOM_CONTROL_API_URL="<CONTROL_API_URL>"
CONFIG_ONESAY_CUSTOM_REALTIME_URL="<REALTIME_URL>"

Only then does it run python setup_codec_board.py and idf.py set-target esp32s3. The codec step needs the network and the patch tool. On Linux and macOS patch is usually installed; on Windows it comes with Git for Windows (C:\Program Files\Git\usr\bin): add that folder to PATH in the ESP-IDF terminal if patch is not found.

Endpoints, identities and volume come from the board's NVS. None is built in. The example's README lists every NVS key and how to write them (nvs.example.csv, make_nvs.py); the SDK's docs/QUICKSTART.md shows the requests the board prints. Set the environment key to 0, for ONESAY_ENVIRONMENT_CUSTOM: the board then uses the two addresses the block wrote.

Do not change them later with idf.py menuconfig: a changed sdkconfig re-solves the dependencies without the SDK's manifest, and the build stops on a missing json component. To change them, delete sdkconfig, dependencies.lock and build, and start again.

3. Use these board settings

These are what our BOX-3 runs used:

SettingValueWhy
App partition3 MB, LiveKit minimal's partition tableThe image with esp_capture's echo canceller is about 2.1 MB
Main task stack20 KiBControl calls run TLS on this task
RTC signaling task stack8 KiB, ONESAY_RTC_SIGNALING_TASK_STACK_SIZE4 KiB overflowed on the board
PSRAMOnThe audio encoder's 40 KiB stack lives in external RAM
Serial logsWARNKeeps the SDK's and ESP-IDF's logs quiet. This example still prints the resource IDs and idempotency keys your tool needs

Bringing up your own board gives the reason for each one, and the memory settings.

Speaker volume is yours to set. The BOX-3's clear level was found by ear, and it interacts with the echo canceller's reference level: if the reference clips, lower its input gain.

4. Flash

The README's block ended by building. Connect the board by USB and, in ~/my_call:

Terminal
idf.py -p <port> flash monitor

Then write the NVS image as the example's README shows (make_nvs.py and the esptool line). To build again after a change, run idf.py build in ~/my_call.

5. Run a call

Use the device-initiated call: the board starts the call itself. This call is available since SDK 0.1.9; until a later release, no one can start an Agent on the microphone of a board on 0.1.10. It has not been verified on a board with a released SDK yet. Add the row agent_prof,data,string,assistant to your nvs.csv (the value is the Agent profile; use your Application's), write the NVS image again, create the board's standing Delegation once as its owner (node partner-helper.mjs standing-delegate --context ctx.json --port 53682, which asks your Consent), and reset the board. room_id, rtc_app_sess, rtc_conn_dlg and key_rtc_conn are then not needed, and you start nothing on a computer: the service sends the Agent in, and the board hears it once it joins. The board prints no publication line, so there is no pub_ id to copy. Wait for the chime, then speak. Press BOOT to hang up, and again to start the next call. This needs two things switched on by OneSay for your Environment (contact OneSay): device-initiated calls and, for 0.1.10 boards, the service side of the 0.1.10 microphone change. Start an AI Agent call from an ESP32 board describes it.

With SDK 0.1.9 or earlier, a person can also start the Agent. On OneSay's service today, the Agent does not hear the board in a call that a person starts (ESP32 SDK 0.1.9 and earlier); use the device-initiated call above. The steps of the call that a person starts are:

  1. Reset the board. It joins the Room. A cold Room may ask it to wait: it retries by itself, up to six attempts, and each new attempt needs your Consent again.

  2. When connected, the board prints its microphone's publication on one line:

    Text
    ONESAY_AGENT_CALL_PUBLICATION pub_...
  3. Start the Agent with that publication as its input: node partner-helper.mjs agent start --context ctx.json --publication pub_..., or from your app with the JavaScript SDK's client.rtc.agents.create. Nothing goes back to the board: LiveKit subscribes it to the Agent's voice.

  4. Wait for the chime, then speak. The microphone stays silent until the board can hear the Agent, up to 75 seconds, and what you say before the chime is not heard. The Agent answers through the speaker. What the Agent says before then is lost.

  5. Stop the Agent with node partner-helper.mjs agent stop, or from your app with client.rtc.agents.stop. The board layer sets no time limit, so a pause does not end the call; it ends when the Agent or the server closes it, or the allowance runs out, and the board prints one result line.

  6. To make the next call, reset the board. A call that a person starts needs a new Room, AppSession, Delegation and key on the board each time, so this example makes one call per boot. A board that starts its own calls (agent_prof in NVS) starts the next call when you press BOOT, and BOOT also hangs up during such a call; the example's README describes it.

The result line

ONESAY_AGENT_CALL {json} reports each step, why the call ended, render counters, and heap and stack figures. It carries no IDs, credentials or audio. A rendered frame means your speaker path accepted it, not that anyone heard it.

Before the call, ONESAY_BOARD_CONFIG {json} shows the board's mode and, in missing_keys, each NVS key the board needs and did not find (names only, never values). When the service refused a step, the result line also carries server_error, the service's public error code for it, for example delegation_required. When a call the board started ended without the board ending it (OneSay removed the board, LiveKit reports for example "Participant Removed" or "Room Closed", or the connection was lost for good), the board reads the call once and the result line also carries call_state and, once recorded, end_reason, for example budget_exceeded when the board's owner could not pay for the Agent as it was about to join (a call that reaches the money limit later reads ended).

If something goes wrong

What you seeWhat it means
The board refuses to start, before any networkThe configuration is incomplete: echo cancellation, or the Room's confirmation, is not set
At configure, error 3 (ONESAY_ERR_WIFI_UNAVAILABLE)No wifi_ssid in NVS, or Wi-Fi or trusted time did not come up
At configure, error 1 (ONESAY_ERR_INVALID_ARG)An NVS key is missing (named in missing_keys) or holds a bad value
At connect_audio, error 1 (ONESAY_ERR_INVALID_ARG), after prepare passedWith SDK 0.1.9 or earlier: the board's clock was more than about 5 s behind the service (SNTP had not finished), or more than about 60 s ahead of it. Start the call after the clock is set, or update: from SDK 0.1.10 the service judges the join material's time, as LiveKit's SDKs do
Error 6 (ONESAY_ERR_AUTH)A credential: no dev_secret, no bearer, or no Delegation from the console
It stops at prepareThe Room was still being prepared and the retries ran out, or a server answer was final. Read the error in the result line
It connects but stays silentThe Agent did not start or publish its voice (check the agent start line), or its first words came before the board could hear
A verification failure in the logs as the call endsThe normal end of such a call today, not a fault

Next