How atharva-ankad/voice_ai_agent works
1. Project shape
This is a small, single-process Python application with a browser UI. The runtime entry point is app.py, and the main behavior is split into three modules under modules/: audio transcription, intent classification, and tool execution.
2. Top-level orchestration
app.py acts as the controller for the whole pipeline. It receives audio from the Streamlit UI, passes it through transcription, sends the transcript to intent detection, then dispatches the result to the appropriate tool and displays all intermediate/final outputs in the page.
3. User interface boundary
The UI is Streamlit-based and is the only interactive surface. It supports two input paths: microphone capture and audio file upload. This means the app is not a network service or multi-user backend; it is a local desktop-style browser app.
4. Audio ingestion and transcription
modules/audio.py is responsible for converting raw audio into text using Faster-Whisper. The README indicates the Whisper base model runs locally, typically CPU-only with int8 quantization, so transcription is a local compute stage rather than an API call.
5. Intent detection layer
modules/intent.py classifies the transcript into one of four intents: create_file, write_code, summarize_text, or general_chat. It uses LangChain with a locally hosted Phi-3 model through Ollama, and the architecture depends on a strict prompt plus a fallback regex cleanup to normalize model output.
6. Tool execution boundary
modules/tools.py is the action layer. It maps the detected intent to concrete behavior: create an empty file, generate/write code, summarize text, or produce a general chat response. This module is the main place where intent becomes side effect or output.
7. Sandboxed file system behavior
All file-producing actions are constrained to the output/ directory at the repository root. That directory is the project’s only persistent artifact store, and the design explicitly rejects path traversal attempts, which makes the file boundary a key security constraint in the architecture.
8. Code-generation data flow
For write_code, the tool layer can read the tail of an existing file before appending new content. That creates a narrow context-preservation flow: existing output file → truncated context → Phi-3 generation → append/write back into output/.
9. Local model/runtime dependencies
The architecture depends on two local model runtimes: Faster-Whisper for speech-to-text and Ollama for Phi-3 inference. No cloud APIs are involved, so the deployment model is “local app + local model servers/libraries,” with model weights downloaded on first run.
10. State and persistence model
There is essentially no application database and no conversation memory. The only durable state is whatever gets written into output/. Everything else is transient per command: audio input, transcript, detected intent, and generated response.
11. Operational flow
A typical run is: user records or uploads audio → Streamlit hands audio to app.py → transcription produces text → intent classification selects a route → tool execution runs → UI shows transcript, intent, action, and final output. That sequential pipeline is the main architecture to diagram.
12. Repo-level structure
The repository is intentionally compact: app.py for orchestration, modules/ for logic, assets/ for documentation imagery, and output/ for generated artifacts. This suggests a tightly coupled but clearly layered prototype where most boundaries are functional rather than service-based.
Main entry points: app.py app.py · tools.py Tool router · audio.py Audio transcribe · intent.py Intent classify
Components 13
App runtime
Streamlit UI and orchestration pipeline
- Streamlit UI · Local interactive surface for microphone and file upload input
- app.py · Main controller that coordinates transcription, intent detection, tool execution, and display
app.py - Audio transcribe · Converts uploaded or recorded audio into text
modules/audio.py - Intent classify · Maps transcript to create_file, write_code, summarize_text, or general_chat
modules/intent.py - Tool router · Dispatches detected intent to concrete actions
modules/tools.py
Local models
Speech and intent inference run locally
- Whisper base · Local Faster-Whisper model used for speech-to-text
- Prompt chain · Strict intent prompt and output normalization logic
- Phi-3 · Locally hosted model served through Ollama for intent and generation
Tool actions
Intent routes that produce outputs or files
- Create file · Creates an empty file in the output sandbox
- Write code · Generates or appends code using existing file tail as context
- Summarize text · Produces a summary response from supplied text
- General chat · Produces a free-form conversational response
Persistent storage
Only durable repository state
- output/ · Only persistent artifact store for generated files
output
Connections 21
- Streamlit UI → app.py: input events · Microphone capture or audio upload is handed to the controller
- app.py → Audio transcribe: transcribe · App sends raw audio for speech-to-text
- Audio transcribe → Whisper base: run model · Faster-Whisper performs local transcription
- Whisper base → Audio transcribe: text · Transcript returns to the audio module
- Audio transcribe → app.py: transcript · Transcript is returned for downstream routing
- app.py → Intent classify: classify · Transcript is sent for intent detection
- Intent classify → Prompt chain: prompting · Intent module applies the strict prompt and cleanup rules
- Prompt chain → Phi-3: infer · Ollama hosts Phi-3 for intent inference
- Phi-3 → Intent classify: labels · Model output is normalized into one of the supported intents
- Intent classify → app.py: intent · Detected intent is returned to the controller
- app.py → Tool router: dispatch · App forwards transcript and intent to the action layer
- Tool router → Create file: route · create_file intent triggers empty-file creation
- Tool router → Write code: route · write_code intent triggers code generation or append
- Tool router → Summarize text: route · summarize_text intent triggers summarization
- Tool router → General chat: route · general_chat intent triggers conversational response
- Create file → output/: write file · New file is created inside the sandboxed output directory
- Write code → output/: append · Generated code is written back into output/
- Summarize text → app.py: result · Summary is returned for UI display
- General chat → app.py: result · Chat response is returned for UI display
- output/ → Write code: read tail · Existing file tail can be read as context before appending
- app.py → Streamlit UI: render · Transcript, intent, action, and final output are shown to the user