One call, two planes: how voice reaches an agent

Press Call in an agent room. The desktop moves from Connecting to Listening. You speak, the agent thinks, and its answer comes through the speaker.

Then look back at the room. What you said is there as a message, marked as spoken. The call felt immediate, but it did not create a second conversation that vanishes when the audio ends.

That behavior shipped across four public projects: SuperMessage v0.1.4, SuperDial v0.0.1, SuperExchange v0.0.7 and AgentPod v0.1.135. Their division of responsibility is the interesting part.

A trustworthy agent call needs more than a media socket. Someone must decide whether the caller belongs in the agent’s room. Peers need encryption keys. A spoken turn must enter the agent’s existing context and stop when the caller hangs up. Dead participants must eventually disappear. The transcript should join the conversation rather than become an unrelated log.

The shipped design handles those requirements with two cooperating planes: Matrix keeps authority and the durable conversation; LiveKit carries low-latency encrypted audio.

One call, two planes

The boundary looks like this:

                 MATRIX: authority + durable conversation

 SuperMessage ── call membership ─────────────► AgentPod
      │                  │                         │
      │                  │                         ├─ authorize the caller
      │                  │                         ├─ start or cancel a turn
      │                  │                         └─ keep the agent's encrypted
      │                  │                            SUPERDIAL device
      │                  │
      ├─ OpenID ─► SuperExchange ◄─ membership decision
      │                  │
      │                  └─ short-lived, one-room LiveKit token
      │
      ├════════════ encrypted LiveKit audio ════════════┐
      │                                                  │
      ▼                                                  ▼
 person's microphone                               superdial-agent
 and speaker                                        speech → agent → speech
      │                                                  │
      └──── transcript / spoken message via Matrix ──────┘

                 LIVEKIT: low-latency media

Matrix is the control and conversation plane in this design. It already knows the person, the room and the agent. It carries call membership, encrypted media-key delivery, transcripts, spoken-message markers and the room’s human-readable history.

LiveKit is the media plane. It is built to move time-sensitive audio. Its credential is short-lived and scoped to one derived media room. It does not independently decide whether a Matrix user belongs in the agent room, and it does not become the durable conversation store.

This is not a claim that every MatrixRTC or LiveKit application must use this exact split. It is a choice about authority: keep identity, room policy and conversation state in the system that already owns them; give the media service only the authority it needs to carry the call.

Narrow authority at every hop

The path from clicking Call to hearing audio is a chain of increasingly specific decisions.

