Skip to content

Run the call worker

The call worker joins every live call of the teams it serves and writes each person’s whole turns into the call’s chat, under their name, and sends the people in the call captions of what each is saying as they say it. It brings the chat’s agents into the call and speaks the reply of the one a person’s turn asks. It is a process of its own, node server/call-worker.ts, that runs beside the API on the same host and with the same .env, so media work never stalls the API.

It needs LiveKit’s three settings, AGENTS_LIVEKIT_URL, AGENTS_LIVEKIT_KEY and AGENTS_LIVEKIT_SECRET, and stops at start without them. Every call is transcribed, so it also needs the AssemblyAI pair, AGENTS_ASSEMBLYAI_KEY and AGENTS_ASSEMBLYAI_URL, that Turn on connectors, views and speech describes, and stops at start without it. Agents speak through the ElevenLabs pair, AGENTS_ELEVENLABS_KEY and AGENTS_ELEVENLABS_URL, from the same page. Without it the worker still starts, brings agents in and asks them, and each reply stays in the chat unspoken, with a line in the worker’s log. It also stops when LIVEKIT_DEBUG_LOG_ROOM_EVENTS is set, since the LiveKit client would then print the tokens LiveKit refreshes. Files and parameters the server keeps lists where LiveKit’s key and secret are kept.

It leads the scope call-worker:<runner teams>, from AGENTS_RUNNER_TEAMS, and claims a live call only while it leads, so two copies never both run one. Several copies may run on one database. The one that leads runs every call, and another takes over within seconds when it stops. It joins a claimed call’s room once a person is in it, and leaves a room nobody has been in for 10 seconds.

Once it is in a call’s room, the worker brings in the chat’s agents that have a home machine to answer on: a DM’s agent, or a room’s first four in the order they were added. Each joins the room as agent:<id> on a connection of its own, which sends the agent’s voice and hears nothing, since the worker hears for it. An agent removed from the chat or archived leaves the call within a second, and the next one takes its place.

For each person’s turn the worker asks one agent at most: the one the turn names first, or for a question the only agent in the call, or with several the first agent in it. The agent’s turn says it is speaking aloud, and the worker speaks only what the record stores of its reply, a sentence at a time, one agent at a time, and a reply never starts while a person talks. Tables, inline code and bare links stay in the chat and are not spoken. A line whose agent was not yet asked when a worker stopped is asked by the next worker that leads the call.

A person who starts to talk while an agent speaks turns its voice down to an eighth at once, for 1.2 seconds or until they stop. Their words stop the agent unless they are only a backchannel such as “mm-hm”, “yeah” or “okay”, or the agent’s own last sentences heard back through a speaker. A “yeah” said over an agent is still that person’s line, and asks no agent. The whole reply stays in the chat either way. The worker’s log says how long each drop and each stop took after the person started talking, as ducked <ms> ms after <person> started talking and stopped <agent> <ms> ms after <person> started talking over it. A stop’s time holds the speech service’s time to give the words that took the floor.

While a person talks, the worker sends their words so far to the people the call holds as LiveKit data on the captions topic, which the worker’s token may send and no person’s may. A caption holds back the word still being heard and any words that could still grow into a secret the server knows, and is never stored. The worker sends none to an empty list of people, since LiveKit would send that to everyone in the room.

  • gomoe.dev. Each deploy runs it as agents-call-worker.service beside the API, as the API’s user on the API’s .env, and restarts it on that deploy’s code. systemd starts it again 3 seconds after it stops. It runs only once Terraform has written /agents/calls and a person has put AssemblyAI’s key at /agents/assemblyai/key, since it stops at start without LiveKit’s settings or that key. Without either the deploy says why, and stops and removes a worker an earlier deploy started.
  • An instance. bin/agentsctl up starts it as the call-worker process for the instance’s team, and bin/agentsctl down stops it first.