enough-dentist-75383
12/08/2025, 11:36 AMtall-airline-16756
12/08/2025, 11:37 AMtall-airline-16756
12/08/2025, 11:37 AMlk 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:
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 docsenough-dentist-75383
12/08/2025, 11:42 AMtall-airline-16756
12/08/2025, 11:42 AMlk 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.enough-dentist-75383
12/08/2025, 11:42 AMtall-airline-16756
12/08/2025, 11:43 AM[project]
name = "custom-agent"
dependencies = [
"livekit-agents",
"livekit",
"uv"
]
2) agent.py (minimal multimodal agent)
# 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)
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)
[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:
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 APIenough-dentist-75383
12/08/2025, 11:46 AMtall-airline-16756
12/08/2025, 11:46 AMuv 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?enough-dentist-75383
12/08/2025, 3:07 PMtall-airline-16756
12/08/2025, 3:07 PMuv 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?enough-dentist-75383
12/09/2025, 2:54 PMtall-airline-16756
12/09/2025, 2:55 PMtts.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|enough-dentist-75383
12/09/2025, 2:55 PMenough-dentist-75383
12/09/2025, 2:55 PMtall-airline-16756
12/09/2025, 2:56 PMCARTESIA_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:
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:
@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 docstall-airline-16756
12/09/2025, 2:56 PMCARTESIA_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:
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:
@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.enough-dentist-75383
12/09/2025, 2:57 PMtall-airline-16756
12/09/2025, 2:57 PMuv 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:
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:
@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).enough-dentist-75383
12/09/2025, 2:58 PMtall-airline-16756
12/09/2025, 2:58 PMfrom 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.
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 LiveKitenough-dentist-75383
12/09/2025, 4:05 PMenough-dentist-75383
12/09/2025, 4:05 PMtall-airline-16756
12/09/2025, 4:06 PMenough-dentist-75383
12/09/2025, 4:07 PMtall-airline-16756
12/09/2025, 4:07 PM