Quest and QuestManager
Async task lifecycle management for services with init/run/close phases.Class: Quest[T]
Represents an async unit of work with initialization, execution, and cleanup phases.Methods
method
Wait for initialization to complete and return the initialized resource.
method
Get the initialized resource immediately, or None if not ready.
method
Cancel the quest and run cleanup.
Class: QuestManager
Manages multiple quests and ensures proper cleanup.Timing Utilities
Class: Stopwatch
Simple timer for measuring elapsed time.Properties and Methods
property
Whether the stopwatch has been started.
method
Get elapsed time in seconds. Returns 0.0 if not started.
method
Stop the timer and return elapsed time, or None if already stopped.
Class: PhasesStopwatch
Track timing for multiple sequential phases.Queue Utilities
Class: RealtimeQueue[T]
Priority queue that releases items based on timestamps for real-time processing.Service Discovery
Functions for finding and connecting to backend services with failover support.get_instances
function
Get all available instances of a service.Parameters:
service_name(str) - Service name (e.g., “stt”, “tts”, “llm”)
find_instance
function
Find a working instance of a service by trying connections.Parameters:
service_name(str) - Service nameclient_factory(Callable) - Function to create client from URLtimeout_sec(float) - Connection timeout per attempt (default: 0.5)max_trials(int) - Maximum connection attempts (default: 3)
MissingServiceAtCapacity- All instances are at capacityMissingServiceTimeout- Connection attempts timed out
async_ttl_cached
function
Decorator to cache async function results with TTL.Parameters:
func(Callable) - Async function to cachettl_sec(float) - Cache TTL in seconds (default: 0.1)
Caching
get_cache
Get a cache instance (local or Redis-backed).- If
KYUTAI_REDIS_URLis set, usesRedisCachefor distributed caching - Otherwise uses
LocalCachefor single-instance in-memory caching
Recording
Class: Recorder
Records WebSocket session events to disk for replay and analysis."client" or "server"
Recordings are saved as JSON files in the specified directory, one file per session.
Audio Processing
ExponentialMovingAverage
Smooth signal processing with configurable attack and release times.WebSocket Utilities
URL Conversion
Convert between HTTP and WebSocket URLs.Usage Example
Related
- UnmuteHandler - Uses Quest and timing utilities
- Architecture Components - Service lifecycle overview
- Monitoring - Metrics and observability