What does the ConversationItemAddedEvent event do?
# ask-ai
b
What does the ConversationItemAddedEvent event do?
t
Thanks for reaching out, aile. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
ConversationItemAddedEvent
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:
Copy code
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.