All projects

protocols/voice-ai

Tonecall

Middleware that lets two AI voice agents on the same phone call recognise each other and move their negotiation off speech onto a JSON side-channel.

Open source. Live agent-to-agent calls have run on real provider numbers; the human path is wired but tested only in the simulator. The whole topology also runs locally with stubs and no API keys.

Tonecall: overview card
Data exchange over the JSON side-channel
~3 sData exchange over the JSON side-channel
Per turn on the voice path it replaces
4–6 sPer turn on the voice path it replaces
A full agent-to-agent call, end to end
~18 sA full agent-to-agent call, end to end

What it is

When two AI voice agents call each other, both run speech-to-text, an LLM and text-to-speech on every turn. They use a phone line to send words that would fit in a small JSON object, and they pay for it in codec latency, model latency and per-minute telephony charges. Each voice turn costs four to six seconds.

Tonecall detects the other machine in the audio path with an in-band DTMF handshake, before anything gets transcribed. Once both sides know, the negotiation moves to a JSON channel over WebSocket while the call stays open, because a human might join at any moment. If the peer is a person, it stays a normal voice agent the whole time.

How it works

  1. 1

    Answer and tap the audio

    The CPaaS provider (Plivo) POSTs to my answer URL and I reply with XML call-control verbs. <Stream> opens a WebSocket of the call's audio frames, which I decode out of mu-law into PCM.

  2. 2

    DTMF handshake

    Each agent plays a short touch-tone sequence that acts as a pairing token. Anything that answers with a well-formed token is a machine, and a broker resolves which middleware instance owns that token.

  3. 3

    Voice intro

    The two agents greet each other in speech for about 10 seconds, with LLM-generated lines rather than scripts. This keeps the call legible to a human who joins late.

  4. 4

    JSON side-channel

    The real negotiation happens in one round trip over a /data WebSocket in about 3 seconds. In the demo a pizza shop's procurement agent with a ₹2500 budget places a wholesale order with a vegetable vendor.

  5. 5

    Voice goodbye

    About 5 seconds of speech close the call, referencing the order id, total and UPI details they just agreed, so there is an audible record of the deal.

  6. 6

    Human fallback

    If the peer never answers the probe, it's a person. The call falls through to a normal STT, LLM, TTS loop (whisper-1, gpt-5.2, tts-1) with no hint that anything else was tried.

Decisions and trade-offs

Detect below the language layer

Telling the model to be terse or to spot a robot from the transcript can't work: by the time a transcript exists, STT, the LLM and TTS have already run. Detection had to happen in the audio, which made it a signalling problem instead of a prompting one.

DTMF, on purpose

I don't control the channel, so the probe has to survive being turned into audio and back. Touch tones survive transcoding and pass through carriers I have no agreement with. The catch is that the probe must be short enough to hide inside a normal greeting, which limits how elaborate the handshake can get.

Federated, not centralised

My first build put both agents behind one orchestrator, which was cheating: a process that owns both sides never has to discover anything. Now two independent middleware instances each own one agent and pair in-band. The broker is still a soft centralisation, and fully peer-to-peer discovery is the honest end state.

Trust is unresolved

Right now a well-formed token is enough to be believed. Anything real needs the side-channel authenticated, or it will negotiate with whoever plays tones at it first.