What is the equivalent of `@session.on("agent_spee...
# ask-ai
b
What is the equivalent of
@session.on("agent_speech_committed")
on Agents Python 1.x? I am migrating from Agent Python 0.x
user_turn_completed
seems relevant but this is for the user, not the agent
t
Thanks for reaching out, Stefanos. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help clarify this for you! In Agents Python 1.x, the equivalent of
@session.on("agent_speech_committed")
is actually the
conversation_item_added
event. This event fires whenever a message—whether from the user or the agent—is added to the chat history. If you'd like to specifically handle messages from the agent, here’s a friendly approach you can try:
Copy code
from livekit.agents import ConversationItemAddedEvent

@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
    # Check if the message is from the agent
    if event.item.role == "assistant":
        print(f"Agent speech committed: {event.item.text_content}")
Just so you know, the
item
property on the event gives you access to the committed
ChatMessage
, including its content, role, and metadata. This is the best way to work with agent messages in Agents Python 1.x. Sources: Text and transcriptions | LiveKit Docs | Docs::Agents