Not every voice command needs an LLM: building a two-tier intent router
Not every voice command needs an LLM: building a two-tier intent router I'm building Liebchen, a voice assistant that runs entirely on my own machine using Ollama and LangGraph. Early on I hit an obvious problem. Saying "lock the computer" shouldn't require a language model to think about it. The p

I'm building Liebchen, a voice assistant that runs entirely on my own machine using Ollama and LangGraph. Early on I hit an obvious problem. Saying "lock the computer" shouldn't require a language model to think about it.
Sending every request to a local LLM is slow and wasteful on a personal machine. A command like "turn the volume up" has exactly one correct action. Asking a model to work that out each time adds delay and a small chance it gets it wrong.
Every request first goes through a router in ai/router.py:
Each pattern is tagged with an intent type: system commands (shutdown, restart, lock, sleep), apps, media (volume, mute, screenshot), info (time, date, battery), search, and stop. A simplified version of the table looks like this:
_INTENT_PATTERNS = [ ( r "<pattern for lock>", lambda m: RouteResult ( IntentType. FAST_SYSTEM, _execute_system ( "lock" ), handled = True ) ), ( r "<pattern for volume up>", lambda m: RouteResult ( IntentType. FAST_MEDIA, _execute_media ( "volume_up" ), handled = True ) ), ( r "<pattern for time>", lambda m: RouteResult ( IntentType. FAST_INFO, _execute_info ( "time" ), handled = True ) ), ] Enter fullscreen mode Exit fullscreen mode The function route(text) walks the table and returns a RouteResult. The handled flag tells the caller whether the fast path did the job or whether to pass the text on to the LLM.
For a small, fixed set of commands, patterns are predictable. The same input always produces the same action, which matters for things like shutdown or lock. There is also nothing to train, and adding a new command is one new line in the table.
The router has a STOP intent. If I say stop while the assistant is mid-answer, it halts and replies that it's listening again. A deterministic fast path is a good place for this, since it doesn't have to wait for the model to finish.
Use the cheapest tool that is reliably correct, and keep the expensive one for what only it can do. Rules handle the commands I can list in advance, and the LLM handles everything else.
Code: github.com/snehalmarteen2005/jarvis-2.0