white-telephone-81843
12/19/2025, 2:06 PMtall-airline-16756
12/19/2025, 2:07 PMtall-airline-16756
12/19/2025, 2:07 PMif __name__ == "__main__": block.
What to do:
• Create an agent dispatch that targets room="test-room" using the LiveKit API.
• Start your agent server so it accepts the dispatched job; your @server.rtc_session() entrypoint will be invoked with ctx.room.name == "test-room".
• The room will be created automatically if it doesn't exist.
Minimal example (async):
from livekit import api
from livekit.agents import cli, AgentServer
import asyncio
# assume server and your @server.rtc_session() handler are defined
async def dispatch_and_run():
lkapi = api.LiveKitAPI()
await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(agent_name="your-agent-name", room="test-room")
)
await lkapi.aclose()
cli.run_app(server)
if __name__ == "__main__":
asyncio.run(dispatch_and_run())
Would you like a version that:
• uses a sync wrapper instead, or
• includes token generation and SDK connection code inside the agent session handler? Sources: Agent dispatch | LiveKit docswhite-telephone-81843
12/19/2025, 2:21 PMtall-airline-16756
12/19/2025, 2:21 PMserver and @server.rtc_session() handler aren't defined. I can show a minimal example you can drop into your project to define an AgentServer and an RTC session entrypoint that will run when you dispatch the agent to "test-room".
Quick clarifying question before I provide code: are you using the LiveKit Python agents package (the example earlier used livekit.agents), or are you working from a different SDK/language?