what is the from livekit.agents.AgentServer class
# ask-ai
b
what is the from livekit.agents.AgentServer class
✅ 1
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about the
AgentServer
class in
livekit.agents
. What it is •
AgentServer
is the server-side component that registers an agent with LiveKit, waits for job/room requests, and orchestrates agent sessions. It manages the lifecycle of agent jobs and acts as the entrypoint for running agent logic when a room or job is dispatched to the agent. Key responsibilities and features • Agent registration & lifecycle: registers the agent with LiveKit and spawns a job process when a request is accepted. • Entrypoint decorator: use
@server.rtc_session()
in Python to define the function that runs for each accepted job/session. • Per-job isolation: each accepted job runs in its own process so multiple sessions can run concurrently without interfering. • Configuration options: ◦
permissions
to control publish/subscribe/data capabilities. ◦
drain_timeout
to control how long the server waits for active jobs to finish on shutdown (default: 30 minutes). ◦
setup_fnc
for prewarm initialization (e.g., loading models). ◦
load_fnc
and
load_threshold
for custom load monitoring (note: not available on LiveKit Cloud). ◦
host
and
port
for the health check endpoint (defaults to
0.0.0.0:8081
). • Health checks: exposes an HTTP health endpoint at
/
for monitoring. • Dispatch control: supports automatic and explicit dispatching (routing by
agent_name
). • Graceful draining: stops accepting new jobs on shutdown and waits up to
drain_timeout
for active jobs to finish. How it’s commonly used • Pair
AgentServer
with
AgentSession
(the per-room/session component) to handle the real-time media pipeline (STT → LLM → TTS). • Start the server with
agents.cli.run_app(server)
. If you’d like, I can: • Show a minimal Python example that defines an
AgentServer
and a
@server.rtc_session()
handler. • Explain how to set specific configuration options (e.g.,
permissions
,
drain_timeout
, or
setup_fnc
). • Help troubleshoot an error you’re seeing when starting an
AgentServer
. Which of those would be most helpful right now? Sources: Server options | LiveKit Documentation | Server lifecycle | LiveKit Documentation | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Deployment reliability on LiveKit Cloud | LiveKit | How to Use the Supervisor Pattern for Multi-Agent Voice AI Systems | LiveKi..., with interactive elements