Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions livekit-agents/livekit/agents/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class ServerOptions:
permissions: WorkerPermissions = field(default_factory=WorkerPermissions)
"""Permissions that the agent should join the room with."""
agent_name: str = ""
"""Set agent_name to enable explicit dispatch. When explicit dispatch is enabled, jobs will not be dispatched to rooms automatically. Instead, you can either specify the agent(s) to be dispatched in the end-user's token, or use the AgentDispatch.createDispatch API""" # noqa: E501
"""Set agent_name to enable explicit dispatch. When explicit dispatch is enabled, jobs will not be dispatched to rooms automatically. Instead, you can either specify the agent(s) to be dispatched in the end-user's token, or use the AgentDispatch.createDispatch API.

By default it uses ``LIVEKIT_AGENT_NAME`` from environment""" # noqa: E501
worker_type: WorkerType = WorkerType.ROOM
"""Whether to spin up an agent for each room or publisher."""
max_retry: int = 16
Expand Down Expand Up @@ -356,6 +358,7 @@ def __init__(
self._http_proxy = http_proxy
self._log_level = _validate_and_normalize_log_level(log_level)
self._agent_name = ""
self._agent_name_is_env = False
self._server_type = ServerType.ROOM
self._id = "unregistered"

Expand Down Expand Up @@ -494,7 +497,15 @@ def decorator(
self._entrypoint_fnc = f
self._request_fnc = on_request
self._session_end_fnc = on_session_end
self._agent_name = agent_name
if agent_name:
self._agent_name = agent_name
self._agent_name_is_env = False
elif os.environ.get("LIVEKIT_AGENT_NAME"):
self._agent_name = os.environ["LIVEKIT_AGENT_NAME"]
self._agent_name_is_env = True
else:
self._agent_name = ""
self._agent_name_is_env = False
self._server_type = type
return f

Expand Down Expand Up @@ -630,6 +641,7 @@ async def worker(_: Any) -> web.Response:
body = json.dumps(
{
"agent_name": self._agent_name,
"agent_name_is_env": self._agent_name_is_env,
"worker_type": agent.JobType.Name(self._server_type.value),
"worker_load": self._worker_load,
"active_jobs": len(self.active_jobs),
Expand Down
Loading