First, the SuperMessage desktop controller begins a join through its protocol seam. It does not open the microphone first and ask questions later. The call joins before native audio devices open, so a refused call never needs to touch the microphone. SuperMessage also installs its encrypted to-device handler before publishing membership, avoiding a race in which a peer key arrives before the client is ready to receive it (PR #191).

SuperDial then uses the Matrix room as the call’s shared name and publishes MatrixRTC call membership. When media access is needed, it asks the homeserver for OpenID. SuperExchange validates that identity and device, then asks AgentPod a different question: may this Matrix user join a call in this particular agent room?

Authentication and authorization are separate here. Matrix establishes the caller. AgentPod, which already knows whether a room belongs to an agent and who is in it, decides whether that caller belongs there. The public integration names explicit refusal cases such as not_member, not_agent_room, harness_mode and calls_disabled (AgentPod PR #949).

Only after that decision does SuperExchange mint a LiveKit credential. The identity is derived from the Matrix user and device; the media-room name is derived from the Matrix room; and the token grants capabilities for that one room. The v0.0.7 release records publish, subscribe and the agent-state attribute as its allowed media capabilities.

Finally, both peers join encrypted media. SuperDial generates per-call media keys and delivers them Olm-encrypted to the participating call devices. AgentPod gives each bridge agent one appservice-minted, encrypted SUPERDIAL device and starts superdial-agent for the room. The agent does not appear through an unrelated bot identity invented by the media layer.

Each hop reduces authority:

Matrix identity
  → permission to join this agent room
  → permission to use this one media room
  → encrypted audio between the admitted peers

The media server gets enough authority to transport audio, not enough to redefine room membership.

Voice returns to the conversation

It would have been simpler to treat the call as an opaque audio session: send sound in, play sound out, discard the interaction when everyone leaves. That would also create a side channel around the product’s existing conversation model.

SuperDial instead defines separate Matrix-facing artifacts for encrypted media keys, live transcript coordination and a dev.superdial.spoken marker on the person’s room message. SuperMessage posts the recognized words as that person’s message and marks it as spoken. The design does not claim to archive raw audio in Matrix.

AgentPod recognizes the marker and routes the text through the agent’s ordinary session with a small spoken-turn instruction. The reply text is also sent to superdial-agent, which turns it into speech. The path is therefore:

voice input
  → transcript
  → room message marked as spoken
  → existing agent turn
  → reply text
  → speech output

That reuse matters. The call gets the conversational context already present in the room instead of opening a parallel voice-only session. It also gets the existing turn identity and cancellation machinery. Voice changes how a turn enters and leaves the system; it does not need to replace what a turn means.

The result is a useful separation of time scales. Audio remains on the low-latency path. The human-readable interaction returns to the durable path where a person can review it after the call.

Hang-up is a distributed operation

Closing an audio track is not the same thing as ending a call.

If the agent is speaking when the person hangs up, AgentPod maps the named spoken turn to cancellation in the existing agent session. A cancelled turn ends silently. The turn id is scoped to its room, and the cancellation targets the currently running turn it names rather than broadly stopping unrelated work.

The client has ordering problems of its own. A user can press hang-up while join is still in flight. SuperMessage waits for that join to return before leaving. It also keeps an earlier call in a leaving state and refuses to start a replacement until leave finishes. Otherwise, a slow leave from the old call could clear the membership state used by the new one.

Processes can disappear without running any cleanup at all, so client-side finally is not enough. Before joining, SuperDial arms a Matrix delayed leave. While LiveKit still sees the participant, SuperExchange restarts the delay. When the participant disappears, SuperExchange sends the delayed leave. The SuperExchange v0.0.7 notes also describe protections against webhook replay, replaced delays and a stale session deleting a newer rejoin.

SuperMessage bounds its own wait, too. A leave that has not returned after 45 seconds is dropped so later calls can proceed; the homeserver-side delayed leave remains the recovery path.

These are all versions of the same rule: when state spans a durable control plane and an ephemeral media plane, every exit needs an owner, an ordering rule and a timeout-backed route to convergence.

Keep races out of the webview

The desktop implementation separates four concerns:

  • superdial::Call implements the shared MatrixRTC and LiveKit protocol;
  • the core controller owns call state and race rules through CallLink and CallAudio abstractions;
  • the Tauri desktop layer owns native microphone and speaker streams;
  • the Svelte interface renders snapshots and sends user intent.

Native audio stays outside the webview. The desktop path uses cpal, adapting device-specific sample rates and channel layouts to 48 kHz mono. Its speaker buffer is capped at 300 milliseconds. Muting sends silence rather than stopping frames, allowing the agent’s utterance detector to recognize that a spoken turn has ended.

The UI boundary has a subtler race. Tauri does not guarantee that an emitted event will be ordered against a command response. A late response saying “Connecting” could therefore overwrite a newer “Listening” event. Every call snapshot carries an increasing sequence number, and the UI keeps the newest snapshot it has seen.

That structure is useful beyond this application. Put protocol behavior behind one seam, platform audio behind another, and state-machine rules in a controller that can be tested without a microphone, a webview or a live call. Then make ordering explicit at the boundary where native and web runtimes meet.

This first calling release was desktop-only. SuperMessage v0.1.4 did not build the LiveKit calling feature for iOS or Android, so the architecture should not be read as a claim of mobile support in that release.

Test the boundary map, not only the pieces

A feature spanning four repositories can have green unit tests everywhere and still fail between them. The public evidence therefore matters most where it crosses the same boundaries as production.

SuperDial shipped a headless caller and a two-caller integration path. SuperMessage tested join and leave races, the one-call rule, audio shutdown and stale snapshot ordering, and its labelled pull request built the macOS, Linux and Windows installers. SuperExchange tested slow membership checks, independent delayed-leave timers, webhook replay and stale sessions.

AgentPod’s end-to-end record crossed almost the whole map: a spoken reply was heard, hanging up cancelled a running turn, a killed caller’s membership cleared after 23.5 seconds, and ordinary chat still worked afterward.

That is stronger evidence than a media-loopback test alone. It exercises identity, room authorization, token exchange, encrypted media, speech recognition, agent execution, cancellation and delayed cleanup. Each boundary has its own local tests, but the full call verifies that the boundaries agree.

What the first macOS builds taught us

The architecture did not make the packaged client infallible.

SuperMessage v0.1.4 could obtain a token, pass room authorization, bring up the agent and publish client membership, then quit before the client connected to LiveKit. That sequence was useful precisely because it crossed both planes: the confirmed control-plane events narrowed the remaining fault to client media setup. PR #193 added the final application’s -ObjC link requirement and a CI check that inspects both slices of the universal binary. The repair shipped in v0.1.5.

A second follow-up addressed microphone permission persistence. PR #195 ad-hoc signed the bundle and checked its bound identity; the public diagnosis says the unsigned bundle was the most likely cause of repeated prompts. That change shipped in v0.1.6.

The narrow lesson is not that a distributed trace proves a native diagnosis. It is that traces can show the last boundary that succeeded, while the packaged artifact still needs independent validation. Protocol proof and executable proof answer different questions.

A checklist for adding voice to an existing system

This implementation suggests a practical review list:

  1. Choose one source of room authority. Do not let the media service quietly create a second membership model.
  2. Mint narrow media credentials. Bind identity, room and capabilities, and keep the credential short-lived.
  3. Separate control, media and durable conversation. Put each kind of state where its guarantees fit.
  4. Make spoken turns ordinary application turns. Reuse context, cancellation and the readable record.
  5. Model join and leave as state machines. Test hung joins, hung leaves, replacement calls and out-of-order UI delivery.
  6. Give dead clients a server-side cleanup path. A vanished process cannot execute cleanup code.
  7. Test the complete trust chain. Identity, authorization, token scope, keys, media, turn execution and reconciliation all matter.
  8. Validate native artifacts separately. A correct protocol does not prove that the final bundle contains and identifies everything it needs.

“Call an agent” looks like one button. Behind it are several kinds of authority and state that should not be collapsed into one service merely because they belong to one interaction.

The useful design choice is the boundary: Matrix decides who and what the conversation is, then keeps its durable record. LiveKit moves the encrypted audio quickly. SuperExchange narrows one authority into the other. SuperDial makes both sides speak the same call protocol. AgentPod turns spoken input into an ordinary agent turn. SuperMessage contains the native devices and the client races.

One call, two planes—and one conversation when the audio stops.