alert-australia-33132
08/21/2025, 12:14 PMtall-airline-16756
08/21/2025, 12:14 PMtall-airline-16756
08/21/2025, 12:18 PMrecord_exception function in the telemetry system to automatically grab those tracebacks.
• Manual Traceback Printing: If you want quick debugging, just use traceback.print_exc() in your exception handling code.
• Logger-based Exception Handling: Another great way is using logger.exception() to log errors along with tracebacks in a neat, structured way.
• Error Event Handling: For voice agents, you can handle errors through the session’s error event system.
• LiveKit CLI: Want to see agent logs live? Use the CLI with livekit-cli agent logs <agent-id> to check out tracebacks in real-time.
• Telemetry and Tracing: You can also integrate telemetry services like LangFuse for detailed error tracking and stack traces.
If you’d like me to walk you through any of these or need more info, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/telemetry/trace_types.py | complex-agents/nutrition-assistant/agent.py | pkg/agentfs/logs.go | Logs, metrics, and telemetry | LiveKit Docsalert-australia-33132
08/21/2025, 8:20 PMtall-airline-16756
08/21/2025, 8:21 PM@session.on("error")
def on_error(ev: ErrorEvent):
asyncio.create_task(log_error_to_database(ev))
if ev.error.recoverable:
return
logger.info(f"session is closing due to unrecoverable error {ev.error}")
1. Database Logging: To keep things running smoothly, log errors asynchronously so the agent doesn’t get held up. Here’s how:
async def log_error_to_database(error_event: ErrorEvent):
loop = asyncio.get_event_loop()
await loop.run_in_executor(
db_executor,
_insert_error_record,
error_event.error.type,
str(error_event.error),
error_event.error.recoverable,
type(error_event.source).__name__ if hasattr(error_event, 'source') else None
)
def _insert_error_record(error_type: str, error_message: str, recoverable: bool, source_component: str):
conn = sqlite3.connect("agent_errors.db")
cursor = conn.cursor()
cursor.execute(
"""
INSERT INTO agent_errors
(error_type, error_message, occurred_at, recoverable, source_component)
VALUES (?, ?, ?, ?, ?)
""",
(error_type, error_message, datetime.now(), recoverable, source_component)
)
conn.commit()
conn.close()
Another option is to send your logs to external services like Datadog for centralized monitoring. If you want, I’d be happy to walk you through any of these options or help you set up the one that fits best!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | complex-agents/nutrition-assistant/agent.py | Log collection | LiveKit Docsalert-australia-33132
08/21/2025, 8:24 PMtall-airline-16756
08/21/2025, 8:25 PM@session.on("error") event pops up whenever there’s an issue with core AI components during a session, like:
• LLM errors: When the language model hits a snag during inference
• STT errors: Problems with converting speech to text
• TTS errors: Trouble with turning text into speech
• RealtimeModel errors: Errors coming from realtime language models
Every time this error event fires, it gives you the lowdown on what went wrong, whether it’s something you can bounce back from, and which component caused it. Just a heads-up though—failures in tool execution and entrypoint errors (like in on_enter methods) won’t trigger this event. Those tool-specific hiccups are handled separately, usually through the function_tools_executed event.
If you want me to walk you through any part of this or need tips on handling errors in certain situations, just give me a shout!
Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime... | Events and error handling | LiveKit Docs