How allenmylath/rustvani works
1. What this repo is
- rustvani is a Rust voice-agent runtime built around a streaming pipeline: audio in, speech detection, transcription, LLM reasoning, response generation, and audio out.
- The architecture mirrors Pipecat’s frame/processor model, but the implementation is Rust/Tokio-centric and optimized for low-latency, low-memory deployment.
2. The core execution model
- The heart of the system is frames/, pipeline/, and agents/.
- Data moves as typed Frames through a chain of FrameProcessors.
- The pipeline is not just a sequence of calls; it is a runtime with queues, lifecycle events, interruption handling, and task orchestration via PipelineTask.
3. Frame boundaries and flow control
- Frames are the main integration boundary between subsystems.
- They carry system events, control signals, and data payloads such as audio chunks, transcriptions, LLM tokens, tool calls, and playback audio.
- The two-queue design in processors separates lifecycle/system frames from normal data frames so interruptions and shutdowns are not blocked by audio backlog.
4. Transport layer
- transport/ is the external I/O boundary.
- WebSocket transport is the primary runtime path (src/transport/websocket/), implemented with axum and async Rust networking.
- Transport adapters inject inbound audio and protocol messages into the pipeline, and emit outbound audio and signaling frames back to the client.
- The ravi/ module sits alongside transport as a real-time protocol layer for client readiness, speaking state, transcription events, and token streaming.
5. Audio pre-processing and voice activity detection
- vad/ handles speech/no-speech detection and turn-state logic.
- It supports a native Silero VAD path and an ONNX-backed path; both are used as a gate before STT and for interruption/turn control.
- audio_process/ provides noise suppression and resampling so transport audio can be normalized before inference.
- turn/ adds end-of-turn heuristics, which helps decide when user speech is complete and when the assistant can respond.
6. Speech-to-text and text-to-speech services
- services/stt/ contains streaming STT integrations, notably Sarvam’s WebSocket STT.
- services/tts/ contains both remote TTS backends and a local Piper ONNX path.
- This is a clear architectural boundary: remote services handle scalable cloud inference, while local ONNX services keep latency-sensitive deployments self-contained.
7. LLM integration and tool/function calling
- services/llm/ and adapters/ define the LLM provider boundary.
- Provider adapters normalize wire formats for OpenAI-compatible and Sarvam-compatible LLMs.
- FunctionRegistry is the tool execution boundary: the model requests a tool, Rust executes it, and the result is fed back into the LLM context.
- The repository distinguishes between simple tool results and richer data-returning tool calls, which affects both LLM context and downstream UI/logging.
8. Conversation context and aggregation
- context/ holds the shared conversation state: messages, tool definitions, and tool-selection state.
- processors/ contains aggregators that collect streaming user and assistant fragments into coherent conversation turns.
- These aggregators sit between STT/LLM/TTS stages and ensure the context is updated consistently rather than frame-by-frame.
9. Conversation flow engine
- dhara/ is a higher-level orchestration layer for multi-node conversational flows.
- It lets the application move between named nodes, each with its own prompt/tooling/context strategy.
- Tool handlers can either stay in the current node or transition to another node, so flow control is separate from the low-level audio/LLM pipeline.
10. Built-in tools and external data access
- tools/postgres/ implements a managed Postgres tool, including schema caching, query execution, structured filtering, and vector search.
- This is a controlled external-service boundary: the LLM does not directly emit arbitrary SQL; it calls constrained tool interfaces instead.
- The tool lifecycle is explicit, with startup/shutdown/cancel hooks so it can be attached to long-running voice sessions safely.
11. Supporting infrastructure
- observer/, metrics/, and clock/ provide supporting runtime abstractions for timing, observation, and instrumentation.
- utils/ contains text cleanup and sentence splitting used by TTS and conversational buffering.
- src/bin/ shows how the library is deployed in practice: WebSocket servers, voice servers, pipeline tests, and provider demos.
12. How to read the system diagram
- The main end-to-end path is: transport input → VAD/audio cleanup → STT → user aggregation/context → LLM/tool loop → assistant aggregation → TTS → transport output.
- The major architectural seams are transport, audio inference, LLM/provider adapters, tool execution, and conversation-flow management.
- Everything else in the repo supports one of those seams or the lifecycle of a pipeline task.
Main entry points: llm/mod.rs LLM · pipeline.rs Pipeline · axum_websocket_transport.rs WebSocket · vad/mod.rs VAD
Components 22
Core runtime
Frame-based execution and orchestration
- Frames · Core frame types, directions, and processor contracts
src/frames/mod.rs - Queues · Two-queue processor buffering for lifecycle and data frames
src/frames/queue.rs - Processors · Frame processor interface and chaining primitives
src/frames/processor.rs - Pipeline · Pipeline assembly and execution orchestration
src/pipeline/pipeline.rs - Task · Task lifecycle, orchestration, and interruption handling
src/pipeline/task.rs
I/O boundary
Transport, audio, and realtime protocol
- Transport · Inbound and outbound transport abstractions
src/transport/mod.rs - WebSocket · Primary websocket transport implementation
src/transport/websocket/axum_websocket_transport.rs - RAVI · Realtime client signaling for speaking, tokens, and readiness
src/ravi/mod.rs - VAD · Speech detection and turn-state control
src/vad/mod.rs - Audio Proc · Noise suppression and resampling before inference
src/audio_process/mod.rs - Turn Engine · Heuristics for detecting completed user turns
src/turn/mod.rs
Inference services
STT, LLM, and TTS integrations
Conversation flow
Context, aggregation, and higher-level routing
- Context · Shared messages, tools, and selection state
src/context/mod.rs - Aggregators · Collect streaming fragments into conversation turns
src/processors/mod.rs - Dhara · Named conversational nodes and transitions
src/dhara/mod.rs
Tools
External service access and tool execution
- Registry · Function registry and tool-call dispatch boundary
src/services/llm/function_registry.rs - Postgres Tool · Schema caching, query execution, filtering, and vector search
src/tools/postgres/mod.rs
Connections 26
- Transport → WebSocket: websocket impl · Primary network transport runtime
- Transport → RAVI: signals · Realtime protocol messages alongside transport
- WebSocket → VAD: audio in · Inbound audio enters the speech gate
- WebSocket → Audio Proc: normalize · Transport audio is cleaned and resampled
- Audio Proc → VAD: preprocess · Normalized audio feeds speech detection
- VAD → Turn Engine: turn state · Speech/no-speech drives end-of-turn logic
- VAD → STT: speech frames · Detected speech is forwarded to transcription
- STT → Aggregators: transcripts · Streaming transcripts are aggregated into turns
- Aggregators → Context: update · Aggregated user and assistant content updates shared context
- Context → LLM: prompt · Conversation state and tools shape model requests
- LLM → Registry: tool call · Model tool requests are dispatched through the registry
- Registry → Postgres Tool: execute · Registered tools invoke constrained external actions
- Postgres Tool → LLM: result · Tool output returns to model context
- LLM → Aggregators: assistant stream · Assistant tokens are accumulated into a turn
- LLM → TTS: speak · Generated assistant text is synthesized to audio
- TTS → WebSocket: audio out · Synthesized audio is emitted back to the client
- Frames → Processors: contract · Processors consume and emit typed frames
- Processors → Queues: buffering · Lifecycle and data frames are separated in queues
- Pipeline → Task: orchestrate · Pipeline execution is managed by pipeline tasks
- Task → Processors: run · Tasks drive the processor chain
- Pipeline → Transport: connect · Runtime connects I/O boundaries to the frame pipeline
- Dhara → Context: state · Higher-level conversational nodes share context strategy
- Dhara → Registry: tools · Flow nodes can use tool handlers and transitions
- Observer → Pipeline: observe · Execution hooks trace pipeline activity
- Metrics → Pipeline: measure · Instrumentation captures runtime behavior
- Clock → Task: timing · Timing abstraction supports task scheduling and latency