Skip to main content
The Runner class provides two modes for running your agents:
  • a single-agent console mode for development,
  • and an HTTP server mode that spawns agents on demand for production deployments.
For a complete working example, see 08_agent_server_example in the Vision Agents repository.

Core Components

Running agents as a server requires four components:
  1. create_agent() - A factory function that configures and returns an Agent instance
  2. join_call() - Defines what happens when an agent joins a call
  3. AgentLauncher - Responsible for running and monitoring the agents
  4. Runner - a wrapper on top of AgentLauncher, providing CLI commands for console and server modes

Basic Example

Running the Server

Start the HTTP server with the serve command:
The server starts on http://127.0.0.1:8000 by default. The interactive API documentation can be found at http://127.0.0.1:8000/docs (Swagger UI).

CLI Options

Console mode

For development and testing, use console mode to run a single agent:
The splash screen is only shown in interactive terminals. It is automatically suppressed in non-interactive environments such as CI pipelines and Docker containers. Use --no-splash to suppress it explicitly.

API Endpoints

The server exposes these endpoints: Close operations (DELETE and POST /close) return HTTP 202 Accepted. The close request is processed asynchronously — the owning node will shut down the session on its next maintenance cycle. Creating a Session:
Response:
Getting Session Metrics:
Response:

Configuration with ServeOptions

The HTTP server behavior can be customized using ServeOptions:

CORS Options

Authentication & Permissions

Use authentication and permission callbacks to secure your agent server and control who can start, view, or close sessions. These callbacks are standard FastAPI dependencies, giving you access to headers, query parameters, and dependency injection.

Permission Callbacks

Each permission callback receives call_id from the URL path and can use standard FastAPI dependencies for authentication:

Customizing the Default FastAPI App

The Runner exposes its FastAPI instance via runner.fast_api, allowing you to add custom routes, middlewares, and other configurations after initialization.

Using a Custom FastAPI Instance

For full control over the FastAPI configuration, provide your own instance via ServeOptions:
When providing a custom FastAPI app via ServeOptions(fast_api=app), the Runner will use it as-is without any configuration.It will not register the default endpoints (/calls/{call_id}/sessions/..., /health, /ready, etc.) nor apply CORS settings. You are responsible for assembling the application yourself.

Session Limits & Resource Management

AgentLauncher provides options to control session lifecycle and resource usage:
  • max_concurrent_sessions - Prevents resource exhaustion by capping how many agents can run simultaneously. Useful for cost control and server capacity planning.
  • max_sessions_per_call - Prevents duplicate agents from joining the same call. Set to 1 to ensure only one agent per conversation.
  • max_session_duration_seconds - Automatically terminates long-running sessions. Protects against runaway sessions that could accumulate costs.
  • agent_idle_timeout - Cleans up agents when all other participants have left the call. The agent disconnects after being alone for this duration.

Using AgentLauncher Without the HTTP Server

The built-in HTTP server is just a thin wrapper around AgentLauncher. If you need a different transport — gRPC, WebSocket, message queue, or a custom protocol — you can use AgentLauncher directly. AgentLauncher is transport-agnostic. It manages agent lifecycle, session limits, and the session registry. You provide the interface layer on top.

AgentLauncher Methods

“Local” methods operate on this node’s in-memory session map. “Registry” methods read from or write to shared storage, so they work across nodes when a SessionRegistry is configured.

gRPC Example

Here’s a sketch of how you might wrap AgentLauncher with a gRPC service:

Scaling to Multiple Nodes

By default, AgentLauncher tracks sessions in local memory, which works for single-node deployments. To scale horizontally across multiple servers, you can provide a SessionRegistry backed by Redis. This allows any node to query or close sessions running on other nodes, and removes the need for sticky sessions or session affinity. See the Horizontal Scaling guide for setup instructions.

Next Steps

Horizontal Scaling

Scale across multiple servers with Redis

Docker Deployment

Docker, Kubernetes, and scaling

Agent Server Example

Complete working implementation