Issue with programmatically toggle STT/TTS on off

OK, for agents/examples/voice_agents/toggle_io.py at main · livekit/agents · GitHub , when I connect to a room I see the following exception:

Exception: cannot access local participant before connecting

I will need to fix that in the sample, but the fix is to add:

await ctx.connect()

Immediately after await session.start(…)

After you apply that fix and connect to a room, it should work. You can test it as follows:

  1. Start the agent uv run examples/voice_agents/toggle_io.py dev
  2. Use the Agents Playground as a front end: https://agents-playground.livekit.io/
  3. Press Connect in the Playground and allow the agent to connect to your toom
  4. Under the RPC options in the playground specify the method name as toggle_input and then the Payload is either audio_off or audio_on - you should see the agent stops or starts responding to your speech.
  5. The example is written with the OpenAI realtime LLM, but it should work with any LLM/STT/TTS - you’ll need to modify it to match your setup if you don’t have an OpenAI key