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:create_agent()- A factory function that configures and returns an Agent instancejoin_call()- Defines what happens when an agent joins a callAgentLauncher- Responsible for running and monitoring the agentsRunner- a wrapper on top ofAgentLauncher, providing CLI commands for console and server modes
Basic Example
Running the Server
Start the HTTP server with theserve command:
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: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:
Configuration with ServeOptions
The HTTP server behavior can be customized usingServeOptions:
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 receivescall_id from the URL path and can use standard FastAPI dependencies for authentication:
Customizing the Default FastAPI App
TheRunner 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 viaServeOptions:
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 to1to 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 aroundAgentLauncher. 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
gRPC Example
Here’s a sketch of how you might wrapAgentLauncher 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