Genie
A custom agent runtime built from scratch on a Raspberry Pi — dispatch pipeline, memory system, multi-LLM provider switching, and 19 voice-controlled skills. Built to understand how agents actually work at the implementation level.
- Role
- Architect and sole developer
- Scope
- Runtime engine, skill system, voice pipeline, memory, hardware integration
- Stack
- Python 3.11 · Raspberry Pi 4 · Gemini 2.0 Flash · NVIDIA NIM · Groq · Sarvam AI STT · Deepgram TTS · OpenWakeWord · Google Calendar API · Spotify Web API · APA102 LEDs
- Voice Skills
- 19+
- LLM Slots
- 4
- Current Version
- V2
- Running on Pi
- Live
01Problem / 05
Why it needed building
I kept building with AI APIs without understanding what was actually happening inside the agent loop — how routing decisions were made, how memory was managed, why some patterns failed. The only way to actually learn it was to build the runtime myself.
Using AI APIs to build products taught me the surface. I wanted the internals — how routing decisions are made, when LLMs should and should not be in the critical path, how memory should be structured for voice contexts. The only path was to build the layer I was curious about.
The product move
Framed the build as a learning exercise with a deployable artifact. Every architectural decision was made twice: once to make it work, once to understand why it worked. The JOURNEY.md documents the reasoning.
02What I built / 05
What I built
A complete voice agent runtime running on a Raspberry Pi 4. Built two versions: V1 with keyword routing and laptop audio (proof of concept), V2 with LLM-based skill dispatch, on-Pi voice I/O, 19+ skills, pluggable LLM providers, and per-turn execution traces. V3 is in progress.
Architecture
- 01 / 08Wake word or GPIO button
- 02 / 08Pending state check (multi-turn skills)
- 03 / 08Brain intercept (control commands)
- 04 / 08LLM skill router with LRU cache
- 05 / 08Argument extraction per skill
- 06 / 08Skill execution pipeline
- 07 / 08LLM fallback with memory injection
- 08 / 08Pipelined TTS playback
Dispatch pipeline
Every turn runs the same 4-stage pipeline
LLM is stage 4, not stage 1. Skills route first — LLM is the fallback.
- 01
Wake: Wake Word / Button
"hey_jarvis" via OpenWakeWord or GPIO button on pin 17 triggers the conversation loop.
- 02
Stage 1: Pending State
Skills with multi-turn state get routed back first — WhatsApp 3-step confirm, timer awaiting duration.
- 03
Stage 2: Brain Intercept
"Switch to local model", "list models", "what mode are you in" — handled before any skill.
- 04
Stage 3: Skill Router
Gemini 2.0 Flash receives all 19 skill manifests, returns matched names as JSON. LRU cached. ArgumentExtractor pulls typed args in a separate LLM call.
- 05
Stage 4: LLM Fallback
Full system prompt + 4-turn history + memory block. Reached only when no skill matched.
Four named model slots, nine registered providers, all swappable by voice.
Under the hood
The engineering behind the skills
Each skill has a specific bug, decision, or constraint behind it — not theory, not tutorials.
- 01
Voice AI pipeline
Wake word → VAD recording → STT → skill dispatch → TTS.
- 02
Wake word detection
OpenWakeWord integration, low-latency trigger loop.
- 03
Audio signal processing
scipy polyphase resampling: 48kHz stereo → 16kHz mono.
- 04
Threading and concurrency
Pipelined TTS, barge-in via threading.Event, non-blocking mic.
- 05
Raspberry Pi and GPIO
APA102 LED strip, push button on pin 17, Pi Camera HAT.
- 06
LED color states
The APA102 LED ring shows four states: idle, listening, processing, speaking.
- 07
Embedded system design
Runs fully air-gapped with local models — no cloud required.
- 08
REST API integration
Google Calendar, Spotify Web API, WhatsApp — 19 skills total.
- 09
ToolManifest system
Custom skill schema — JSON-typed args, validation, execution context.
Stack
Grouped by layer
- 01
Hardware
Raspberry Pi 4, Seeed 2-Mic HAT, APA102 LEDs, Pi Camera, GPIO.
- 02
Voice layer
OpenWakeWord, Sarvam STT, Deepgram TTS, sounddevice, pygame, scipy.
- 03
LLM layer
Gemini 2.0 Flash, NVIDIA NIM, Groq, LM Studio.
- 04
Runtime
Python 3.11, ToolManifest, ExecutionContext, Google Calendar API, Spotify API, WhatsApp.
Version history
Where Genie is headed
- 01
V1 Foundation (shipped)
Wire up the hardware and get a keyword-based loop running end to end — prove the runtime could exist on a Pi at all.
- 02
V2 Intelligence (current)
Replace keyword matching with an LLM skill router, add real memory and context, and rebuild the pipeline into modular, swappable stages. Basic voice search, sending messages on my behalf, and daily briefings already run on this — still rough, but working. Wake word reliability was hardened here after the resampling fix.
- 03
V3 Orchestrator (next)
MCP support turns Genie from a runtime with its own tools into one that can drive everything else on the box — the six MCP servers in Arsen's Lab already expose the camera, microphone, shell, browser, database, and Alexa, and V3 is where Genie becomes their client. Plus cron-driven autonomy, vector memory over facts.json, and software AEC to finally close out barge-in.
- 04
V4 Embodiment (future)
Add sensors and mobility so Genie can act in physical space, not just talk in it.
Trade-off
The LLM is the fallback, and barge-in is the honest failure
The LLM sits at stage four of four, not stage one — it is the fallback, not the router. Routing every turn through a model is slow and expensive, so the router caches on (text, model) and most repeated requests never reach it. The honest failure is barge-in: the architecture is correct, but the microphone hears the speaker. That is a physics problem, and V3 fixes it in software with acoustic echo cancellation.
What building this taught me
The lessons that stuck
- 01
Skills-First Dispatch: Put LLM at stage 4, not stage 1.
Most requests hit the cached skill router — the LLM is the exception. Latency and cost drop dramatically when the routing logic is cheap and the expensive call is the fallback, not the default.
- 02
The Resampling Bug: Some bugs are hardware, not code.
OpenWakeWord expects 16kHz mono. PipeWire runs at 48kHz stereo. Detection dropped from 0.33 to 0.025. Fix: scipy polyphase downsample 3:1, take channel 0. It looked like a model failure until it wasn't.
- 03
Barge-In Is Done — Architecturally: Hardware limitations trump clean code.
threading.Event propagates cleanly through TTS, skills, and the LLM layer. But the mic hears the speaker. The architecture is correct. The physics isn't. V3 will fix it in software with acoustic echo cancellation.
- 04
Memory Injection Strategy: Inject on every turn, not selectively.
Sending extra tokens on every turn costs more. Missing context costs more conversations. Always-inject wins in practice until semantic retrieval is reliable enough to replace it.
Source
Full docs and current demos
03Decisions / 05
What I decided, and what it cost
- 01
LLM at stage 4, not stage 1
Routing through the LLM on every turn is expensive and slow. The skill router sends manifests to Gemini Flash and caches the result by (text, model). Most repeated requests never touch the LLM router at all.
- 02
Hard startup failure on invalid manifests
Every skill declares a ToolManifest with name, description, examples, arguments, produces/consumes. Missing or invalid fields fail loudly at boot — not mid-conversation. You find skill bugs before the first turn.
- 03
Pipelined TTS by sentence
Synthesis and playback run concurrently. Sentence N+1 is synthesized while sentence N is playing. No gap between sentences, no waiting for the full response to synthesize before speaking begins.
- 04
Always inject memory, do not retrieve
Short-term (12 turns) and long-term (facts.json keyword match) are injected into every prompt unconditionally. Cheaper to send extra tokens than to miss context. Semantic retrieval is V3.
04Constraints / 05
What I had to work within
- C.01Physical hardware limits what software patterns can do — barge-in works architecturally but fails because the mic hears the speaker.
- C.02Raspberry Pi 4 CPU cannot run large local models — the 4-slot LLM system exists to route appropriately by task.
- C.03Voice context is different from chat — memory injection patterns that work in chat create noise in voice. Short-term window (12 turns) was tuned empirically.
05Outcome / 05
What happened
Genie V2 runs daily. It handles calendar events proactively, sends WhatsApp messages via a 3-stage state machine, streams Spotify, runs web searches, and switches between 9 LLM models by voice. V3 will add vector memory and software AEC.
- 01Built complete dispatch pipeline from scratch — pending state, brain intercept, LLM routing, LLM fallback.
- 02Solved real hardware bug: 48kHz→16kHz scipy resampling fix restored wake word detection from 0.025 to 0.33.
- 03Pluggable LLM provider system — 9 models across 4 named slots, swappable by voice command.
- 04Per-turn ExecutionTrace logs component timing: STT / Router / ArgExtract / Tools / LLM / TTS.