How to send text to participants and test locally

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

How can I send text to my participants from within an Agent?

I’m trying:

self.session.room_io.room.local_participant.send_text("my payload", topic="my topic")

But I can’t test this via uv run agent.py console because I get:

RuntimeError: Cannot access room_io: the AgentSession was not started with a room.

How do I test this locally?

The console command doesn’t connect to a room, which is why you get that error.

To test with a room:

  1. Run uv run agent.py dev - this connects your agent to a real room
  2. Use a frontend with the same LiveKit API key to connect to the same room

To access the room object from within a node (like llm_node), use get_job_context():

from livekit.agents import get_job_context

ctx = get_job_context()
room = ctx.room
await room.local_participant.send_text("my payload", topic="my topic")