how to modify the session history like adding time...
# ask-ai
a
how to modify the session history like adding timestamp to each event
t
Thanks for reaching out, Arun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you want to add a timestamp to each session-history event. You can do this by listening for the
conversation_item_added
event on the session, attaching a timestamp (for example ISO UTC) to the item’s metadata, and optionally forwarding the augmented item to persistent storage or your observability pipeline. Example (Python):
Copy code
from datetime import datetime
from livekit.agents import ChatItem

@session.on("conversation_item_added")
def handle_convo_item(item: ChatItem):
    if not hasattr(item, "metadata") or item.metadata is None:
        item.metadata = {}
    item.metadata["timestamp"] = datetime.utcnow().isoformat()
    # optional: send item to your backend/logging here
Notes and alternatives: • For richer time data (e.g., per-transcript chunk), also listen to
user_input_transcribed
and add timestamps there. • If you already use Agent Observability in the Cloud Dashboard, it provides synchronized playback with timestamps for transcripts and actions, which may remove the need to add timestamps manually. Would you like a JavaScript/TypeScript example or instructions for storing these augmented events in a database or log pipeline? Sources: How to capture real-time agent transcriptions during conversations | Testing and evaluation | LiveKit docs | Transcriber | LiveKit docs | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal|