LiveKit keeps all conversation history permanently...
# ask-ai
c
LiveKit keeps all conversation history permanently. Over a 37-question survey, old function outputs (question text + choices + instructions) accumulate ~50-60KB of dead weight the LLM never re-reads. This causes: - 5x TTFT degradation (0.5s at Q1 → 2.8s at Q37) - ~$3.49 LLM cost per call (input tokens grow linearly) - Behavioral errors from accumulated context bias Old FunctionCall items are replaced with a one-line summary Old FunctionCallOutput items are stripped entirely (the heavy payload). The most recent pair (current question) is kept intact. All user/assistant messages are preserved — they carry important behavioral signals. Is there a built in way in Livekit to achieve this?
t
Thanks for reaching out, Yousri. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I hear you: you want a way to automatically compress/summarize old function-call history (keep recent pair intact, replace older FunctionCall with one-line summaries and drop heavy FunctionCallOutput payloads) to reduce tokens, latency, and cost. Short answer: LiveKit does not have a built‑in automatic feature that compresses or summarizes conversation history for you. What you can do instead • Implement client/server-side pruning and summarization before you build the prompt: ◦ Keep all user/assistant messages intact (as you said). ◦ Replace older
FunctionCall
events with a one-line summary (who/what/intent/time). ◦ Strip out old
FunctionCallOutput
payloads entirely, or store them externally and reference them by ID. ◦ Always keep the current question’s FunctionCall/Output pair intact. • Use a ConversationManager helper pattern (or similar middleware) to manage what gets sent to the LLM: ◦ Maintain the full history in
session.history
(or your own store). ◦ When preparing
chat_ctx
for the LLM, build a reduced context that includes: ▪︎ Recent messages (last N turns). ▪︎ System message summarizing earlier turns (one-line or short bullet list). ▪︎ Summaries for old FunctionCalls in place of full events. ◦ Optionally include pointers/IDs to the stripped outputs in case you need to rehydrate them later. Practical tips to implement 1. Decide retention rules: ◦ e.g., keep last 3 Q/A turns fully, summarize anything older than that. 1. Create concise summary format: ◦ For FunctionCall: "Q5: validated_user_email -> validated (params: {email_masked})" ◦ For FunctionOutput removed: "Output for Q3 stored at output_id:12345" 1. Store full outputs in external storage (DB or object store) and reference by ID to avoid token costs. 2. Run periodic summarization: ◦ After every X questions, append a short summary system message (1–2 lines) representing the combined earlier context. 1. Measure and iterate: ◦ Track tokens, TTFT, and LLM cost to tune retention/summarization thresholds. If helpful, I can: • Sketch a small pseudocode flow for a ConversationManager that filters/summarizes history before calling the LLM. • Suggest concrete summary templates for your FunctionCall and FunctionCallOutput items. • Recommend thresholds (how many turns to keep vs summarize) based on your 37-question workflow. Which would you prefer next: a pseudocode flow you can drop into your agent, or a few concrete summary templates to use right away? Sources: Building multi-agent architectures with LiveKit agents | LiveKit