Overview
The Agents SDK includes a CLI interface that make it easy to start your agent server in various modes. Each mode is optimized for specific use cases and development stages, from local testing to production deployments.
Your agent server can be started in the following modes:
| Mode | Description |
|---|---|
start | Production mode with graceful shutdown handling and optimized logging. |
dev | Development mode with auto-reload and detailed logging for fast iteration. |
console | Local, single-session, terminal-based testing. Only available for Python agents. |
connect | Single-session, direct connection to a specific LiveKit room for targeted debugging with live participants. |
These is also a one-time setup command, download-files, that downloads required runtime assets for plugins. To learn more see Download files.
Authentication
You must set authentication credentials before you start your agent server in order to connect to LiveKit and LiveKit Inference. They can be set in environment variables or passed as command-line arguments.
Console mode doesn't use your credentials to connect to LiveKit, but it requires them for LiveKit Inference. Because console mode doesn't accept credentials as command-line arguments, you must provide them in environment variables.
| Argument | Description | Environment variable |
|---|---|---|
--url | LiveKit server or Cloud project WebSocket URL | LIVEKIT_URL |
--api-key | LiveKit API key | LIVEKIT_API_KEY |
--api-secret | LiveKit API secret | LIVEKIT_API_SECRET |
Set environment variables
Run the following LiveKit CLI command to load your LiveKit Cloud API keys into a .env.local file:
lk app env -w
The file should look like this:
LIVEKIT_API_KEY=<your API Key>LIVEKIT_API_SECRET=<your API Secret>LIVEKIT_URL=<your LiveKit server URL>
Start mode
Start mode runs your agent server in production with proper error handling and graceful shutdown. This mode connects to LiveKit with settings optimized for production deployments.
Start mode provides the following features:
- Production logging: Log level defaults to
INFOfor clean output. - Graceful shutdown: Drains active jobs before shutting down on
SIGINTorSIGTERMsignals. - Production optimizations: Includes load balancing, overload protection, and pre-warmed idle processes to ensure high availability.
To start your agent server in production mode, use the following command:
uv run agent.py start
In Node.js, in order to start your agent server in production mode, you must build using tsc before you start:
tsc && node agent.js start
Graceful shutdown
In production mode, when your agent server receives a shutdown signal (such as SIGTERM from a container orchestrator or Ctrl+C), it drains active jobs before closing:
- Stops accepting new job assignments.
- Waits for active jobs to complete (up to
--drain-timeoutin Python). - Closes all connections and cleans up resources.
- Exits with appropriate status code.
Parameters
The following parameters are available in production mode:
| Parameter | Description | Default |
|---|---|---|
--log-level | Set the logging level (trace, debug, info, warn, error, critical) | info |
--drain-timeout | Time in seconds to wait for jobs to finish before shutting down | None (waits indefinitely) |
| Parameter | Description | Default |
|---|---|---|
--log-level | Set the logging level (trace, debug, info, warn, error, fatal) | info |
Dev mode
In dev mode, your agent server starts with features optimized for local development, including enhanced logging and automatic code reloading:
- Debug logging: Log level defaults to
DEBUGfor detailed output. - Auto-reload: In Python, auto-reloads when code changes are detected. For Node.js, use
tsxfor automatic Typescript complication and reloading. - Development optimizations: No graceful shutdown drain period for faster iteration.
Start your agent server in dev mode with the following command:
uv run agent.py dev
tsx agent.ts dev
Parameters
The following parameters are available in dev mode:
| Parameter | Description | Default |
|---|---|---|
--log-level | Set the logging level (trace, debug, info, warn, error, critical) | debug |
--no-reload | Disable auto-reload on file changes. | By default, auto-reload is enabled. |
| Parameter | Description | Default |
|---|---|---|
--log-level | Set the logging level (trace, debug, info, warn, error, fatal) | debug |
Console mode
Console mode runs your agent server in your terminal without connecting to LiveKit. This single-session mode simulates a full agent session entirely on your local machine for quick testing and debugging during development.
Console mode allows you to interact with your agent using text or voice, and offers the following features:
- Audio I/O: Choose which local audio devices to use for input and output.
- Visual feedback: Displays audio input using a real-time frequency visualizer.
- Text mode: Toggle between audio and text-only interaction.
- Session recording: Record sessions to disk for playback and analysis.
While console mode doesn't use LiveKit for media transport, if you're using LiveKit Inference, you must have your authentication credentials set as environment variables in order to test your agent. See the Authentication section for more information.
Start your agent server in console mode with the following command:
uv run agent.py console
You can speak to your agent with text or voice.
Parameters
The following parameters are available in console mode:
| Parameter | Description |
|---|---|
--text | Interact with your agent using only text input (no audio). You can also toggle between audio and text input using the shortcut Ctrl+T. |
--input-device | Specify the input device to use for audio input using device ID or name substring. Use --list-devices to get the device IDs and names for available input devices. |
--output-device | Specify the output device to use for audio output using device ID or name substring. Use --list-devices to get the device IDs and names for available output devices. |
--list-devices | List all available input and output audio devices on your system. |
--record | Record the agent session to disk. If enabled, saves the session to a JSON file named console-recordings/session-<timestamp>/. |
Examples
Use these examples to run your agent in console mode with different configurations:
List available audio devices:
uv run agent.py console --list-devices
Run your agent in text-only mode:
uv run agent.py console --text
Specify input and output devices for audio:
uv run agent.py console --input-device "Macbook Pro Microphone" --output-device "External Headphones"
Record the session to disk:
uv run agent.py console --record
Connect mode
Connect mode starts your agent server with a direct connection to a specific LiveKit room. This single-session mode is useful for testing with live participants or debugging specific room scenarios.
uv run agent.py connect --room my-test-room
Connect to a room with a specific participant identity:
uv run agent.py connect --room my-room --participant-identity my-agent-1
pnpm tsx agent.ts connect --room my-test-room
Connect to a room with a specific participant identity:
pnpm tsx agent.ts connect --room my-room --participant-identity my-agent-1
Parameters
| Parameter | Description | Required |
|---|---|---|
--room | Name of the room to connect to. If the room doesn't exist, it's automatically created. | Yes |
--participant-identity | Identity to use for the agent participant. Autogenerated if not provided. | No |
--log-level | Set the logging level. Valid values are: trace, debug, info, warn, error, critical. Default is debug. | No |
| Option | Description | Required |
|---|---|---|
--room | Name of the room to connect to. | Yes |
--participant-identity | Identity to use for the agent participant. Autogenerated if not provided. | No |
--log-level | Set the logging level. Valid values are: trace, debug, info, warn, error, fatal. Default value is debug or the value set in the LOG_LEVEL environment variable. | No |
Download files
Some plugins require model files or other assets to be available at runtime. For example, the turn-detector, silero, and noise-cancellation plugins all require downloaded model files.
The download-files command downloads required external assets for these plugins. Run this command as part of your build process or before running your agent locally for the first time.
When executed, download-files calls each plugin's download-files() method to fetch its files. Any custom plugins that implement download-files() are invoked automatically.
The following command downloads files for the plugins your agent uses:
uv run agent.py download-files
tsc && node agent.js download-files
Add scripts in Node.js
If you're using Node.js, you can add the following scripts to your package.json file to start your agent server in different modes using pnpm:
{"scripts": {"dev": "tsx agent.ts dev","build": "tsc","start": "tsc && node agent.js start","connect": "tsx agent.ts connect","download-files": "tsc && node agent.js download-files"}}
For example, to start the agent in development mode, execute the following command:
pnpm dev