how can i deploy my own agent in sandbox and test
# ask-ai
e
how can i deploy my own agent in sandbox and test
t
Thanks for reaching out, Guess. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to deploy your own agent to the LiveKit sandbox and test it — here’s a concise step-by-step you can follow. 1. Install and authenticate the LiveKit CLI • Install the LiveKit CLI and run:
Copy code
lk cloud auth
1. Prepare your agent project • Use a starter template (Python or Node) or your existing agent code. Ensure your project contains the expected agent entry points and configuration. 1. Deploy the agent • From your agent project directory run:
Copy code
lk agent create
This registers the agent, generates a
livekit.toml
config, builds the Docker image, and deploys it. 1. Open the sandbox test frontend • In the LiveKit Cloud dashboard go to your project’s Sandbox settings (Agent Builder). • Click “Test Agent” or “Regenerate test app” to get the public sandbox URL / agent preview. 1. Test and iterate • Use the Agent preview or sandbox frontend URL to interact with the agent in-browser. • Make code changes locally, then redeploy with
lk agent create
to update the sandbox. If you want, tell me which language/runtime you’re using (Python or Node) and whether you need the starter template links or help with a specific error during any step. Sources: Sandbox | LiveKit docs | Deploying to production | LiveKit Docs | Agent Builder | LiveKit docs
e
i want my own ai agent custom code i dont have any templete
t
Thanks — you want to deploy fully custom agent code (no template). Quick questions so I can give a targeted walkthrough: 1. Which programming language/runtime will you use for the agent? (Python, Node, Go, or other) 2. Do you already have a LiveKit Cloud project and CLI authenticated (
lk cloud auth
)? 3. Will your agent accept audio/video, text, or both? 4. Do you need instructions to build a Docker image and push it, or do you want to use
lk agent create
to handle build/deploy? Answer these and I’ll provide a minimal example scaffold and the exact steps to deploy and test in the sandbox.
e
1. python 2. yes 3. yes both 4. no
t
Great — since you’re using Python, already authenticated, want audio+video+text, and prefer not to use templates, here’s a minimal, focused plan and the exact files/commands to get a custom agent running and test it in the sandbox. What I’ll provide: • Minimal project layout and required files • Simple Python agent showing audio/video/text handling • How to run locally (dev) so sandbox frontend can talk to it • How to create a sandbox test app and join the room Project layout • agent/ ◦ pyproject.toml ◦ agent.py ◦ Dockerfile ◦ livekit.toml 1) pyproject.toml (dependencies)
Copy code
[project]
name = "custom-agent"
dependencies = [
  "livekit-agents",
  "livekit",
  "uv"
]
2) agent.py (minimal multimodal agent)
Copy code
# agent.py
import asyncio
from livekit.agents import cli, agents, JobContext, WorkerOptions
from livekit import rtc

class CustomAgent:
    async def on_participant_join(self, session, participant):
        await session.say("Hello — I can handle voice, video, and text.")

    async def on_user_speech(self, session, text):
        await session.say(f"You said: {text}")

    async def on_text_message(self, session, text, sender):
        await session.send_text(f"Received: {text}")

    async def on_video_frame(self, session, frame):
        # frame: process or inspect if needed
        print(f"Video frame {frame.width}x{frame.height}")

