Skip to content
mentoor

Topic 4 of 5 · 5 min read

Handling barge-in and interrupted replies

Goal: Trace an interrupted turn in a session log and state what the agent must cancel and which part of its reply to drop from history.

When the caller talks over the agent, you must stop generation, stop playback and rewrite the history so it contains only what the caller actually heard.

Check yourself · 1 of 3

A caller interrupts after the agent has spoken about 3 seconds of a 9-second generated reply. What should the stored assistant turn contain?

Choose one answer

Why it matters

Models generate audio faster than people hear it. By the time the caller interrupts, the model may have produced the next ten seconds, and the session believes it said all of it. If you leave that in history, the agent will refer to things the caller never heard ("as I explained, the fee is 12 dollars") and the conversation falls apart.

What an interruption involves

  1. Detect speech from the caller while the agent is speaking (this is VAD again).
  2. Cancel the response on the model so it stops generating.
  3. Stop playback in the browser or phone gateway immediately, and flush any queued audio.
  4. Truncate history. Tell the session how many milliseconds of the reply were played, so the saved turn is cut at that point. OpenAI Realtime has a truncate event for this.
  5. Cancel anything attached to the cancelled reply, such as queued filler or an unfinished tool announcement.

Not every sound is an interruption

  • Backchannels such as "mm-hm" or "right" mean "keep going". Ending the agent's turn on each one makes it stutter. Require a minimum duration or a few real words before treating speech as barge-in.
  • Echo. If the agent's voice leaks from speaker to microphone, it interrupts itself. Browser WebRTC applies echo cancellation. Phone and server audio often does not, so check it on speakerphone.
  • Other voices and noise can start a barge-in. A higher threshold and a minimum speech length help.

Before and after

A session log shows the agent generating 9 seconds of audio, the caller speaking at 3 seconds, and the saved assistant message containing all 9.

{ "type": "conversation.item.truncate", "item_id": "item_41", "content_index": 0, "audio_end_ms": 3000 }

With a truncate event sent at the playback position, the history keeps roughly the first three seconds. Without it, the model "remembers" saying words that were never played. Check the exact event and field names in your vendor's documentation.

What goes wrong

  • Stopping playback but not generation. The model keeps working and may finish a tool call the caller just overrode.
  • Truncating by server time. Use the playback position, because audio is buffered ahead of what the speaker has played.
  • Treating every noise as barge-in. Coughs and "uh-huh" cancel good answers.
  • No echo cancellation. The agent interrupts itself and loops.

Examples

Reading an interrupted session log

12.0s response.created   item_41
12.4s audio started
15.2s speech_started    (caller)
15.2s response.cancel   sent
15.3s playback stopped  played=2800ms
15.3s item.truncate     item_41 audio_end_ms=2800

The agent must cancel the response, stop playback and truncate item 41 at 2,800 ms. If the truncate is missing, history holds the full generated reply, including words the caller never heard.

Backchannel filter

A caller says "mm-hm" while the agent explains a refund. The agent stops and asks "Yes?" The fix is to ignore speech shorter than a set duration unless it contains real words, so only a genuine interruption cancels the reply.

Key points

  • On barge-in, cancel generation, stop and flush playback and truncate history to what was actually played.
  • Audio is generated faster than it is heard, so history must be cut at the playback position, not at the generated length.
  • Backchannels such as "mm-hm" should not end the agent's turn; require a minimum duration or a few words.
  • Without echo cancellation the agent can hear itself and interrupt itself.
  • Cancel anything tied to the cancelled reply, such as queued filler or a tool announcement.

Common mistakes

  • Stopping playback but not cancelling generation, so the model keeps working on the abandoned reply.
  • Truncating by server time instead of by how much audio the caller actually heard.
  • Treating every cough or "uh-huh" as an interruption.
  • Testing only with headphones, then shipping to speakerphones where echo makes the agent talk to itself.

Check yourself · 2 of 3

The agent keeps stopping when the caller says "mm-hm" while it explains. What should change?

Choose one answer

Check yourself · 3 of 3

Why must playback be flushed as well as generation cancelled on barge-in?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic