wooden-angle-9937
08/27/2025, 4:08 AMtall-airline-16756
08/27/2025, 4:08 AMtall-airline-16756
08/27/2025, 4:09 AMsession.history property. It holds the entire chat history. Here’s a friendly little guide on how to do it:
• You can check out the session.history property anytime during or after the session.
• Then, use the add_shutdown_callback method or listen for the close event on the session to save the conversation right when the session ends.
Here’s a simple example to log the chat history:
@session.on("close")
def on_close(ev: CloseEvent):
print("Chat History:")
for item in session.history.items:
if item.type == "message":
text = f"{item.role}: {item.text_content.replace('\n', '\\n')}"
if item.interrupted:
text += " (interrupted)"
print(text)
This way, you’ll make sure the full conversation is saved and ready to be exported to a file or database whenever you need it.
And if you’re also looking to record audio or video, LiveKit’s Egress feature has got you covered for recording the whole session. Just a quick tip: to avoid any extra audio after the user leaves, remember to delete the room or stop the egress when the session ends.
Sources: Session recording and transcripts | LiveKit Docs | tests/test_agent_session.py