Skip to content
OneSay Developers

Guides

How an AI Agent talks through an ESP32 board

An ESP32 board can be the microphone and speaker of a OneSay AI Agent, as a pre-production preview. This page explains how that call is put together, and why. To run one, follow Talk to an AI Agent on an ESP32-S3-BOX-3.

An ESP32 board can be the microphone and speaker of a OneSay AI Agent, as a pre-production preview. This page explains how that call is put together, and why. To run one, follow Talk to an AI Agent on an ESP32-S3-BOX-3.

The short version

The Agent does not run on the board. It runs in OneSay's service and joins a LiveKit Room. The board joins the same Room as an ordinary participant: it sends its microphone in and plays what comes back. A person is the authority for the call: either they allowed their board in advance to start calls, or they start the Agent and allow every step themselves. The Agent replies in the language the person speaks; before anyone speaks, or when it cannot tell the language, it replies in Simplified Chinese. No API, SDK or board setting sets the language.

Who does what

PartIts jobWhat it never does
The person who owns the DeviceAllows their board in advance to start calls, or starts and stops the Agent and allows each step
The board's firmwareCaptures with echo cancellation, plays audio, keeps its credential; asks OneSay for a call when its owner allowed thatCreates or stops an Agent itself, or grants itself anything
The ESP32 SDKConnects, publishes, subscribes, reports each stepTouches I2S, GPIO or the codec
OneSay's serverDecides who may join, publish and listen, and bills the conversationTrusts a client's own claim
LiveKitCarries the audio in real timeDecides who is allowed

Why a board cannot start an Agent

Firmware can be read and copied, so nothing a board claims is a permission. An Agent costs money each time it runs, and that decision belongs to a person. OneSay refuses createAgentExecution and its stop from a Device, whatever the firmware does. Joining a Room or connecting audio never starts an Agent.

From ESP32 SDK v0.1.9, the owner can allow their board in advance, with a standing Delegation, to start Agent calls for them. OneSay then starts the Agent and checks the Delegation, the owner and the owner's permissions on every start; the board still never calls createAgentExecution. See Start an AI Agent call from an ESP32 board.

What happens in a call

These are the steps of a 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 call the board starts itself (Start an AI Agent call from an ESP32 board).

  1. The board joins. It exchanges its own credential for a short-lived token, and joins under your Consent.
  2. The board publishes its microphone. It prints the publication's pub_ ID, and an empty Room stays empty so far.
  3. You start the Agent, naming that publication as its only input. OneSay checks that the Device is paired to you for this Application, and that you delegated its media.
  4. The Agent joins and speaks through an output publication, whose ID your app reads.
  5. The board subscribes to that output, under a Delegation and your Consent. Until this takes effect it hears nothing.
  6. You talk. The Agent listens to the board's microphone and answers through the board's speaker.
  7. The call ends. You stop the Agent. The agent_call flow sets no time limit of its own: by default it ends when the Agent or the server closes the call, or when the money allowance runs out.

Why the Agent's first words can be lost

From the Agent's output appearing to the board being able to hear it took 24 to 28 seconds in our runs. The Agent may already be speaking, and what it says in that time does not reach the speaker. If the microphone is already sending, the Agent answers what it hears, and that reply is lost too. This is a limit of today's path, not of your board. So box3_agent_call holds its microphone silent until the board can hear, up to 75 seconds, then plays a short chime that says to speak. That ran once on our board, and no person has judged the chime yet.

From reset to a board that can hear took about a minute and a half in our runs; a product's path will differ.

Why echo cancellation is required

The Agent decides on the server whether someone has started to speak. The sound of the board's own speaker, picked up by its microphone, looks like a person talking, and the Agent keeps stopping. So your capture must deliver echo-cancelled audio, and you declare that with capture.echo_cancelled. The SDK refuses the connection without it, before any request. The SDK does not perform or check echo cancellation: the quality is your board's.

Why the Room holds only the board and the Agent

The board plays every audio track it subscribes to, so a third participant would come out of its speaker too. You confirm this with room_device_and_agent_only, and the example refuses to start otherwise.

How a call ends, as the logs show it

When the Agent's call ends, the board's connection closes with a verification failure, and the Agent reports that its input has gone. That is the normal end of such a call today. It reads as a fault in the logs, and it is not one.

A very long reply can be cut short by the reply limit in the Agent's policy.

Set the Agent's name, persona and language

In OneSay Cloud, open Devices, then Device configuration, and choose the scope: the organization, the current project or the current environment. A project's values apply over the organization's, and an environment's over the project's.

  • Name: what the Agent calls itself, up to 40 characters.
  • Persona: how the Agent speaks and behaves, up to 2,000 characters.
  • Language: the language the Agent replies in before the user has spoken, or when it cannot tell the user's language. Otherwise it replies in the language the user speaks.

Leave a field empty to inherit it from the scope above. Each field is plain text: no line break, no leading or trailing space and none of < > ` { } [ ] # *. The persona sets only the Agent's name, tone and topics. The platform's own instructions come first, and the persona cannot change them.

A saved change applies from each board's next call; a call already running keeps the values it started with. Your server can read and replace the same values through the API: getEnvironmentDeviceConfiguration and replaceEnvironmentDeviceConfiguration (and the organization and project pairs), sending the whole value set with the expected_version from the read.

The voice, the board settings and the service region show Not open yet until they work end to end.

What has been verified

On one ESP32-S3-BOX-3, on the pre-production environment: a person heard a clear, complete reply; several turns ran using recorded speech; calls ran for up to about 4 minutes; and the board ended a live call itself once, with no crash. These calls are not yet reliable: the server may end a call early, and we are looking into why.

Not yet verified on a device: interrupting the Agent, a live conversation with several turns, and longer calls. ESP32-P4 is declared, not yet built or run by us.

Next