lively-horse-90722
08/12/2025, 9:45 AMtall-airline-16756
08/12/2025, 9:45 AMtall-airline-16756
08/12/2025, 9:46 AM@agent.on("agent_stopped_speaking")
def on_agent_stopped_speaking(msg: llm.ChatMessage):
if isinstance(msg.content, list):
msg.content = "\n".join(
"[image]" if isinstance(x, llm.ChatImage) else x for x in msg
)
log_queue.put_nowait(f"[{datetime.now()}] AGENT:\n{msg.content}\n\n")
You can do the same for user speech by using the user_speech_committed event like this:
@agent.on("user_speech_committed")
def on_user_speech_committed(msg: llm.ChatMessage):
if isinstance(msg.content, list):
msg.content = "\n".join(
"[image]" if isinstance(x, llm.ChatImage) else x for x in msg
)
log_queue.put_nowait(f"[{datetime.now()}] USER:\n{msg.content}\n\n")
If you want to dive deeper, feel free to check out the LiveKit Documentation and take a look at this handy example code. Hope this helps!lively-horse-90722
08/12/2025, 9:50 AMtall-airline-16756
08/12/2025, 9:51 AMsession.say
or session.generate_reply
.
• conversation_item_added: This event happens when a new agent speech item is added to the conversation history.
Here’s a quick example showing how you can use these events:
@agent.on("AGENT_STARTED_SPEAKING")
def on_agent_started_speaking():
print("Agent started speaking.")
@agent.on("AGENT_STOPPED_SPEAKING")
def on_agent_stopped_speaking():
print("Agent stopped speaking.")
@agent.on("speech_created")
def on_speech_created(event):
print(f"New agent speech created. Source: {event.source}")
These events make it easy to log everything your agent says. If you want to dive deeper or have any questions, just give me a shout—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/events.py | VPAEvent | LiveKit Agents | Events and error handling | LiveKit Docs