async def entrypoint(ctx: JobContext):
    session = agents.Session(ctx.room, ctx.agent_id, CustomAgent())

    session.on("participant_joined", lambda p: asyncio.create_task(session.agent.on_participant_join(session, p)))
    session.on("user_speech", lambda text: asyncio.create_task(session.agent.on_user_speech(session, text)))
    session.on("text_received", lambda text, sender: asyncio.create_task(session.agent.on_text_message(session, text, sender)))
    session.on("video_frame_received", lambda frame: asyncio.create_task(session.agent.on_video_frame(session, frame)))

    await session.start(
        room_io.InputOptions(audio_enabled=True, video_enabled=True, text_enabled=True),
        room_io.OutputOptions(audio_enabled=True, text_enabled=True)
    )

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
3) Dockerfile (for eventual cloud deploy; not required for dev)
Copy code
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim
WORKDIR /app
COPY pyproject.toml ./
RUN uv sync --locked
COPY . .
CMD ["uv", "run", "agent.py", "start"]
4) livekit.toml (basic)
Copy code
[agent]
name = "custom-agent"
cmd = ["uv", "run", "agent.py", "start"]
Run locally (dev mode) 1. From project dir, install dependencies per your environment or use the
uv
tool if available. 2. Start agent in dev mode so LiveKit Cloud can dispatch sessions to your local process:
Copy code
uv run agent.py dev
(This connects the worker to your LiveKit project and registers the agent.) Create sandbox frontend (test app) 1. In LiveKit Cloud dashboard, open your project → Sandbox. 2. Create or regenerate the sandbox test app (Agent Builder / Test Agent) and note the sandbox ID / public URL. 3. Ensure the sandbox token server is available so the frontend can join rooms. Test flow • Start your local agent with
uv run agent.py dev
. • Open the sandbox test app URL, join the room (allow mic/camera). • Speak, send text, or enable camera — your agent should receive events and respond with speech/text. • View agent logs locally to debug output. If you want, I can: • Produce a runnable Git repo (complete files) you can git clone. • Expand the agent to include STT/TT S plugin calls (Deepgram/OpenAI/Cartesia) for higher-quality speech handling. • Provide exact sandbox steps to generate tokens and the minimal frontend config to point at your agent. Which of those would you like next? Sources: React quickstart | LiveKit docs | Sandbox | LiveKit docs | Voice AI quickstart | LiveKit docs | Agent session | LiveKit docs | OpenAI and LiveKit partner to turn Advanced Voice into an API
e
cant we deploy agent code in sandbox
t
Short answer: the sandbox is a test frontend — it does not host or run your custom agent code directly. What you can do: • Run your agent locally in dev mode so the sandbox frontend dispatches sessions to your local process: a. Start your agent:
uv run agent.py dev
b. Open the sandbox test app URL and join a room — cloud will route the session to your running worker. • Or deploy your agent to LiveKit Cloud so the sandbox frontend talks to the cloud-hosted agent: a. Prepare
Dockerfile
and
livekit.toml
. b. Run
lk agent create
(or
lk agent deploy
) to register/build/deploy the agent. c. Use the sandbox test app to connect to the deployed agent. If you want, I can: • Give the exact
livekit.toml
and
Dockerfile
tweaks for cloud deploy, or • Walk you through running your Python agent in
dev
mode step-by-step so the sandbox can test it. Which would you like?
e
i want if we can use sandox for entire agent deployed and fe and all
t
Short answer: No — the sandbox is a test frontend only and does not host or run your custom backend agent code. What you can do instead: • Run your agent locally in dev mode while using the sandbox frontend to test: a. Start your Python agent:
uv run agent.py dev
b. Open the sandbox test app URL and join a room — LiveKit will dispatch the session to your running worker. • Or deploy your agent to LiveKit Cloud and use the sandbox frontend to connect to the cloud-hosted agent: a. Add
Dockerfile
and
livekit.toml
. b. Run
lk agent create
(or
lk agent deploy
) to build and deploy. c. Use the sandbox test app to interact with the deployed agent. If you want, I can: • Give step-by-step commands to run your agent in dev mode and verify the sandbox connection, or • Provide the exact
Dockerfile
and
livekit.toml
tweaks plus
lk
commands to deploy to LiveKit Cloud. Which option do you want to proceed with?
e
livekit tts failure and recovery
t
I can help with LiveKit TTS failures and recovery — to give precise steps I need a bit more info. Please share: • Which TTS provider(s) you're using (ElevenLabs, OpenAI, Cartesia, etc.). • Exact error message(s) or relevant agent logs (copy/paste). • Whether you configured a fallback chain (FallbackAdapter). • When the failure happens (startup, during speak, intermittently). • Are you running the agent locally (dev) or deployed to LiveKit Cloud? If you want a quick mitigation now, I can show a minimal code example using
tts.FallbackAdapter
and an error handler that notifies users and retries. Which would you prefer? Sources: Events and error handling | LiveKit docs | Text-to-speech (TTS) models | LiveKit Docs | examples/drive-thru | livekit/livekit_composite | DeepWiki | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal|
e
cartesia
its failing silently not getting any metrics -
t
Thanks — since you're using Cartesia for TTS, here’s a concise troubleshooting and recovery plan and the exact code you can add. Acknowledging: You asked about LiveKit TTS failures with Cartesia and how to recover. 1) Quick checklist to verify • Ensure
CARTESIA_API_KEY
is set for your agent process. • Confirm your agent is running (dev or deployed) and receiving sessions. • Check agent logs for Cartesia errors (rate limits, auth, network timeouts). 2) Add automatic recovery with a fallback adapter • Use a fallback TTS provider so speech continues if Cartesia fails. • Minimal example:
Copy code
from livekit.agents import tts, AgentSession
from livekit.plugins import cartesia, elevenlabs

tts_adapter = tts.FallbackAdapter([
    cartesia.TTS(model="sonic-3"),         # primary
    elevenlabs.TTS(voice="Rachel"),        # fallback
])

session = AgentSession(tts=tts_adapter)
3) Listen for TTS errors and inform users • Handle
error
events to log and notify users when failures happen:
Copy code
@session.on("error")
def on_error(event):
    if event.source == "tts":
        # recoverable True means fallback/retry will be attempted
        if not event.error.recoverable:
            session.say("Sorry — speech is currently unavailable. Please try again.")
        # always log for debugging
        print("TTS error:", event.error)
4) Retry and health checks • FallbackAdapter marks failed providers unhealthy and retries them automatically; no extra polling needed. • If you need custom retry behavior, wrap TTS calls with a short-exponential backoff before falling back. 5) Logs & diagnostics to collect (send these if you want deeper help) • Exact Cartesia error messages from agent logs • Whether failures are auth errors, rate limits, timeouts, or audio synthesis errors • Whether failures are intermittent or constant • Whether you’re running locally (dev) or deployed If you want, paste the Cartesia error lines from your agent logs and I’ll point to the exact fix (auth key, model mismatch, or suggested fallback configuration). Sources: Sandbox | LiveKit docs | Examples | livekit/livekit_composite | DeepWiki | livekit/livekit_composite | DeepWiki | Cartesia TTS | LiveKit docs | Cartesia TTS plugin guide | LiveKit docs
Thanks — I hear that Cartesia TTS is failing silently and no metrics are appearing. Let’s narrow this down and get recovery working. What to check now (quick checklist) • Confirm
CARTESIA_API_KEY
is set in the environment of the running agent process. • Verify the agent process is actually running and receiving sessions (local
uv run ... dev
or cloud logs). • Inspect agent logs for any Cartesia-related lines (auth, 4xx/5xx, timeouts). Search for "cartesia", "tts", or "error". • Confirm you’re using a supported model/voice (e.g.,
sonic-3
) in your Cartesia call. Immediate code changes to detect & recover 1) Add a FallbackAdapter so speech continues if Cartesia fails:
Copy code
from livekit.agents import tts, AgentSession
from livekit.plugins import cartesia, elevenlabs

tts_adapter = tts.FallbackAdapter([
    cartesia.TTS(model="sonic-3"),      # primary
    elevenlabs.TTS(voice="Rachel"),     # fallback
])

session = AgentSession(tts=tts_adapter)
2) Log and surface TTS errors to users:
Copy code
@session.on("error")
def on_error(event):
    if event.source == "tts":
        print("TTS error:", event.error)
        if not event.error.recoverable:
            # notify the user in-session
            session.say("Sorry — speech is currently unavailable. Please try again.")
Diagnostics I need from you to pinpoint the silent failure • Paste the Cartesia-related log lines (timestamps + error text) from your agent. • Are you running the agent in dev mode locally or deployed in LiveKit Cloud? • Are failures intermittent or constant? Any recent config/API key changes? • Do you have fallback configured already? If you prefer, paste the last 20 log lines mentioning "cartesia" or "tts" and I’ll identify the root cause and exact fix.
e
its failing silently
t
Thanks — I understand Cartesia TTS is failing silently. I’ll help troubleshoot and get recovery working. I need a few quick details and will give the highest-impact checks you can run right now. Questions (one or two answers each) 1. Are you running the agent locally in dev mode (
uv run ... dev
) or deployed to LiveKit Cloud? 2. Do you have a fallback configured (FallbackAdapter) in your
AgentSession
? 3. Share the last 20 lines of your agent logs that mention "cartesia", "tts", or "error" (paste here). Immediate checks to run now • Verify env var: confirm
CARTESIA_API_KEY
is set in the environment of the running agent. • Confirm agent is receiving sessions: check your agent stdout/logs for session start messages when a user joins. • Search logs for any Cartesia-related traces: run
grep -i "cartesia\|tts\|error" <logfile>
or inspect console output. • Validate model/voice: ensure you’re using a supported model (e.g.,
sonic-3
) and a valid voice ID. Hotfix to prevent silent user impact • Add a FallbackAdapter so speech still works when Cartesia fails:
Copy code
from livekit.agents import tts, AgentSession
from livekit.plugins import cartesia, elevenlabs

tts_adapter = tts.FallbackAdapter([
    cartesia.TTS(model="sonic-3"),
    elevenlabs.TTS(voice="Rachel"),
])

session = AgentSession(tts=tts_adapter)
• Add an error handler to log and notify users:
Copy code
@session.on("error")
def on_error(event):
    if event.source == "tts":
        print("TTS error:", event.error)
        if not event.error.recoverable:
            session.say("Sorry — speech is currently unavailable. Please try again.")
If you can paste the requested log lines and confirm dev vs cloud and fallback status, I’ll analyze the logs and tell you the exact root cause and next steps (auth, rate limit, model mismatch, network timeouts, or SDK bug).
e
retry tts how to do it
t
You can implement retries two ways: use the built-in FallbackAdapter (recommended) or add custom retry logic on TTS errors. Below are concise examples and best-practice notes for both. 1) Recommended — automatic retries via FallbackAdapter • Automatically switches to backups and marks unhealthy providers for later recovery.
Copy code
from livekit.agents import tts, AgentSession
from livekit.plugins import cartesia, elevenlabs, openai

tts_adapter = tts.FallbackAdapter([
    cartesia.TTS(model="sonic-3"),            # primary
    elevenlabs.TTS(voice="Rachel"),           # fallback 1
    openai.TTS(model="tts-1"),                # fallback 2
])

session = AgentSession(tts=tts_adapter)
2) Custom retry logic + user notification • Listen for error events and retry a limited number of times with backoff, then fall back or notify the user.
Copy code
import time
import asyncio

MAX_RETRIES = 3
BASE_DELAY = 0.5  # seconds

async def try_say(session, text):
    for attempt in range(1, MAX_RETRIES + 1):
        try:
            await session.say(text)   # uses session.tts internally
            return True
        except Exception as e:
            # log the error
            print(f"TTS attempt {attempt} failed: {e}")
            if attempt == MAX_RETRIES:
                return False
            await asyncio.sleep(BASE_DELAY * (2 ** (attempt - 1)))

@session.on("error")
def on_error(event):
    if event.source == "tts":
        print("TTS error event:", event.error)
        # reactive fallback/notify on non-recoverable error
        if not event.error.recoverable:
            asyncio.create_task(session.send_text("Speech is currently unavailable."))
Best practices • Use FallbackAdapter with at least one alternate provider to avoid user-visible silence. • Keep MAX_RETRIES small (2–4) and use exponential backoff to avoid amplifying transient failures. • Log full error details (provider, HTTP status, message, timestamps). Share those logs if you want deeper analysis. • Ensure env vars/API keys for all providers are correctly set and reachable from the agent process. • Monitor metrics/events: listen for
ErrorEvent
and
MetricsCollectedEvent
to detect repeated failures. If you want, I can: • Give the exact code to integrate an ElevenLabs fallback for your current Cartesia setup. • Review the Cartesia-related log lines you have and recommend whether to use fallback, retry, or configuration fixes. Which do you prefer? Sources: Events and error handling | LiveKit docs | Remote method calls | LiveKit docs | How to Get Help from LiveKit
e
livekit api new version
launch when happened
t
LiveKit's "Launch Week" occurred May 16–20, 2022. • May 16: Unity WebGL SDK release • May 17: React Native beta + React packages v1.0 • May 18: LiveKit 1.0 announced • May 19: Universal Egress announced • May 20: LiveKit Community Day Would you like links to the blog posts for any of those days? Sources: Launch Week! 🚀 | <![CDATA[ LiveKit Blog ]]>
e
livekit-agents[openai,deepgram,cartesia,bey,silero,turn-detector] livekit-api> latest versiona dn when did it launch
t
I don’t have exact latest version numbers or release dates for those specific packages in my sources. To get the current versions and release dates, check these places: • PyPI pages for each package (search: livekit-agents, livekit-api, livekit-plugins like cartesia, deepgram, openai, silero, bey, turn-detector). • GitHub repositories/releases (e.g., livekit/agents, livekit/livekit, livekit/agents-plugins). • LiveKit docs or release notes for announcements. If you’d like, I can: • Look up the current PyPI/GitHub version numbers and release dates for each package you listed and paste them here — confirm you want me to do that. Sources: OpenAI STT plugin guide | LiveKit docs | Agents Framework | livekit/livekit_composite | DeepWiki | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Server-side | livekit/livekit_composite | DeepWiki | server-sdk-go | livekit/livekit_composite | DeepWiki