Skip to main content

Separated user/AI conversation cache for streaming voice models. Gives your voice AI memory without role confusion.

Project description

tibet-voice-cache

Conversation memory for streaming voice AI. Give your voice model persistent context without role confusion.

pip install tibet-voice-cache

What it does

Streaming voice models (Gemini Live, OpenAI Realtime) lose context between sessions. When you inject raw conversation history as user/model turns, the model replays old responses, talks to itself, or confuses who said what.

tibet-voice-cache stores user and AI utterances separately and builds clean context summaries for your system instruction — no fake turns, no role confusion.

Android ──audio──► your proxy ──audio──► Gemini Flash Live
                       │                       │
                  input_transcript         output_transcript
                       │                       │
                       ▼                       ▼
                  user_said[]              ai_said[]
                       │                       │
                       └──── system instruction injection ────┘
                                    │
                           "Earlier discussed:
                            User asked about X
                            You answered Y"

Quick start

from tibet_voice_cache import VoiceCache

# Create a cache (in-memory or persistent)
cache = VoiceCache(actor="user_123", storage_dir="./cache")

# During your voice session, record what's said
cache.add_user("What's the weather like?")
cache.add_ai("It's sunny and 22 degrees!")
cache.complete_turn()

# Next session: inject context into system instruction
system_prompt = cache.inject_into_system_instruction(
    "You are a helpful voice assistant."
)
# Result:
# "You are a helpful voice assistant.
#
#  === PRIOR CONTEXT ===
#  The user previously said:
#    - What's the weather like?
#  You previously responded:
#    - It's sunny and 22 degrees!
#  === END CONTEXT ===
#  Do NOT respond to the above context unless the user refers to it."

Gemini Flash Live adapter

Drop-in integration for Google's Gemini Live API:

from tibet_voice_cache import VoiceCache
from tibet_voice_cache.adapters.gemini_live import GeminiLiveAdapter
from google import genai

cache = VoiceCache(actor="user_123", storage_dir="./cache")
adapter = GeminiLiveAdapter(cache)

# Build config with context already injected
config = adapter.build_config(
    base_instruction="You are OomLlama, a friendly Dutch AI assistant.",
    voice="Kore",
)

client = genai.Client(api_key=API_KEY)
async with client.aio.live.connect(model="gemini-3.1-flash-live-preview", config=config) as session:
    # In your relay loop, hook into transcription events:
    async for msg in session.receive():
        if msg.server_content:
            if msg.server_content.input_transcription:
                adapter.on_input_transcript(msg.server_content.input_transcription.text)
            if msg.server_content.output_transcription:
                adapter.on_output_transcript(msg.server_content.output_transcription.text)
            if msg.server_content.turn_complete:
                adapter.on_turn_complete()

    # Session ends — persist cache for next time
    adapter.on_session_end()

Summary styles

Choose how context is formatted for your model:

from tibet_voice_cache import VoiceCache, SummaryStyle

# Labeled (default) — clear sections
cache = VoiceCache(actor="user", summary_style=SummaryStyle.LABELED)

# Compact — minimal tokens
cache = VoiceCache(actor="user", summary_style=SummaryStyle.COMPACT)
# → [Context] User: weather question. You: sunny, 22 degrees.

# Narrative — natural language
cache = VoiceCache(actor="user", summary_style=SummaryStyle.NARRATIVE)
# → Earlier in the conversation:
#   - The user said: "What's the weather like?"
#   - You replied: "It's sunny and 22 degrees!"

# Chronological — ordered pairs
cache = VoiceCache(actor="user", summary_style=SummaryStyle.CHRONOLOGICAL)
# → Previously discussed:
#     1. User: What's the weather? -> You: Sunny, 22 degrees

Multi-language labels

Built-in English and Dutch, or bring your own:

# Dutch labels
cache = VoiceCache(actor="user", summary_style=SummaryStyle.LABELED)
cache.summary_builder.labels = SummaryBuilder.LABELS["nl"]

# Custom labels
cache.summary_builder.labels = {
    "header": "--- KONTEXT ---",
    "footer": "--- ENDE ---",
    "user_label": "Benutzer sagte:",
    "ai_label": "Du antwortetest:",
    "no_replay": "Reagiere nicht auf obigen Kontext.",
    ...
}

Bulk session import

Save all transcripts at once when a session ends:

cache.add_session_transcripts(
    user_texts=["Hello", "How are you?", "Tell me a joke"],
    ai_texts=["Hi there!", "I'm great!", "Why did the chicken..."],
)

Migrate from mixed history

Coming from a [{"role": "user", "content": "..."}, {"role": "assistant", ...}] format?

legacy_history = [
    {"role": "user", "content": "Hello"},
    {"role": "assistant", "content": "Hi!"},
]
cache = VoiceCache.from_mixed_history(legacy_history, actor="migrated")

Persistence

Cache is stored as JSON per actor. Works with any filesystem:

# Local storage
cache = VoiceCache(actor="user_123", storage_dir="./cache")

# Shared storage (NFS, S3 mount, etc.)
cache = VoiceCache(actor="user_123", storage_dir="/mnt/shared/voice-cache")

# In-memory only (no persistence)
cache = VoiceCache(actor="user_123")

File format:

{
  "actor": "user_123",
  "user_said": [
    {"text": "Hello", "timestamp": 1712234567.89, "turn_id": 0}
  ],
  "ai_said": [
    {"text": "Hi there!", "timestamp": 1712234568.12, "turn_id": 0}
  ],
  "turn_counter": 1,
  "updated": "2026-04-04T10:30:00+00:00"
}

Why not Google's Context Cache API?

Google's context caching is designed for REST API calls — cache large documents, save tokens. For the Live API (streaming audio), their approach is send_client_content with raw turns — which causes the exact role confusion this package solves.

Google's own docs recommend: "For longer contexts, provide a single message summary." That's exactly what tibet-voice-cache does, automatically.

Part of the TIBET ecosystem

tibet-voice-cache is part of TIBET — Traceable Intent-Based Event Tokens. Built by the HumoticaOS family.

Package Description
tibet-voice-cache This package — voice conversation memory
tibet-voice-cache-mcp MCP server wrapper (coming soon)

License

MIT — use it, fork it, give your voice AI a memory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tibet_voice_cache-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tibet_voice_cache-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file tibet_voice_cache-0.1.0.tar.gz.

File metadata

  • Download URL: tibet_voice_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tibet_voice_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d134498234167e4d69a3358b67ff89a79a96f83d629d5fb0e8f7ad868e47433
MD5 f9889811960ea14146a98aeee1ac8888
BLAKE2b-256 14e7bf2f044276f5a11f814c613ac3217efef85a570fa91af0f09a03379b80ca

See more details on using hashes here.

File details

Details for the file tibet_voice_cache-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tibet_voice_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94ada32ab8ce3d1b99f41049b2995c23a8d8511d494ed1f2db017ed84175a6c9
MD5 4e3d5819b81490d8ba417e61c07909fb
BLAKE2b-256 b030e2fb62f252bcc9f5a3f6c317f1f8f38fb30e973187342330a87dad8faf30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page