square-bear-67002
05/08/2025, 6:07 PMtall-airline-16756
05/08/2025, 6:07 PMtall-airline-16756
05/08/2025, 6:08 PMuser_speech_committed
(when user speech is committed) and agent_stopped_speaking
(when the agent stops speaking).
• Accessing session history: Use the session.history
property to access the entire conversation history. You can also set up a shutdown callback to save this history when the session ends. For example:
async def write_transcript():
current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"/tmp/transcript_{ctx.room.name}_{current_date}.json"
with open(filename, 'w') as f:
json.dump(session.history.to_dict(), f, indent=2)
print(f"Transcript for {ctx.room.name} saved to {filename}")
ctx.add_shutdown_callback(write_transcript)
Additionally, for real-time access to the conversation, you can listen for events like conversation_item_added
(emitted whenever an item is added to the chat history) and user_input_transcribed
(emitted whenever user input is transcribed).
For more details and example code, you can refer to the MultimodalAgent example at: https://github.com/livekit/agents/blob/main/examples/conversation_persistor.py.
Sources: Recording agent sessions | LiveKit Docs | Session recording and transcripts | LiveKit Docs