Skip to content

worker: read agent name from livekit.toml as last fallback - #7295

Open
u9g wants to merge 1 commit into
mainfrom
jason/toml-agent-name
Open

u9g wants to merge 1 commit into
mainfrom
jason/toml-agent-name

Conversation

@u9g

@u9g u9g commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Why

The agent name is moving out of code into livekit.toml, checked into git, so Cloud, lk, simulations and observability can all read the same name without booting the worker. Proposal: https://app.notion.com/p/livekit/Proposal-livekit-toml-layout-for-agent-name-and-regions-3d83c4901a4281beb3b9f1f3e74de44d

This is phase 1: the SDK learns to read the file and warns about names set in code. Phase 2, a few weeks out, removes the code parameter.

What

Agent name precedence is now LIVEKIT_AGENT_NAME_OVERRIDE, then the agent_name argument to rtc_session (code), then LIVEKIT_AGENT_NAME, then [agent] name from ./livekit.toml.

  • The toml fallback is applied at the start of run() and only in production. run(devmode=True) (lk agent dev, dev, console) never takes it, so dev workers stay out of the deployed agent's pool.
  • When the name comes from code, run() logs one warning pointing at livekit.toml. The agent_name docstrings mark the parameter deprecated.
  • A missing file, a missing [agent]/name, or a malformed file means no name; malformed files log at debug.
  • tomllib on 3.11+, tomli on 3.10 (new marker dependency, uv.lock updated).

JS parity: livekit/agents-js has the matching change.

Verification

uv run --project livekit-agents pytest tests/test_worker_config.py -q --unit: 15 passed (5 new: toml fallback, env beats toml, devmode ignores toml, missing file, code-name warning). ruff check, ruff format --check and scripts/check_types.py clean on touched files.

Precedence is now LIVEKIT_AGENT_NAME_OVERRIDE, the rtc_session agent_name
arg, LIVEKIT_AGENT_NAME, then [agent] name from livekit.toml in the working
directory. Dev workers skip the toml name so they never join the deployed
agent's pool. A name set in code logs a deprecation warning at run().
@u9g
u9g requested a review from a team as a code owner September 15, 2026 19:08

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Devin Review

Comment on lines +570 to +575
if self._agent_name_source != "none" or devmode:
return
name = _toml_agent_name(os.path.join(os.getcwd(), "livekit.toml"))
if name:
self._agent_name = name
self._agent_name_source = "toml"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟑 Development restart retains TOML name

A production-to-development restart keeps livekit.toml's name. _agent_name_source remains toml, so the dev worker joins the deployed dispatch pool.

Learn more

AgentServer.aclose() restores _closed, and run() supports another invocation on the same instance. The first production run changes _agent_name_source from none to toml. On a later development run, the source check returns before devmode can suppress that persisted fallback.

Example: Run one server with devmode=False and [agent] name = "deployed", close it, then run it with devmode=True. The second run still registers as deployed instead of using an empty name.

Recommended fix: When entering development mode, clear a previously resolved TOML name and reset its source to none. Preserve override, code, and environment names.

Suggested change
if self._agent_name_source != "none" or devmode:
return
name = _toml_agent_name(os.path.join(os.getcwd(), "livekit.toml"))
if name:
self._agent_name = name
self._agent_name_source = "toml"
if devmode:
if self._agent_name_source == "toml":
self._agent_name = ""
self._agent_name_source = "none"
return
if self._agent_name_source != "none":
return
name = _toml_agent_name(os.path.join(os.getcwd(), "livekit.toml"))
if name:
self._agent_name = name
self._agent_name_source = "toml"
Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

except FileNotFoundError:
return ""
except (OSError, tomllib.TOMLDecodeError) as e:
logger.debug("ignoring unreadable livekit.toml", extra={"path": path, "error": str(e)})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 TOML errors bypass log redaction

Unreadable configs log path and str(e) without PII markers. Customer data in either value bypasses structured-log redaction.

Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

logger.warning(
"agent_name is set in code; move it to livekit.toml ([agent] name). "
"The agent_name parameter will be removed in a future release.",
extra={"agent_name": self._agent_name},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 Agent name bypasses log redaction

A code-defined agent name is logged as agent_name without a PII marker. The value bypasses structured-log redaction.

Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant