boundless-truck-87206
08/03/2025, 5:28 PMtall-airline-16756
08/03/2025, 5:28 PMtall-airline-16756
08/03/2025, 5:28 PMConversationItemAddedEvent is triggered when an item is added to the chat history, such as a message from the user or the assistant. This event provides details about the message, including its content, role (user or assistant), and whether it was interrupted.
Key Features:
• Properties: Access the message's role, text content, and interruption status.
• Use Cases: Update chat interfaces, track conversation states, and monitor message interruptions.
• Event Flow: Emitted after a message is successfully added to the chat context, ensuring all processing is complete.
Example Usage:
from livekit.agents import ConversationItemAddedEvent
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
print(f"New message from {event.item.role}: {event.item.text_content}")
print(f"Interrupted: {event.item.interrupted}")
for content in event.item.content:
if isinstance(content, str):
print(f"Text content: {content}")
This event is essential for maintaining synchronized conversation history and supports both text and multimedia content.