### Copy Example App Files Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Copies the example application and Dockerignore file to the current directory. Assumes the app exists in the parent directory. ```bash cp ../agent-example-app/* . cp ../agent-example-app/.dockerignore . ``` -------------------------------- ### Install and Login to Cerebrium CLI Source: https://github.com/livekit-examples/agent-deployment/blob/main/cerebrium/README.md Install the Cerebrium CLI and log in to your account. This is the first step to managing your deployments. ```bash pip install cerebrium --upgrade cerebrium login ``` -------------------------------- ### Deploy Application with fly.toml Source: https://github.com/livekit-examples/agent-deployment/blob/main/fly.io/README.md Deploy your application to Fly.io using the specified fly.toml configuration file. This command uploads your code and starts the deployment process. ```bash fly deploy -c fly.toml ``` -------------------------------- ### Authenticate with Fly.io CLI Source: https://github.com/livekit-examples/agent-deployment/blob/main/fly.io/README.md Use this command to log in to your Fly.io account via the command-line interface. Ensure you have the Fly.io CLI installed. ```bash fly auth login ``` -------------------------------- ### Deploy Agent with Cerebrium CLI Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Commands to install the Cerebrium CLI, log in, and deploy an agent. Secrets must be configured through the Cerebrium dashboard. ```bash # Install the Cerebrium CLI and log in pip install cerebrium --upgrade cerebrium login # Add secrets via the Cerebrium dashboard at https://dashboard.cerebrium.ai: # LIVEKIT_URL=wss://your-project.livekit.cloud # LIVEKIT_API_KEY=your-api-key # LIVEKIT_API_SECRET=your-api-secret # Copy cerebrium.toml to your project root (alongside your Dockerfile), then deploy cerebrium deploy ``` -------------------------------- ### Python Dockerfile for LiveKit Agent Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Production-ready Dockerfile for a Python LiveKit Agent. It runs as a non-root user, installs dependencies, pre-downloads model files, and exposes a health check port. ```dockerfile # python-agent-example-app/Dockerfile # syntax=docker/dockerfile:1 ARG PYTHON_VERSION=3.11.6 FROM python:${PYTHON_VERSION}-slim ENV PYTHONUNBUFFERED=1 ARG UID=10001 RUN adduser \ --disabled-password \ --gecos "" \ --home "/home/appuser" \ --shell "/sbin/nologin" \ --uid "${UID}" \ appuser RUN apt-get update && \ apt-get install -y gcc python3-dev \ && rm -rf /var/lib/apt/lists/* USER appuser RUN mkdir -p /home/appuser/.cache && chown -R appuser /home/appuser/.cache WORKDIR /home/appuser COPY requirements.txt . RUN python -m pip install --user --no-cache-dir -r requirements.txt COPY . . # Pre-download any model files so they are baked into the image RUN python main.py download-files EXPOSE 8081 CMD ["python", "main.py", "start"] ``` ```bash # Build and run locally docker build -t my-python-agent . docker run --rm \ -e LIVEKIT_URL=wss://your-project.livekit.cloud \ -e LIVEKIT_API_KEY=your-api-key \ -e LIVEKIT_API_SECRET=your-api-secret \ my-python-agent ``` -------------------------------- ### Cerebrium Deployment Configuration Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Configuration for deploying a LiveKit Agent to Cerebrium using `cerebrium.toml`. This setup includes autoscaling between 1 and 5 replicas based on CPU utilization and a 900-second grace period for conversations. ```toml # Cerebrium deployment configuration example # This is a placeholder as the actual content of cerebrium.toml was not provided. ``` -------------------------------- ### Deploy Agent to Fly.io Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Use `flyctl` to create an app, set LiveKit and other necessary secrets, and deploy the agent. Scale the deployment manually if needed. ```bash curl -L https://fly.io/install.sh | sh fly auth login fly app create agent-example fly secrets set --app agent-example \ LIVEKIT_URL="wss://your-project.livekit.cloud" \ LIVEKIT_API_KEY="your-api-key" \ LIVEKIT_API_SECRET="your-api-secret" \ OPENAI_API_KEY="your-openai-key" # add any other secrets your agent needs fly deploy -c fly.toml fly scale count 3 --app agent-example ``` -------------------------------- ### Deploy Agent on Render Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Instructions for setting up a LiveKit Agent deployment on Render. This involves creating an environment group for secrets and then creating a Blueprint pointing to the repository containing the render.yaml file. ```bash # In the Render dashboard (https://dashboard.render.com): # 1. Create an Environment Group named "agent-example-env" with: # LIVEKIT_URL=wss://your-project.livekit.cloud # LIVEKIT_API_KEY=your-api-key # LIVEKIT_API_SECRET=your-api-secret # 2. Create a Blueprint pointing to your repository. # Render will detect render.yaml and provision the service automatically. # To update: push a new Docker image tag and redeploy via the Render dashboard # or connect your repo for automatic deploys on git push. ``` -------------------------------- ### Fly.io Deployment Configuration Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Configuration file for deploying a LiveKit Agent to Fly.io. It uses a blue-green deployment strategy and sets a kill timeout for graceful shutdown. ```toml # fly.io/fly.toml app = 'agent-example' primary_region = 'iad' kill_timeout = "300s" [build] dockerfile = "Dockerfile" ignorefile = ".dockerignore" [env] PYTHONUNBUFFERED = '1' [[vm]] memory = '4gb' cpu_kind = 'shared' cpus = 2 [deploy] strategy = "bluegreen" [[checks]] name = "healthcheck" type = "tcp" interval = "10s" timeout = "2s" grace_period = "5s" port = 8081 ``` -------------------------------- ### Create a New Fly.io App Source: https://github.com/livekit-examples/agent-deployment/blob/main/fly.io/README.md Create a new application on Fly.io. You can specify a custom name for your app. This command assumes you have a fly.toml file in your project root. ```bash fly app create agent-example ``` -------------------------------- ### Build and Push Docker Image to ECR Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Builds a Docker image for the agent using buildx for multi-platform support and pushes it to the specified ECR repository. Requires the repository URI and a version tag. ```bash docker buildx build --platform linux/amd64 -t "": --push . ``` -------------------------------- ### Python Agent Application Entrypoint Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Minimal Python agent entry point using the livekit-agents SDK. Configure worker options and connect to a LiveKit room. ```python # python-agent-example-app/main.py import logging from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, WorkerType, cli logger = logging.getLogger("my-worker") logger.setLevel(logging.INFO) async def entrypoint(ctx: JobContext): logger.info("starting entrypoint") # Connect to the LiveKit room and subscribe to all tracks await ctx.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_ALL) logger.info("connected to the room") if __name__ == "__main__": cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, worker_type=WorkerType.ROOM)) ``` ```shell # requirements.txt livekit-agents>=0.9.0 # Run locally python main.py start # Pre-download model files at build time python main.py download-files ``` -------------------------------- ### Kubernetes Secret and Deployment Commands Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Commands to create a Kubernetes secret for LiveKit credentials, apply the agent manifest, scale the deployment, and check rollout status. ```bash # Create the Kubernetes secret kubectl create secret generic agent-example-livekit \ --namespace livekit \ --from-literal=LIVEKIT_URL="wss://your-project.livekit.cloud" \ --from-literal=LIVEKIT_API_KEY="your-api-key" \ --from-literal=LIVEKIT_API_SECRET="your-api-secret" # Apply the manifest kubectl apply -f agent-manifest.yaml # Scale the deployment kubectl scale deployment agent-example --replicas=3 -n livekit # Check rollout status kubectl rollout status deployment/agent-example -n livekit ``` -------------------------------- ### Describe ECR Repositories Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Fetches information about ECR repositories, primarily to retrieve the repository URI needed for Docker login and image tagging. ```bash aws ecr describe-repositories ``` -------------------------------- ### Node.js Dockerfile for LiveKit Agent Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Multi-stage Dockerfile for a Node.js LiveKit Agent using pnpm. It compiles TypeScript in a build stage and uses a slim final image for minimal size. ```dockerfile # node-agent-example-docker/Dockerfile # syntax=docker/dockerfile:1 FROM node:20-slim AS base WORKDIR /app RUN npm install -g pnpm@9.7.0 FROM base AS build RUN apt-get update -qq && apt-get install --no-install-recommends -y ca-certificates COPY --link . . RUN pnpm install --frozen-lockfile RUN npm run build FROM base COPY --from=build /app /app COPY --from=build /etc/ssl/certs /etc/ssl/certs EXPOSE 8081 CMD ["node", "./dist/agent.js", "start"] ``` ```bash # Build and run locally docker build -t my-node-agent . docker run --rm \ -e LIVEKIT_URL=wss://your-project.livekit.cloud \ -e LIVEKIT_API_KEY=your-api-key \ -e LIVEKIT_API_SECRET=your-api-secret \ my-node-agent ``` -------------------------------- ### Configure Render Deployment Blueprint Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Defines a private service deployment on Render using a blueprint. It specifies the repository, service name, runtime, plan, environment variables from a group, region, and scaling parameters. ```yaml # render/render.yaml services: - type: pserv repo: https://github.com/livekit-examples/agent-deployment # Path to the directory containing your Dockerfile rootDir: python-agent-example-app name: agent-example runtime: image plan: starter # Credentials injected from a Render environment group envVars: - fromGroup: agent-example-env region: virginia maxShutdownDelaySeconds: 300 scaling: minInstances: 1 maxInstances: 4 targetCPUPercent: 60 targetMemoryPercent: 60 version: "1" ``` -------------------------------- ### Login Docker to ECR Repository Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Logs the Docker client into an AWS ECR repository using temporary credentials obtained via the AWS CLI. Requires the repository URI. ```bash aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin "" ``` -------------------------------- ### Deploy LiveKit Agents Service with Cerebrium Source: https://github.com/livekit-examples/agent-deployment/blob/main/cerebrium/README.md Deploy your LiveKit agents service to Cerebrium. Ensure your cerebrium.toml file is in the root of your project. ```bash cerebrium deploy ``` -------------------------------- ### Create CloudFormation Stack for ECS Resources Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Creates a CloudFormation stack to provision AWS resources including VPC, ECS Cluster, ECR repository, Task Definition, IAM Role, and ECS Service. ```bash aws cloudformation create-stack \ --stack-name agents-stack \ --template-body file://cloudformation.yaml \ --capabilities CAPABILITY_NAMED_IAM ``` -------------------------------- ### AWS ECS with CloudFormation Deployment Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Steps to deploy a LiveKit Agent to AWS ECS Fargate using CloudFormation. This includes storing credentials in Secrets Manager, creating the stack, pushing a Docker image, and updating the stack to scale. ```bash # 1. Store LiveKit credentials in AWS Secrets Manager aws secretsmanager create-secret \ --name ecs/agent-example/livekit-url \ --region us-east-1 \ --secret-string "wss://your-project.livekit.cloud" aws secretsmanager create-secret \ --name ecs/agent-example/livekit-api-key \ --region us-east-1 \ --secret-string "your-api-key" aws secretsmanager create-secret \ --name ecs/agent-example/livekit-api-secret \ --region us-east-1 \ --secret-string "your-api-secret" # 2. Create the CloudFormation stack (update cloudformation.yaml with secret ARNs first) aws cloudformation create-stack \ --stack-name agents-stack \ --template-body file://cloudformation.yaml \ --capabilities CAPABILITY_NAMED_IAM # 3. Retrieve the ECR repository URI aws ecr describe-repositories --query 'repositories[?repositoryName==`agent-example`].repositoryUri' --output text # 4. Authenticate Docker and push the image aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin "" docker buildx build --platform linux/amd64 \ -t ":v1.0.0" --push . # 5. Update cloudformation.yaml image tag, then scale up to 1 # Set DesiredCount: 1 in AgentExampleService, then: aws cloudformation update-stack \ --stack-name agents-stack \ --template-body file://cloudformation.yaml \ --capabilities CAPABILITY_NAMED_IAM # 6. Deploy a new version docker buildx build --platform linux/amd64 \ -t ":v1.0.1" --push . # Update image tag in cloudformation.yaml, then run update-stack again ``` -------------------------------- ### Render Environment Variables for LiveKit Agents Source: https://github.com/livekit-examples/agent-deployment/blob/main/render/README.md Configure these environment variables in your Render environment group to connect your agents to LiveKit. Ensure you replace the placeholder values with your actual LiveKit credentials. ```bash LIVEKIT_URL=wss://your-livekit-url.livekit.cloud LIVEKIT_API_KEY=your-livekit-api-key LIVEKIT_API_SECRET=your-livekit-api-secret ``` -------------------------------- ### Apply Kubernetes Manifest Source: https://github.com/livekit-examples/agent-deployment/blob/main/kubernetes/README.md Apply the agent manifest to your Kubernetes cluster. Ensure you have reviewed and modified the `agent-manifest.yaml` file with your specific configurations, including environment variables and resource limits. ```bash kubectl apply -f agent-manifest.yaml ``` -------------------------------- ### Scale Application Instances Source: https://github.com/livekit-examples/agent-deployment/blob/main/fly.io/README.md Manually adjust the number of running instances for your Fly.io application. This command allows you to scale the count of your deployed agent. ```bash fly scale count --app agent-example ``` -------------------------------- ### Kubernetes Deployment Manifest Source: https://context7.com/livekit-examples/agent-deployment/llms.txt A Kubernetes Deployment manifest for a LiveKit Agent. It configures a 10-minute termination grace period for conversation draining and specifies resource requests for CPU and memory. ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: agent-example namespace: livekit labels: app: agent-example spec: replicas: 1 selector: matchLabels: app: agent-example template: metadata: labels: app: agent-example spec: # Allow 10 minutes for ongoing conversations to finish terminationGracePeriodSeconds: 600 containers: - name: agent-example image: your-docker-repo.com/path-to-your-docker-build:latest resources: requests: cpu: "4" memory: "8Gi" limits: cpu: "4" memory: "8Gi" env: - name: LIVEKIT_URL valueFrom: secretKeyRef: name: agent-example-livekit key: LIVEKIT_URL - name: LIVEKIT_API_KEY valueFrom: secretKeyRef: name: agent-example-livekit key: LIVEKIT_API_KEY - name: LIVEKIT_API_SECRET valueFrom: secretKeyRef: name: agent-example-livekit key: LIVEKIT_API_SECRET ``` -------------------------------- ### Set Application Secrets Source: https://github.com/livekit-examples/agent-deployment/blob/main/fly.io/README.md Configure necessary secrets for your Fly.io application, such as LiveKit connection details. These secrets are exposed as environment variables to your deployed application. Add any other required secrets for your specific agent. ```bash fly secrets set --app agent-example \ LIVEKIT_URL="wss://your-url-from-livekit-cloud-dashboard.livekit.cloud" \ LIVEKIT_API_KEY="api-key-from-livekit-cloud-dashboard" \ LIVEKIT_API_SECRET="api-secret-from-livekit-cloud-dashboard" ``` -------------------------------- ### Configure Cerebrium Deployment Source: https://context7.com/livekit-examples/agent-deployment/llms.txt Defines deployment settings for a Cerebrium agent, including name, Python version, base image, and resource allocation. Ensure secrets are added via the Cerebrium dashboard. ```toml [cerebrium.deployment] name = "cerebrium" python_version = "3.11" docker_base_image_url = "debian:bookworm-slim" disable_auth = false include = ['./*', 'main.py', 'cerebrium.toml'] exclude = ['.*'] [cerebrium.hardware] cpu = 2 memory = 8.0 compute = "CPU" [cerebrium.scaling] min_replicas = 1 max_replicas = 5 cooldown = 30 replica_concurrency = 1 response_grace_period = 900 # seconds to let active conversations finish scaling_metric = "cpu_utilization" scaling_target = 60 [cerebrium.runtime.custom] port = 8081 dockerfile_path = "./Dockerfile" ``` -------------------------------- ### Create AWS Secrets for ECS Agent Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Creates necessary secrets in AWS Secrets Manager for LiveKit URL, API Key, and API Secret. These are required for the agent to connect to LiveKit. ```bash aws secretsmanager create-secret \ --name ecs/agent-example/livekit-url \ --region us-east-1 \ --secret-string "wss://your-url-from-livekit-cloud-dashboard.livekit.cloud" aws secretsmanager create-secret \ --name ecs/agent-example/livekit-api-key \ --region us-east-1 \ --secret-string "api-key-from-livekit-cloud-dashboard" aws secretsmanager create-secret \ --name ecs/agent-example/livekit-api-secret \ --secret-string "api-secret-from-livekit-cloud-dashboard" ``` -------------------------------- ### Update CloudFormation Stack Source: https://github.com/livekit-examples/agent-deployment/blob/main/aws-ecs/README.md Updates an existing CloudFormation stack with changes from the template file. Used after modifying the CloudFormation YAML, such as updating the Docker image URI or desired count. ```bash aws cloudformation update-stack \ --stack-name agents-stack \ --template-body file://cloudformation.yaml \ --capabilities CAPABILITY_NAMED_IAM ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.