does 1.x agent have this log like 0.x had? e.g. "c...
# ask-ai
m
does 1.x agent have this log like 0.x had? e.g. "committed agent speech"
t
Thanks for reaching out, Kush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether 1.x includes the same "committed agent speech" log that 0.x had. 1.x does not expose a log entry specifically named "committed agent speech." Instead, agent speech that is committed to the conversation is emitted as a
conversation_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 docs
m
Yes provide an example of subscribing/loggigin
t
You're asking for an example of subscribing to and logging
conversation_item_added
in 1.x. Below are concise examples in Python and JavaScript. Python (sync handler)
Copy code
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)
Copy code
@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
Copy code
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 conversations
l
Can you let me know how would I get this log as well directly from livekit? speech playout finished
t
You're asking how to get the "speech playout finished" log directly from LiveKit. Use the
playback_finished
event on the session's audio output — it fires when synthesized speech has finished playing and includes an
interrupted
flag. Python
Copy code
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
Copy code
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 speaking
l
What about {"message": "speech playout started", "level": "DEBUG", "name": "livekit.agents.pipeline", "speech_id": "c0e2f5c00d2d", "pid": 78410, "job_id": "AJ_jq5dcFRuraWR", "timestamp": "2025-12-04T202758.322238+00:00"}?
t
That log line is the internal debug message emitted when audio playback for a speech utterance begins. You can detect the same event programmatically by listening for
playback_started
on
session.output.audio
, and correlate it to the
speech_id
from logs or
conversation_item_added
. Python
Copy code
@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
Copy code
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 speaking
l
How do I get those all internal debug messages from livekit without subscribing like this?
t
You're asking how to get LiveKit's internal debug messages (like "speech playout started") without adding event listeners in your app. You can do that without subscribing in code by using one of these options: • Agent Observability (LiveKit Cloud): Open the Agent insights for the session in the dashboard to view runtime debug logs, traces, and turn-by-turn details (includes playback start/finish messages). No code required. • Stream logs with the LiveKit CLI: ◦ Run
lk 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 Docs
l
I am running with that log level only. Do I also need to put something like this? logging.getLogger("livekit.agents.pipeline").setLevel(logging.DEBUG)
t
Setting the agent process log level to DEBUG is generally sufficient to emit internal debug lines like those from livekit.agents.pipeline. You do not strictly need to call
Copy code
logging.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:
Copy code
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.
l
I am running on Livekit Cloud btw. Just wanted you to have this information for context.
t
Thanks — helpful context. Since you're on LiveKit Cloud and already running with DEBUG: • You do not need to call
logging.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?
l
How about the event for "validated agent reply"?
t
You're asking how to observe a "validated agent reply." There isn't a separate event named "validated agent reply." Use
speech_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:
Copy code
@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 docs
l
Can you do this: If you want, I can provide a JSON-formatted logger example that correlates
speech_id
,
job_id
, and timestamps across these events
t
Below is a concise JSON-formatted logger example (Python and Node) that captures and correlates
speech_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)
Copy code
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)
Copy code
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?
l
What about: skipping validation, agent is speaking and does not allow interruptions
t
You're asking how to detect when the agent is "skipping validation" and is speaking with interruptions disabled. There is no dedicated event named "skipping validation." To observe that state, combine these signals: •
speech_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