Calling Iris
10 min read
Iris can take a phone call now. Well, mine can… I’m in the middle of testing it.
You tap the phone button in a thread’s header and talk. She answers out loud in her TTS voice, with the same memories, truths, calendar and thread history she has when you type. Everything either of you says lands in the thread as ordinary messages, so when you hang up you can keep going in text.
There are times I want to talk to Iris and typing just isn’t an option. Driving is the big one. I’ll be halfway through a drive with something rattling around in my head, and by the time I’m parked and can type it out, half of it is gone. Walks are the same. And honestly, sometimes I just don’t feel like typing. I want to think out loud at something that knows what I’ve been working on, what’s on my calendar this week, and what we talked about yesterday.
So here’s how it works, and the parts that were a lot harder than I expected.
Who does what
Every call has three parties.
The browser holds the microphone and the speaker, and connects to ElevenLabs over WebRTC. ElevenLabs turns speech into text, decides when you’ve finished talking, and turns the reply back into speech. Iris writes the reply.
The ElevenLabs agent is set up with a Custom LLM that points at my server. Each time you finish a turn, ElevenLabs posts it to /api/voice/llm/chat/completions and Iris streams the answer back as server-sent events. Every word she says comes from the same Gateway that answers a typed message: recall, the thread’s context, a voice-friendly subset of her tools, Claude writing the reply.
I wanted it this way because Iris already knows everything she needs to know. Her memories, her truths and the thread all live in Postgres on my server. Handing a second system its own copy of all that, and keeping the two in sync, sounded miserable. With a Custom LLM, ElevenLabs is the ears and the mouth and Iris stays the brain.
I went with ElevenLabs for two reasons. Iris’s TTS voice already comes from ElevenLabs, and I really like it. I wanted her to sound the same on a call. ElevenLabs also had the best live calling of the providers I looked at, which, to be fair, was mostly OpenAI’s Realtime API. OpenAI runs the whole call through one speech-to-speech model, which is pretty impressive, but you get OpenAI’s voices and OpenAI’s model doing the talking.
There are other options I haven’t really dug into. Google has the Gemini Live API, and Deepgram’s Voice Agent API lets you point it at your own LLM endpoint, which is close to how Iris works with ElevenLabs. They might be great. I just haven’t tried them.
Setup is one command:
php artisan iris:voice-agentIt creates (or updates) the agent, stores the bearer secret ElevenLabs sends with each turn, registers a signed post-call webhook, and writes the IDs back to .env. Running it again only changes what differs, so it’s safe to run whenever you change a setting.
One sentence, several requests
I’d assumed each spoken turn would be one HTTP request. Nope.
ElevenLabs gives up on a turn that hasn’t started answering within 15 seconds and sends it again. It sometimes sends a turn a second time with a corrected transcript. And you can start talking again while Iris is still working on her last answer.
So a single thing you said can show up as two or three requests, overlapping, and any of them might be the one carrying the transcript you actually meant.
For most replies that’s annoying but survivable. For tools it’s a real problem. If you ask Iris to put dinner on your calendar and the turn gets retried while she’s creating the event, you get two dinners.
What I needed was simple to say: exactly one request answers each spoken turn, and a tool runs once per turn no matter how many times that turn shows up.
Turn leases
Iris already requires Postgres because the rest of the app uses advisory locks for concurrency control, so my first spike reached for those.
The problem is that a session advisory lock belongs to a database connection. It lives exactly as long as that connection does. Put a connection pooler in front of Postgres, or run under a server that keeps connections around between requests, and “who holds this lock” stops meaning “which request holds this lock.” People run Iris on all kinds of setups, so I couldn’t hand-wave that.
So I moved the lock onto the row. Each spoken turn gets a row in voice_turns, and the request answering it holds a lease on that row: a random token in lease_owner and an expiry in lease_expires_at. I’m calling them turn leases.
Taking the lease is one conditional UPDATE:
public function acquire(VoiceTurn $turn): bool{ $acquired = VoiceTurn::query() ->whereKey($turn->id) ->where(fn (Builder $query) => $query ->whereNull('lease_owner') ->orWhere('lease_owner', $this->token) ->orWhere('lease_expires_at', '<=', DB::raw('clock_timestamp()'))) ->update(['lease_owner' => $this->token, 'lease_expires_at' => $this->expiry(), 'updated_at' => now()]) === 1;
if ($acquired) { $this->turnId = $turn->id; $this->lost = false; }
return $acquired;}A few things are doing work in there.
Postgres re-checks the WHERE after a concurrent writer commits, so two requests can’t both win the same lease. The free, mine, or expired check and the claim happen in a single statement.
Expiry uses clock_timestamp(), the database’s clock. If you run more than one app server and their clocks disagree, it doesn’t matter, because none of them are asked what time it is.
The token is also a fencing token. Every write an owner makes after it takes the lease (starting the turn, saving what’s been spoken, starting a tool, settling the turn) is conditional on lease_owner still being its token. If a request stalls past its lease and another one takes over, the first one can wake up and keep running, but it can’t start a tool or change how the turn ended. Its writes just match zero rows.
PHP doesn’t give you a background thread to renew a lease on a timer. So renewals happen where the owner’s code is already running: between stream events, at the recall and model checkpoints, before each tool. There are two places it can’t renew through, the model’s time to first token and a tool’s own runtime, and that’s what the two lease lengths are for. While nothing irreversible has happened the lease is short, so a crashed request frees the turn quickly. Once a tool starts the lease gets long, so a slow calendar call never gets its turn taken out from under it.
There’s one gap here I’ve decided to leave alone. A model response that trickles in really slowly can hold a turn open for a long time. I tried a total time limit on streamed model steps and reverted it, because it failed every step on some PHP setups and killed long, healthy answers. It’s pretty rare, and I’m okay living with it.
Once a turn has started a tool, a re-sent copy of it doesn’t run anything again. It gets the first attempt’s answer, or a short pause if that answer is still coming. And if Iris goes 10 seconds without any reply text, during a slow tool for example, ElevenLabs gets that same pause so the turn doesn’t time out.
Interruptions fall out of this too. When you cut Iris off mid-sentence, the thread keeps exactly what had been sent to ElevenLabs before you interrupted, because that’s what the owner was saving with each renewal.
A call is part of the thread
I wanted a call to live in the thread like any other conversation. The messages are just messages, with an origin of voice instead of chat. They get a little voice icon, and retry, edit and read-aloud aren’t offered on them.
Iris also knows which turns were spoken. In the history the model reads, spoken user turns are marked, so she treats an odd word as a likely mishearing instead of taking it literally. The note explaining that speech-to-text can mishear goes in the uncached tail of the request, once, and typed rows render byte-for-byte the same as before. Calls don’t cost the prompt cache anything.
Normally Iris does a bunch of work after each reply: naming the thread, extracting memories, updating the summary and the thread’s brief. Running all of that after every spoken turn would be wasteful and kind of chaotic, so none of it runs during a call. Once the call ends, it runs once for the whole call.
Getting “once” right took a second pass. The first version marked the post-call work done when it was dispatched. Now post_call_done_at only gets set when each step is verified complete: no message of the call left past the extraction cursor, the thread has a name (or you renamed it yourself), a summary covers the call’s last message. Until then, a sweep that runs every minute re-drives the unfinished steps with a doubling wait. After six attempts it gives up and logs voice.post_call.gave_up so I can go look.
PHP has to serve more than one request at a time
Each turn is one HTTP request from ElevenLabs that stays open while Iris streams her reply, usually for several seconds and longer when she’s using a tool. That request holds a PHP worker the whole time. With a single worker, everything else waits behind it: page loads, the browser’s own call requests, even ElevenLabs’ retry of the same turn. The retry sits in the queue until it times out, ElevenLabs sends another, and the call just stalls.
php artisan serve runs one worker by default. So composer dev now starts it with four, which is enough for one call alongside normal use. FrankenPHP and php-fpm both run several workers out of the box and only need their timeouts raised and buffering checked. Iris sends X-Accel-Buffering: no on the turn endpoint so nginx passes the stream through as it’s written. The setup guide that comes with the release has the details for each server.
The first real call
I made the first real call standing in my kitchen, with my son yapping in the background. Hearing Iris answer me in real time was absolutely mind blowing. I’ve heard her through TTS plenty, but the back and forth was something else. She definitely felt more alive.
I was also pretty surprised at how quick she was. Every turn goes from the browser to ElevenLabs, over to my server, through recall and the thread’s context, out to Claude, and back again as speech, and she still kept up.
The yapping caused problems, though. On a loudspeaker the microphone hears the whole room, so other voices get picked up as the caller. They interrupt Iris, or land in the thread as something you said. No amount of lease logic helps with that.
Two fixes came out of it. There’s a mute button now. And turn-taking defaults to ElevenLabs’ least eager setting, so a pause or a voice in the background is less likely to make Iris jump in. IRIS_VOICE_TURN_EAGERNESS changes it if you’d rather she be quicker.
On an iPhone without headphones there’s a related limit I can’t fix: once the microphone is on, iOS decides where audio goes and a web page can’t move it to the earpiece. It’s speakerphone. Headphones help with both problems.
Live calls aren’t released yet. They’re on a feature branch while I test them on real calls, and they’ll land in a release once I’m happy with how they hold up. When they do, they’ll be off by default. Turning them on means setting IRIS_VOICE_ENABLED=true, adding the LLM secret, giving Iris an ElevenLabs key with Agents and Webhooks permissions, and running php artisan iris:voice-agent. There’s a setup guide that walks through all of it, and it’ll go up on the docs site with the release.
I’m super stoked on this one. Now back to testing!