Can I pass any custom args into cli.run_app()?
# ask-ai
c
Can I pass any custom args into cli.run_app()?
t
Thanks for reaching out, Anton. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for your question! The
cli.run_app()
function doesn’t directly support passing custom arguments. It accepts a
WorkerOptions
object and an optional
hot_reload
parameter. But don’t worry—you can still pass your configuration data in a few helpful ways: • Environment Variables: You can use environment variables to pass configuration data, which your code can easily load with libraries like
dotenv
. • Prewarm Function: Consider using the
prewarm_fnc
callback within
WorkerOptions
to set up custom data inside the
proc.userdata
dictionary before your app runs. • Session or Room Metadata: Another option is to pass custom data through
ctx.room.metadata
or the
userdata
field in
AgentSession
. If you’d like, I’d be happy to walk you through any of these methods with more details or examples—just let me know! Sources: examples/avatar_agents/audio_wave/dispatcher.py | basics/interrupts_user.py | examples/local_audio/README.md | main.py
c
Tell me about CLI_ARGUMENTS
t
CLI_ARGUMENTS
is a global variable in the LiveKit Agents framework that holds the command-line arguments passed to the LiveKit CLI when you run an agent. It’s of type
proto.CliArgs
and gets set up whenever you execute a CLI command like
start
,
dev
,
console
, or
connect
. Here are some important things to know about `CLI_ARGUMENTS`: • It includes configuration options such as logging level, API credentials, WebSocket URL, and the execution mode (like production or development). • During runtime, it helps determine how the agent behaves—for example, you can check if the agent is running in console mode using
cli.CLI_ARGUMENTS.console
. • When you use the
console
command, it sets up debug logging, mock WebSocket credentials, and simulation parameters so you can quickly test without needing a live server. If you’d like, I’m here to help with more specific examples or details on how to use
CLI_ARGUMENTS
. Just let me know! Sources: livekit-agents/livekit/agents/worker.py
c
Can I add my custom args to CLI_ARGUMENTS?
t
I understand you're looking to add custom arguments to the
CLI_ARGUMENTS
structure in LiveKit. Currently, this variable is a predefined
proto.CliArgs
object that includes fixed command-line options like
--url
,
--api-key
, and
--log-level
, so it doesn't support user-defined extensions or dynamic fields. But don’t worry! There are other ways you can pass custom configuration data: • WorkerOptions: You can use the
user_arguments
field in
WorkerOptions
to send custom data to the agent's process and entrypoint. • Environment Variables: Setting custom runtime settings through environment variables is another flexible option. • Configuration Files: You might also consider using config files to define any additional parameters you need. If you have a specific scenario or goal in mind, please feel free to share it! I’d be happy to help guide you toward the best solution. Sources: livekit-agents/livekit/agents/worker.py | lerobot/configs/parser.py | examples/local_audio/README.md
c
Tell me more about using user_arguments
t
Thank you for your question! It looks like the sources don’t mention a
user_arguments
parameter within
WorkerOptions
, but don’t worry—there are several friendly ways you can pass custom data or configuration to your agent: • Entrypoint Function: You can use the
entrypoint_fnc
to easily access job context and room data. • Environment Variables: Another great option is to pass configuration data through environment variables. • Shared State: You might also consider using shared state within
JobContext
or
RunContext
. • Prewarm Function: Lastly, storing process-level data in the
proc.userdata
dictionary via a
prewarm_fnc
can be really helpful. If you’d like, feel free to share a bit more about your specific use case—I’d be happy to help guide you toward the best approach using these methods. I’m here to help! Sources: Worker options | LiveKit Docs | agents/src/worker.ts | examples/voice_agents/langgraph_agent.py | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | main.py