How can I see if my agent main.py file is running ...
# ask-ai
w
How can I see if my agent main.py file is running in dev mode or prod mode? I want to perform specific behaviors in dev mode for testing vs prod mode
t
Thanks for reaching out, Alex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To help you figure out whether your
main.py
file is running in dev mode or prod mode, you can check the
devmode
parameter that’s passed to the
Worker
instance. This parameter is set automatically by the LiveKit Agents CLI depending on how you start the agent: • Dev mode: This kicks in when you run
python main.py dev
, which sets
devmode=True
. • Prod mode: This happens when you run
python main.py start
, setting
devmode=False
. Feel free to use this
devmode
parameter in your code to tailor behaviors specifically for testing in dev mode or running smoothly in production. If you have any questions about this, I’m here to help! Sources: livekit-plugins/livekit-plugins-browser/livekit/plugins/browser/proc_main.p... | Docs::Agents
w
But before that, when I'm registering the agent name I want to pick a name based on what mode its being used in.
t
To help you register an agent name based on the mode (dev or prod), you can easily set the
agent_name
parameter dynamically in the
WorkerOptions
when initializing your agent. Here’s a simple example to guide you:
Copy code
from livekit.agents import cli, WorkerOptions, JobContext

def entrypoint(ctx: JobContext):
    # Your agent logic here
    pass

if __name__ == "__main__":
    devmode = True  # Replace with actual devmode check
    agent_name = "my-agent-dev" if devmode else "my-agent-prod"

    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            agent_name=agent_name,  # Dynamically set based on mode
        ),
    )
In this example, you’ll notice the
agent_name
switches to "my-agent-dev" when in dev mode, and "my-agent-prod" when in prod mode. Using the
devmode
parameter like this makes it straightforward to adjust the name based on your current environment. If you have any questions or want to explore this further, I’m here to help! Sources: Accepting incoming calls | LiveKit Docs | README.md | livekit-agents/livekit/agents/cli/proto.py | Docs::Agents
w
but how can i see if we're in devmode ? that's the key question I have
t
Let's take a look at how you can tell if you're in dev mode—it’s pretty straightforward! You just need to check the
devmode
parameter that gets passed to your
Worker
instance. The LiveKit Agents CLI does this for you automatically, depending on how you start the agent: • If you run
python main.py dev
, then
devmode=True
. • If you run
python main.py start
, then
devmode=False
. Inside your code, you can use this parameter to decide what logic should run based on whether you’re in dev mode or not. Here’s a simple example to guide you:
Copy code
from livekit.agents import cli, WorkerOptions, JobContext

def entrypoint(ctx: JobContext):
    # Your agent logic here
    pass

if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            agent_name="my-agent",
        ),
        devmode=True  # This is automatically set by the CLI
    )
So, by checking the
devmode
value, you can easily tailor your agent’s behavior to fit the current mode. If you have any questions or want to explore this further, I’m here to help!