feat(hf): reuse the prompt KV cache across turns to keep time to first token flat
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- ai, performance
Línea de trabajo
Start by reading the livekit-plugins-hf implementation introduced in #7731 and trace how it encodes ChatContext for each turn. Compare the tokenized prompt prefixes across turns and identify where past_key_values could be retained and invalidated. Done means safely reusing unchanged prefixes, falling back when history changes, and bounding cache memory per session and overall; coordinate this design with #5351.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature Type
Would make my life easier
Feature Description
livekit-plugins-hf (#7731) re-encodes the full prompt on every turn: system prompt, tools and the whole conversation so far. Earlier turns don't change between replies, but their attention keys and values are computed again each time. So time to first token grows with the length of the call.
Measured on Qwen2.5-0.5B-Instruct, Apple M4 (MPS), temperature=0, steady state (second pass, shapes warm):
| conversation | prompt tokens | time to first token |
|---|---|---|
| first turn | 36 | 52 ms |
| after 10 exchanges | 846 | 257 ms |
| after 20 exchanges | 1666 | 494 ms |
| after 40 exchanges | 3306 | 1002 ms |
A 20x slowdown over one call, on the smallest model. Larger models scale it further.
Proposal: keep each session's past_key_values between turns, and on the next turn feed only the tokens after the longest shared prefix.
- Key the cache by session (or by
ChatContextidentity) and evict it when the session ends. - Fall back to a full re-encode when the prefix changes, e.g. history truncation or an edited system prompt.
- Bound the memory per session and in total, since the cache trades memory for latency. This interacts with the KV cache compression proposed in #5351.
Hosted providers already do this: the openai, anthropic and google plugins all expose prompt caching.
Workarounds / Alternatives
- Trim history aggressively, which loses context.
- Use a server with prefix caching (vLLM, SGLang) through the
openaiplugin. That adds a separate service.
Additional Context
- Follow-up to #7731 and related to #5351.
- Prefix reuse pairs with batching (#7764): prefix caching cuts each turn's prefill; batching shares decode across sessions.
- Lenguaje dominante
- Python
- Estrellas
- 14.6k
- Forks
- 3.9k
- Merge medio
- 2 d 23 h
- PR fusionados (30 d)
- 177
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de livekit/agents
-
Assistant markup is stripped from chat history when expressive mode is offPosiblemente ocupada @ShivamSharma43 la tomó hace 6 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hostsQuizá libre de nuevo @AbarnaaSree la tomó hace 46 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
livekit/agents#7022 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Tool argument errors put the argument values in the log message body, outside `lk.pii.*`Posiblemente ocupada @Li-john1021 la tomó hoy. Abierto
Dificultad 3/5 Medio día Aptitud para principiantes 25/100
livekit/agents#7801 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Google Realtime (Vertex AI): update_instructions() appends a model turn instead of replacing the system instructionPosiblemente ocupada @Li-john1021 la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
livekit/agents#7785 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
elevenlabs: text-to-dialogue (v3/v4) alignment timestamps are chunk-relative, breaking synced transcriptsPosiblemente ocupada @satheeshk50 la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
livekit/agents#7773 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de livekit/agents
Issues similares
-
documentation pkg: sphinx-needs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
useblocks/sphinx-needs#2255 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
home-assistant/core#186538 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
btclib-org/btclib-secp256k1#1181 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pyrite-wiki/pyrite#917 ·
Los mantenedores suelen responder en 1 día