When exactly is the `created_at` timestamp for eac...
# ask-ai
w
When exactly is the
created_at
timestamp for each item in
session.history
is recorded
t
Thanks for reaching out, Steve. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking when the
created_at
timestamp for items in
session.history
is recorded — specifically which moment in the processing pipeline it reflects. The
created_at
timestamp is set when the item is committed to the chat history. That happens after the agent has processed the user's input and the conversation item is finalized (for example, after the STT → LLM → TTS pipeline finishes producing and committing the response). In short:
created_at
reflects the moment the message/event becomes part of the official conversation record. Sources: Events and error handling | LiveKit docs
w
then the created at wouldnt be accurate correct? is there any way i can improve the accuracy?
t
You're right —
created_at
records when an item is committed to history, so it won't always match the exact moment speech began. You can improve timing accuracy by capturing earlier events and/or word-level timings. Options: • Use the
user_input_transcribed
event (it includes
is_final
and the transcript) and record a timestamp when the final or interim transcription arrives. • Enable TTS-aligned or word-timing transcription from your TTS/STT provider (if supported) to get per-word timestamps you can store alongside the item. • Add a timestamp in an
on_user_turn_completed
node (or similar pipeline hook) before LLM processing — commit that timestamp into your own metadata when you later store the history item. Which of these would you like help implementing (provider/STT details, pipeline node example, or sample code to store metadata)? Sources: Events and error handling | LiveKit docs | Text and transcriptions | LiveKit docs | Pipeline nodes and hooks | LiveKit docs
w
if i use the events such as use_input transcribted then should i use session.userdata to store everything??
t
Good question — you can use
session.userdata
, but choose the approach that fits your access patterns and retention needs. Recommendations: • Use
session.userdata
for small, per-session metadata you need accessible across pipeline nodes (e.g., interim timestamps, latest transcript, flags). It's simple and keeps data tied to the session lifecycle. • Don’t store large or high-frequency data solely in
session.userdata
(like every interim word timestamp). Instead, buffer those in-memory during the turn and periodically persist to your own storage or a DB. • For precise timing and searchability, persist final records (transcripts + timestamps + word-level timing) to an external datastore as soon as they’re available, and keep a reference/summary in
session.userdata
(e.g.,
last_transcript_id
,
turn_start_ts
). • When using
user_input_transcribed
, record both interim and final timestamps as needed: store interim only if you need them for real-time UX; always persist the final
is_final
transcript with its timestamp for accuracy. If you want, tell me which SDK or pipeline node you’re using and I’ll give a short code/example for storing timestamps in
session.userdata
and persisting final transcripts.
w
should i use session.userdata or should i use some other variable and store
t
You're on the right track asking this — choice depends on volume, lifetime, and access patterns. Short answer • Use
session.userdata
for small, per-session values you need across pipeline nodes (turn start time, last_final_transcript, flags, ids). • Use an external store (DB, object store) for high-frequency or large data (interim word timestamps, full transcripts history, analytics) and keep only references/summaries in
session.userdata
. Guidelines • Keep
session.userdata
lightweight: single numbers, small objects, or pointers (e.g.,
last_transcript_id
,
turn_start_ts
). • Buffer high-frequency interim events in memory during the turn, then persist final results to your DB when
is_final
arrives. • Persist word-level timings or every interim transcript externally as they arrive if you need precise real-time alignment or audit trails. • Always write the final (committed) transcript + final timestamp immediately to persistent storage and update
session.userdata
with its id/timestamp for quick access. • If multiple workers/processes access the same session, avoid relying on
session.userdata
as the only source of truth for persisted history — use the external DB as canonical storage. If you want, tell me which SDK/language and your persistence choice (Postgres, Dynamo, Mongo, etc.) and I’ll provide a short example pattern (in-memory buffer → persist on final → update
session.userdata
).
w
if i have multiple concurrent sessions runnign which is better?
t
For multiple concurrent sessions, use a hybrid approach: keep
session.userdata
lightweight for per-session state you need instantly across pipeline nodes, and use an external datastore as the canonical source for transcripts, timestamps, and high-frequency data. Why: • session.userdata — fast, simple, good for small items (turn_start_ts, last_transcript_id, flags). Works well when only one worker touches a session and data volume is low. • External store — required when you have many concurrent sessions, need durability, cross-worker access, full transcript history, analytics, or high-frequency word-level timings. Best practices 1. Keep
session.userdata
small (single values or pointers). 2. Buffer interim/high-frequency events in-memory per turn; persist only final results (or important interim events) to your DB. 3. Persist final transcript + timestamps immediately on
is_final
and write its id/timestamp back into
session.userdata
. 4. Use the external DB as the source of truth if multiple workers/processes may access the same session. 5. If you need low-latency shared state across workers, use a fast shared cache (Redis) for short-lived data and the DB for durable storage. 6. Design idempotent writes for concurrency (upserts, optimistic locking, or write-once keys) to avoid dupes when multiple processes report the same turn. 7. Limit session.userdata lifetime to the session; rely on external storage for long-term retention. If you tell me your SDK/language and your preferred datastore (Postgres, DynamoDB, Mongo, Redis), I can provide a short example pattern (in-memory buffer → persist on final → update
session.userdata
).