clean-wolf-63214
06/27/2025, 5:38 PMtall-airline-16756
06/27/2025, 5:38 PMtall-airline-16756
06/27/2025, 5:38 PMconversation_item_added
event is triggered when an item is committed to the chat history. This event applies to both user and agent items. It includes a single property:
• `item`: ChatMessage - represents the message that was added to the conversation.
You can handle this event by registering a callback function. Here's an example:
from livekit.agents import ConversationItemAddedEvent
from livekit.agents.llm import ImageContent, AudioContent
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
print(f"Conversation item added from {event.item.role}: {event.item.text_content}. interrupted: {event.item.interrupted}")
# to iterate over all types of content:
for content in event.item.content:
if isinstance(content, str):
print(f" - text: {content}")
elif isinstance(content, ImageContent):
# image is either a rtc.VideoFrame or URL to the image
print(f" - image: {content.image}")
elif isinstance(content, AudioContent):
# frame is a list[rtc.AudioFrame]
print(f" - audio: {content.frame}, transcript: {content.transcript}")
This allows you to process various types of content in the conversation item, such as text, images, and audio.
Sources: Events and error handling | LiveKit Docs