Bottom Linear Gradient  Lines image

Article

3 min

read

Add a Human Operator to a Live Voice AI Agent

A human in the loop

Adam Kalsey

Adam Kalsey

EVP, Product

Add a Human Operator to a Live Voice AI Agent

In this article

Share

Angular Gradient Image

Build it free.

Create a space and ship your first call flow in minutes.

Subscribe

Tags

Voice AI

AI Agents

Developer Tutorials

This series builds a talking jack-o'-lantern for trick-or-treaters, and this post is part 8. If it's the first one you've read, go back to part 1. In part 7 my server took charge of pacing and modes. Its checks are good, but a person standing in the yard sees things a camera misses. A nervous six-year-old can look older in a tall hat, and a family of adults who'd love the full act might bring a stroller. Here I build a phone remote that runs the show and lets that person overrule the server.

Relay commands through the server

The pumpkin's page holds the call and every setting, and it runs on a computer hidden inside the prop. The remote is a phone-sized page I can open from anywhere in the yard. The two pages never talk to each other directly. The server sits between them, passing numbered commands from the remote to the page and the page's status back to the remote.

def command(self, kind, name=None, value=None):
    with self._lock:
        self._seq += 1
        self._commands.append({"seq": self._seq, "kind": kind, "name": name, "value": value})
        del self._commands[:-KEEP_COMMANDS]
        return self._seq

def commands_after(self, seq):
    with self._lock:
        if seq < 0:
            return {"seq": self._seq, "commands": []}
        return {"seq": self._seq, "commands": [c for c in self._commands if c["seq"] > seq]}
def command(self, kind, name=None, value=None):
    with self._lock:
        self._seq += 1
        self._commands.append({"seq": self._seq, "kind": kind, "name": name, "value": value})
        del self._commands[:-KEEP_COMMANDS]
        return self._seq

def commands_after(self, seq):
    with self._lock:
        if seq < 0:
            return {"seq": self._seq, "commands": []}
        return {"seq": self._seq, "commands": [c for c in self._commands if c["seq"] > seq]}
def command(self, kind, name=None, value=None):
    with self._lock:
        self._seq += 1
        self._commands.append({"seq": self._seq, "kind": kind, "name": name, "value": value})
        del self._commands[:-KEEP_COMMANDS]
        return self._seq

def commands_after(self, seq):
    with self._lock:
        if seq < 0:
            return {"seq": self._seq, "commands": []}
        return {"seq": self._seq, "commands": [c for c in self._commands if c["seq"] > seq]}
def command(self, kind, name=None, value=None):
    with self._lock:
        self._seq += 1
        self._commands.append({"seq": self._seq, "kind": kind, "name": name, "value": value})
        del self._commands[:-KEEP_COMMANDS]
        return self._seq

def commands_after(self, seq):
    with self._lock:
        if seq < 0:
            return {"seq": self._seq, "commands": []}
        return {"seq": self._seq, "commands": [c for c in self._commands if c["seq"] > seq]}

A command can start or stop the show, set a slider, or reset a group of sliders. The server adds one more kind of its own, the restart from part 7. Once a second, the pumpkin's page asks for any commands newer than the last one it applied, so each command lands once. A newly loaded page gets the current number and none of the backlog, so a reload can't replay old slider changes over its saved settings.

Status flows the other way. Every second, the page posts whether it's running, the call's state, who's on stage, the mic level, and every setting. The remote shows all of it, and if the page goes quiet for more than five seconds, the remote treats the pumpkin's computer as gone.

Start needs a click

Chrome won't play audio until someone clicks on the page, so someone has to click Start on the pumpkin's computer once per page load. The page reports whether it's armed, which means someone has clicked Start there. Until it's armed, the remote's Start button stays disabled and shows a hint. Once it's armed, Start and Stop on the phone work from anywhere.

The Gentle / Normal switch

The remote's "This group" card shows the mode the server wants for the group in front, along with a switch to change it. Pressing the switch sends the operator's choice to the server.

@server.app.post("/eyes-remote/mode")
async def remote_mode(request: Request):
    mode = (await request.json()).get("mode")
    if mode not in ("gentle", "normal"):
        return JSONResponse({"error": "mode must be gentle or normal"}, status_code=400)
    call_id = agent.pacer.current_call
    visits.operator_choice(mode)
    agent._sync_pacer()
    sent = bool(call_id) and bool(visits.visit) and tell_if_needed(call_id, OPERATOR_GENTLE, OPERATOR_NORMAL)
    return {"sent": sent}
@server.app.post("/eyes-remote/mode")
async def remote_mode(request: Request):
    mode = (await request.json()).get("mode")
    if mode not in ("gentle", "normal"):
        return JSONResponse({"error": "mode must be gentle or normal"}, status_code=400)
    call_id = agent.pacer.current_call
    visits.operator_choice(mode)
    agent._sync_pacer()
    sent = bool(call_id) and bool(visits.visit) and tell_if_needed(call_id, OPERATOR_GENTLE, OPERATOR_NORMAL)
    return {"sent": sent}
@server.app.post("/eyes-remote/mode")
async def remote_mode(request: Request):
    mode = (await request.json()).get("mode")
    if mode not in ("gentle", "normal"):
        return JSONResponse({"error": "mode must be gentle or normal"}, status_code=400)
    call_id = agent.pacer.current_call
    visits.operator_choice(mode)
    agent._sync_pacer()
    sent = bool(call_id) and bool(visits.visit) and tell_if_needed(call_id, OPERATOR_GENTLE, OPERATOR_NORMAL)
    return {"sent": sent}
@server.app.post("/eyes-remote/mode")
async def remote_mode(request: Request):
    mode = (await request.json()).get("mode")
    if mode not in ("gentle", "normal"):
        return JSONResponse({"error": "mode must be gentle or normal"}, status_code=400)
    call_id = agent.pacer.current_call
    visits.operator_choice(mode)
    agent._sync_pacer()
    sent = bool(call_id) and bool(visits.visit) and tell_if_needed(call_id, OPERATOR_GENTLE, OPERATOR_NORMAL)
    return {"sent": sent}

A human operator's choice of context is remembered by the visit state we wrote in part 7, which holds it for the group in front until they leave. A person's choice outranks every automatic check. After Normal, a failed age check, a small child measured joining, and the model's own call to become_gentle all leave the act in place. After Gentle, only another press brings the act back. If nobody's on stage when the operator presses, the choice applies to a group arriving within 20 seconds. I can press Gentle when I see a stroller coming up the driveway.

If the pumpkin isn't in the chosen mode yet, the server also sends a message into the call asking for the tool that switches modes.

Traps to avoid

Don't let a later automatic check undo a person's choice. Scope the override to the group in front, and keep it until they leave.

Next

The pumpkin can now run a whole night with a person keeping watch. In part 9 I test it without visitors, replay a recorded night through the real server, and watch it live while it runs.

The series

  1. The system and the call.

  2. The agent: a personality and three modes, as contexts and steps.

  3. Tools: what the AI calls on my server, and why its material lives in code.

  4. Vision: letting the agent see, and checking the camera before any decision that matters.

  5. The stage: detecting who is standing in front of the pumpkin, in the browser.

  6. The voice: audio effects in the browser.

  7. Pacing and state: the server keeps score.

  8. The operator: a person with a phone who can overrule the agent (this post).

  9. Testing it, and running it for a whole night.

Bottom Linear Gradient  Lines image

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.