microscopic-airport-67304
12/04/2025, 8:23 PMtall-airline-16756
12/04/2025, 8:23 PMtall-airline-16756
12/04/2025, 8:23 PMconversation_item_added event when an item (including agent speech) is added to the chat history. You can use that event for the same observability purpose (capture the agent's final spoken text in the timeline).
Would you like an example of subscribing to or logging conversation_item_added events from your runtime?
Sources: Agent insights in LiveKit Cloud | LiveKit docs | Events and error handling | LiveKit docsmicroscopic-airport-67304
12/04/2025, 8:26 PMtall-airline-16756
12/04/2025, 8:26 PMconversation_item_added in 1.x. Below are concise examples in Python and JavaScript.
Python (sync handler)
from livekit.agents import AgentSession, ConversationItemAddedEvent
# assume session is created
session = AgentSession(...)
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
item = event.item
print(f"Conversation item added - role={item.role}, text={item.text_content}")
for content in item.content:
if isinstance(content, str):
print(f" - Text: {content}")
else:
print(f" - Content: {content}")
Python (async handler)
@session.on("conversation_item_added")
async def on_conversation_item_added(event: ConversationItemAddedEvent):
item = event.item
# async-safe logging or processing
print(f"Conversation item added - role={item.role}, text={item.text_content}")
JavaScript / TypeScript
import { AgentSession } from "livekit-agents";
const session = new AgentSession({...});
session.on("conversation_item_added", (event) => {
const item = event.item;
console.log(`Conversation item added - role=${item.role}, text=${item.text_content}`);
(item.content || []).forEach((c: any) => {
if (typeof c === "string") console.log(" - Text:", c);
else console.log(" - Content:", c);
});
});
Do you want this wired to a structured logger (JSON) or stored to a file/DB? I can provide that next.
Sources: Events and error handling | LiveKit docs | How to capture real-time agent transcriptions during conversationslively-magazine-71371
12/04/2025, 8:48 PMtall-airline-16756
12/04/2025, 8:48 PMplayback_finished event on the session's audio output — it fires when synthesized speech has finished playing and includes an interrupted flag.
Python
from livekit.agents.voice.io import PlaybackFinishedEvent
@session.output.audio.on("playback_finished")
def on_playback_finished(ev: PlaybackFinishedEvent):
# ev.interrupted is True if playback was cut off
print(f"Speech playout finished. Interrupted: {ev.interrupted}")
Node.js / TypeScript
session.output.audio.on('playback_finished', (ev) => {
console.log(`Speech playout finished. Interrupted: ${ev.interrupted}`);
});
Notes:
• session.output.audio may be None/undefined before the session starts or if audio output is disabled.
• This event signals actual audio playback completion (different from transcription finalization).
Would you like this forwarded to a structured logger (JSON) or stored to a file/DB?
Sources: How to detect when an agent has finished speakinglively-magazine-71371
12/04/2025, 8:56 PMtall-airline-16756
12/04/2025, 8:56 PMplayback_started on session.output.audio, and correlate it to the speech_id from logs or conversation_item_added.
Python
@session.output.audio.on("playback_started")
def on_playback_started(ev=None):
# ev may be None or contain metadata depending on runtime
# correlate using speech_id from your conversation item or logs
print("Speech playout started")
Node.js / TypeScript
session.output.audio.on("playback_started", (ev) => {
console.log("Speech playout started");
// correlate ev or conversation item to speech_id if available
});
Use the playback_finished event to detect completion and the conversation_item_added event to get the committed speech text and speech_id for correlation. Would you like an example that logs JSON with speech_id, job_id, and timestamps?
Sources: How to detect when an agent has finished speakinglively-magazine-71371
12/04/2025, 9:04 PMtall-airline-16756
12/04/2025, 9:05 PMlk agent logs to stream stdout/stderr (includes debug messages when the agent is started with --log-level=DEBUG).
• Forward runtime logs to an external provider (no per-event subscription):
◦ Configure secrets to enable forwarding to Datadog, CloudWatch, Sentry, or New Relic. Once enabled, all internal debug logs are sent automatically.
Notes:
• Ensure the agent log level is set to DEBUG to capture debug lines.
• LiveKit Cloud's dashboard is good for quick inspection; for long-term retention and querying, forward logs to an external provider.
Would you like the exact CLI commands or the secret keys/CLI snippets for one of the forwarding destinations (Datadog, CloudWatch, Sentry, or New Relic)?
Sources: https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal| | Agent insights in LiveKit Cloud | LiveKit docs | Agent server options | LiveKit docs | Log collection | LiveKit Docslively-magazine-71371
12/05/2025, 3:24 PMtall-airline-16756
12/05/2025, 3:24 PMlogging.getLogger("livekit.agents.pipeline").setLevel(logging.DEBUG)
unless one of these is true:
• Your app or another library later overrides logger levels, filters, or handlers.
• You want to raise only that specific logger to DEBUG while keeping others quieter.
If you do set it explicitly, also ensure your handlers will emit DEBUG-level records (e.g., root handler level is DEBUG or lower). Example safe setup:
import logging
logging.basicConfig(level=logging.DEBUG) # ensures handlers will output DEBUG
logging.getLogger("livekit.agents.pipeline").setLevel(logging.DEBUG) # optional explicit per-logger
If you still don't see pipeline debug lines after this, tell me whether you're running on LiveKit Cloud or self-hosted and how you're viewing logs (CLI, dashboard, external forwarder) and I’ll help troubleshoot next steps.lively-magazine-71371
12/05/2025, 3:25 PMtall-airline-16756
12/05/2025, 3:25 PMlogging.getLogger("livekit.agents.pipeline").setLevel(logging.DEBUG") unless:
◦ another part of your app changes logger levels/handlers, or
◦ you want to raise only that specific logger to DEBUG while keeping others quieter.
• What matters:
◦ Agent process must start with --log-level=DEBUG (you already have this).
◦ Handlers must allow DEBUG output (e.g., logging.basicConfig(level=logging.DEBUG) if you control Python handlers).
◦ LiveKit Cloud will collect and show those debug logs in the Agent insights dashboard automatically.
• Quick checks if you still don't see the pipeline debug lines:
a. Confirm the agent instance shown in Agent insights is the same one running with --log-level=DEBUG.
b. Use lk agent logs to stream the instance stdout to verify debug lines are emitted.
c. Ensure no runtime config or library is lowering the pipeline logger level after startup.
If you'd like, I can provide the exact commands to stream logs from LiveKit Cloud or a tiny Python snippet that ensures handlers are at DEBUG so nothing gets filtered. Which would you prefer?lively-magazine-71371
12/05/2025, 4:27 PMtall-airline-16756
12/05/2025, 4:27 PMspeech_created as the equivalent: it fires when a reply/speech is constructed and ready for playout (i.e., validated and scheduled). To track the full lifecycle, combine these:
• speech_created — reply validated and SpeechHandle available.
• session.output.audio.on("playback_started") — playout started.
• session.output.audio.on("playback_finished") — playout finished (ev.interrupted shows if cut off).
• conversation_item_added — reply committed to conversation history (includes `speech_id`/text).
Example Python wiring:
@session.on("speech_created")
def on_speech_created(ev):
print("speech_created", ev.speech_handle.speech_id)
@session.output.audio.on("playback_started")
def on_playback_started(ev=None):
print("playout started")
from livekit.agents.voice.io import PlaybackFinishedEvent
@session.output.audio.on("playback_finished")
def on_playback_finished(ev: PlaybackFinishedEvent):
print("playout finished", ev.interrupted)
@session.on("conversation_item_added")
def on_conversation_item_added(ev):
print("committed to history", ev.item.role, ev.item.text_content)
If you want, I can provide a JSON-formatted logger example that correlates speech_id, job_id, and timestamps across these events. Which format do you prefer?
Sources: Events and error handling | LiveKit docs | How to detect when an agent has finished speaking | Prompting guide | LiveKit docslively-magazine-71371
12/05/2025, 4:28 PMspeech_id, job_id, and timestamps across these eventstall-airline-16756
12/05/2025, 4:29 PMspeech_id, job_id, and timestamps for speech_created, conversation_item_added, playback_started, and playback_finished. Each log entry is emitted as a single JSON object suitable for structured logging/forwarding.
Python (structured logging)
import json
import time
from datetime import datetime, timezone
from livekit.agents.voice.io import PlaybackFinishedEvent
def now_iso():
return datetime.now(timezone.utc).isoformat()
def log_json(**kwargs):
print(json.dumps(kwargs, default=str, ensure_ascii=False))
@session.on("speech_created")
def on_speech_created(ev):
# ev.speech_handle contains speech_id and job metadata
log_json(
event="speech_created",
level="INFO",
timestamp=now_iso(),
speech_id=getattr(ev.speech_handle, "speech_id", None),
job_id=getattr(ev.speech_handle, "job_id", None),
role=getattr(ev.speech_handle, "role", None),
)
@session.on("conversation_item_added")
def on_conversation_item_added(ev):
item = ev.item
log_json(
event="conversation_item_added",
level="INFO",
timestamp=now_iso(),
speech_id=getattr(item, "speech_id", None),
job_id=getattr(item, "job_id", None),
role=item.role,
text=item.text_content,
)
@session.output.audio.on("playback_started")
def on_playback_started(ev=None):
# Attempt to extract speech_id/job_id from ev or session state if available
speech_id = getattr(ev, "speech_id", None) if ev else None
log_json(
event="playout_started",
level="DEBUG",
timestamp=now_iso(),
speech_id=speech_id,
)
@session.output.audio.on("playback_finished")
def on_playback_finished(ev: PlaybackFinishedEvent):
# ev may include speech_id or be correlated via SpeechHandle in your app
log_json(
event="playout_finished",
level="DEBUG",
timestamp=now_iso(),
speech_id=getattr(ev, "speech_id", None),
interrupted=getattr(ev, "interrupted", None),
)
Node.js / TypeScript (structured logging)
function nowIso() {
return new Date().toISOString();
}
function logJson(obj: Record<string, any>) {
console.log(JSON.stringify(obj));
}
session.on("speech_created", (ev: any) => {
logJson({
event: "speech_created",
level: "INFO",
timestamp: nowIso(),
speech_id: ev.speech_handle?.speech_id ?? null,
job_id: ev.speech_handle?.job_id ?? null,
role: ev.speech_handle?.role ?? null,
});
});
session.on("conversation_item_added", (ev: any) => {
const item = ev.item;
logJson({
event: "conversation_item_added",
level: "INFO",
timestamp: nowIso(),
speech_id: item?.speech_id ?? null,
job_id: item?.job_id ?? null,
role: item?.role ?? null,
text: item?.text_content ?? null,
});
});
session.output.audio.on("playback_started", (ev: any) => {
logJson({
event: "playout_started",
level: "DEBUG",
timestamp: nowIso(),
speech_id: ev?.speech_id ?? null,
});
});
session.output.audio.on("playback_finished", (ev: any) => {
logJson({
event: "playout_finished",
level: "DEBUG",
timestamp: nowIso(),
speech_id: ev?.speech_id ?? null,
interrupted: ev?.interrupted ?? null,
});
});
Notes:
• Some event objects may not include speech_id or job_id directly; if missing, track the mapping between SpeechHandle and playback in your app state so you can emit the IDs when `playback_started`/`finished` fire.
• These logs are ready to forward to external observability systems or viewed in stdout (LiveKit Cloud will capture stdout logs when running in Cloud).
Would you like a version that writes these JSON logs to a file or forwards them to Datadog/CloudWatch?lively-magazine-71371
12/05/2025, 4:54 PMtall-airline-16756
12/05/2025, 4:54 PMspeech_created — indicates a reply/speech was created and is ready (this is the closest equivalent to "validated" and scheduled for playout).
• agent_state_changed with new_state == "speaking" — indicates the agent has started speaking.
• Track the allow_interruptions flag you passed to session.say() / session.generate_reply() (e.g., allow_interruptions=False) when you create the speech. Store that alongside the speech_id from the SpeechHandle.
• playback_started / playback_finished on session.output.audio — shows playout lifecycle (use ev.interrupted on finish to see if an interruption occurred).
• conversation_item_added — shows the reply committed to history (useful to correlate `speech_id`/`job_id`).
Practical approach (recommended):
1. On speech_created, log a JSON entry with speech_id, job_id, and allow_interruptions.
2. On agent_state_changed == speaking, emit a correlated log referencing that speech_id.
3. On playback_started / playback_finished, emit correlated logs (include interrupted on finish).
4. Use Agent insights or your forwarded logs to query these correlated entries to prove the agent was speaking and interruptions were disabled.
If you want, I can provide the small JSON-logging snippet that wires allow_interruptions into the logs for direct correlation. Which language—Python or Node—do you prefer?
Sources: Events and error handling | LiveKit docs | Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Log collection | LiveKit Docs | Streamline Troubleshooting with Agent Observability