> Hello, I'm facing an unusual problem with my ...
# ask-ai
g
Hello, I'm facing an unusual problem with my agent. Sometimes it sends and say values ​​like <|audio_text|>, as in the example below:
Copy code
{
  "id": "item_Clh60LcmD6UIgb8CEL6U4",
  "type": "message",
  "role": "assistant",
  "content": [
    "<|audio_text|>"
  ],
  "interrupted": false,
  "extra": {},
  "metrics": {
    "started_speaking_at": 1765483113.0202394,
    "stopped_speaking_at": 1765483114.1185155
  }
}
This is my AgentSession:
session = AgentSession(
userdata=userdata,
llm=openai.realtime.RealtimeModel.with_azure(modalities=["text"]),
tts=elevenlabs.TTS( voice_settings=VoiceSettings(stability=0.5, similarity_boost=0.75,style=0.0,speed=1.0,use_speaker_boost=True)))
My problem is that this <|audio_text|> is being sent to my user (the person interacting with the agent). I don't just want to remove it from the history; I want it to never be spoken again.
Any idea what it could be?
t
Thanks for reaching out, vnnicius. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking about the agent sending "<|audio_text|>" to users and you want it never to be spoken. I hear you. What’s happening • The placeholder "<|audio_text|>" is an internal token the Realtime model can emit when audio-oriented segments are present. If it reaches your TTS or frontend it becomes visible/spoken. What you can do (recommended) 1. Ensure the RealtimeModel is forced to text-only:
Copy code
llm = openai.realtime.RealtimeModel.with_azure(modalities=["text"])
1. Intercept and clean model output before it reaches TTS by adding a transcription node that strips the token:
Copy code
async def transcription_node(self, text: AsyncIterable[str], model_settings: ModelSettings) -> AsyncIterable[str]:
    async for chunk in text:
        cleaned = chunk.replace("<|audio_text|>", "").strip()
        if cleaned:
            yield cleaned
• This guarantees the token never gets forwarded to ElevenLabs or the user. Optional checks • Confirm no other part of your pipeline (frontend, session config, or other plugins) is enabling audio responses or injecting control tokens. • Keep your external TTS (ElevenLabs) as the only speech path so the model’s audio tokens are irrelevant. If you’d like, share a short sample of the raw model stream or your pipeline code around where you send text to TTS and I’ll point to the exact spot to add the transcription_node. Sources: OpenAI Realtime API plugin guide | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Text and transcriptions | LiveKit docs
g
how to filter this before the tts generation
t
You want to remove "<|audio_text|>" from model output before it reaches your TTS. Below is a concise Python example and the exact places to apply it. 1) Ensure the model is text-only:
Copy code
llm = openai.realtime.RealtimeModel.with_azure(modalities=["text"])
2) Intercept and filter output before TTS by implementing a transcription node on your AgentSession (or override the method your agent uses to stream LLM output). Example async transcription node:
Copy code
async def transcription_node(self, text: AsyncIterable[str], model_settings) -> AsyncIterable[str]:
    async for chunk in text:
        # remove placeholder tokens and trim whitespace
        cleaned = chunk.replace("<|audio_text|>", "").strip()
        if cleaned:
            yield cleaned
3) If your pipeline uses a different hook (e.g.,
llm_node
in Node agent code), apply the same filtering there before enqueuing chunks to TTS. What to check • Place this node in the path that sends text to your ElevenLabs TTS so the placeholder is removed before any speech synthesis. • Keep
modalities=["text"]
so audio-control tokens are less likely to appear. If you want, paste the small section of your agent pipeline where you pass LLM output to TTS and I’ll point exactly where to insert the node. Sources: Agents v0.x migration guide - Node.js | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | Modifying LLM output before TTS | LiveKit docs