# sagar-tamang/friday-tony-stark-demo architecture

> Architecture diagram of the GitHub repository sagar-tamang/friday-tony-stark-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagar-tamang/friday-tony-stark-demo
- Repository: https://github.com/sagar-tamang/friday-tony-stark-demo

## Overview

1. **The repository is split into two cooperating runtimes**
   - **MCP server**: launched with `uv run friday`, backed by `server.py` and the `friday/` package.
   - **Voice agent**: launched with `uv run friday_voice`, backed by `agent_friday.py`.
   - The architecture is intentionally bifurcated: one process provides tools and resources, the other handles real-time speech interaction and delegates tool calls over the network.

2. **The MCP server is the “tool backend”**
   - It exposes capabilities over **MCP via FastMCP** and serves them over **SSE** on `http://127.0.0.1:8000/sse`.
   - This is the boundary where the LLM-facing assistant can ask for external information or utility functions without embedding those concerns into the voice pipeline itself.

3. **Tooling is organized by domain inside `friday/tools/`**
   - `web.py` contains internet-facing tools such as search/news/web fetch style capabilities.
   - `system.py` contains local/environment utilities such as current time and system information.
   - `utils.py` contains generic helper tools like formatting/counting logic.
   - Each module is expected to register its tools against the MCP server, and `friday/tools/__init__.py` acts as the aggregation point.

4. **The server also exposes prompts and resources, not just tools**
   - `friday/prompts/templates.py` holds reusable prompt templates for MCP clients.
   - `friday/resources/data.py` exposes structured resources such as a `friday://info`-style knowledge resource.
   - This means the server is more than an RPC tool host: it is also a content/prompt provider for downstream clients.

5. **The voice agent is a real-time speech pipeline**
   - `agent_friday.py` builds the LiveKit-based assistant loop: microphone input → STT → LLM reasoning → TTS output.
   - It runs as a LiveKit agent in dev mode and joins a room, so the “speaker/output” side is mediated through LiveKit rather than being a local CLI app.

6. **The speech pipeline is provider-swappable**
   - STT defaults to **Sarvam Saaras v3**.
   - LLM defaults to **Google Gemini 2.5 Flash**.
   - TTS defaults to **OpenAI TTS** (`nova` voice).
   - The README indicates alternative providers are supported for some stages, so the agent is designed with clear model-provider boundaries rather than hard-coding one vendor end-to-end.

7. **Tool calls are remote and live, not bundled**
   - The voice agent connects to the MCP server at runtime and pulls tools “in real time.”
   - This creates a clean separation: speech/LLM orchestration remains in the agent, while all operational capabilities live in the MCP server process.
   - The practical effect is that tool changes can ship independently of the voice pipeline.

8. **Configuration is centralized in environment variables**
   - `friday/config.py` is the server-side settings layer.
   - `.env.example` shows the main operational dependencies: LiveKit credentials, STT/LLM/TTS provider keys, and optional integrations like Groq, Google credentials, Deepgram, and Supabase.
   - The architecture assumes secrets and provider selection are externalized rather than compiled into code.

9. **External services are core architectural dependencies**
   - **LiveKit**: room/session transport for the voice agent.
   - **Sarvam / Google / OpenAI / Groq**: speech and model providers depending on configuration.
   - **Supabase**: optional backing service for a ticketing-related tool path.
   - These services materially shape the system: the repo is not self-contained; it orchestrates multiple cloud APIs.

10. **The data flow is asymmetric**
   - Incoming audio goes only through the voice agent.
   - LLM decisions may trigger MCP tool calls over SSE.
   - Tool responses flow back into the agent’s reasoning loop, then synthesized speech returns to the user through LiveKit/TTS.
   - This makes the MCP server a side-channel capability provider rather than part of the audio stream.

11. **The main architectural boundary is process and transport**
   - The server/agent split is not just code organization; it is a runtime boundary.
   - Communication between the two is networked (SSE/MCP), while the agent’s user interaction is streamed through LiveKit.
   - That separation is the key diagram element: audio/session path on one side, tool/backend path on the other.

12. **The repo is built for extensibility through modules**
   - New server capabilities are added by creating a tool module under `friday/tools/` and registering it.
   - New reusable prompt or resource material is added under `friday/prompts/` or `friday/resources/`.
   - So the MCP server behaves like a plugin host for assistant capabilities, while the voice agent stays comparatively stable.

13. **Operationally, both processes must run together**
   - The README makes this explicit: start the MCP server first, then start the voice agent.
   - For an architecture diagram, this is best represented as two independently deployed local processes or containers with a live dependency from agent → server.

Main entry points: [`friday/tools/__init__.py`](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/__init__.py) (Tool registry), [`server.py`](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/server.py) (Server entry), [`friday/config.py`](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/config.py) (Config), [`agent_friday.py`](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/agent_friday.py) (Voice entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime_server["MCP Server"]
  node_server_entry["Server entry<br/>process<br/>[server.py]"]
  node_mcp_core["FastMCP<br/>mcp host"]
  node_server_config["Config<br/>settings<br/>[config.py]"]
  node_tool_registry["Tool registry<br/>package index<br/>[__init__.py]"]
  node_web_tools["Web tools<br/>tool module<br/>[web.py]"]
  node_system_tools["System tools<br/>tool module<br/>[system.py]"]
  node_util_tools["Utility tools<br/>tool module<br/>[utils.py]"]
  node_prompt_templates["Prompt templates<br/>prompt pack<br/>[templates.py]"]
  node_resource_data[("Knowledge resource<br/>resource pack<br/>[data.py]")]
end

subgraph group_runtime_voice["Voice Agent"]
  node_agent_entry["Voice entry<br/>process<br/>[agent_friday.py]"]
  node_livekit_loop["LiveKit loop<br/>agent runtime"]
  node_audio_ingest(("Audio input<br/>stream stage"))
  node_stt_stage{{"Speech-to-text<br/>model stage"}}
  node_llm_reasoning{{"LLM reasoning<br/>model stage"}}
  node_tts_stage{{"Speech synthesis<br/>model stage"}}
  node_mcp_client["MCP client<br/>tool client"]
end

subgraph group_external["External Services"]
  node_livekit_service[("LiveKit<br/>external platform")]
  node_model_providers[("Model APIs<br/>external providers")]
  node_supabase[("Supabase<br/>external service")]
end

node_server_entry -->|"starts"| node_mcp_core
node_mcp_core -->|"loads"| node_tool_registry
node_mcp_core -->|"serves"| node_prompt_templates
node_mcp_core -->|"serves"| node_resource_data
node_tool_registry -->|"includes"| node_web_tools
node_tool_registry -->|"includes"| node_system_tools
node_tool_registry -->|"includes"| node_util_tools
node_server_config -->|"configures"| node_mcp_core
node_agent_entry -->|"starts"| node_livekit_loop
node_livekit_loop -->|"receives"| node_audio_ingest
node_audio_ingest -->|"transcribes"| node_stt_stage
node_stt_stage -->|"feeds"| node_llm_reasoning
node_llm_reasoning -->|"speaks"| node_tts_stage
node_livekit_loop -->|"joins"| node_livekit_service
node_stt_stage -->|"uses"| node_model_providers
node_llm_reasoning -->|"uses"| node_model_providers
node_tts_stage -->|"uses"| node_model_providers
node_llm_reasoning -->|"calls tools"| node_mcp_client
node_mcp_client -->|"SSE/MCP"| node_mcp_core
node_mcp_client -->|"discovers"| node_tool_registry
node_mcp_core -.->|"optional backend"| node_supabase

click node_server_entry "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/server.py"
click node_server_config "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/config.py"
click node_tool_registry "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/__init__.py"
click node_web_tools "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/web.py"
click node_system_tools "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/system.py"
click node_util_tools "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/utils.py"
click node_prompt_templates "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/prompts/templates.py"
click node_resource_data "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/resources/data.py"
click node_agent_entry "https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/agent_friday.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server_entry,node_mcp_core,node_server_config,node_tool_registry,node_web_tools,node_system_tools,node_util_tools,node_prompt_templates,node_resource_data toneBlue
class node_agent_entry,node_livekit_loop,node_audio_ingest,node_stt_stage,node_llm_reasoning,node_tts_stage,node_mcp_client toneAmber
class node_livekit_service,node_model_providers,node_supabase toneMint
```

## Components

### MCP Server

Tool backend exposed over MCP/SSE

- [Server entry](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/server.py): process · Launches the MCP server process · `server.py`
- **FastMCP**: mcp host · Registers and serves tools, prompts, and resources
- [Config](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/config.py): settings · Server-side environment and provider settings · `friday/config.py`
- [Tool registry](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/__init__.py): package index · Aggregates server tools for registration · `friday/tools/__init__.py`
- [Web tools](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/web.py): tool module · Internet-facing search and fetch capabilities · `friday/tools/web.py`
- [System tools](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/system.py): tool module · Local time and system/environment utilities · `friday/tools/system.py`
- [Utility tools](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/tools/utils.py): tool module · Generic helper tools such as formatting and counting · `friday/tools/utils.py`
- [Prompt templates](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/prompts/templates.py): prompt pack · Reusable MCP prompt templates · `friday/prompts/templates.py`
- [Knowledge resource](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/friday/resources/data.py): resource pack · Structured MCP resources like friday://info · `friday/resources/data.py`

### Voice Agent

Real-time speech runtime

- [Voice entry](https://github.com/sagar-tamang/friday-tony-stark-demo/blob/main/agent_friday.py): process · Launches the LiveKit voice agent · `agent_friday.py`
- **LiveKit loop**: agent runtime · Joins a room and manages the live session
- **Audio input**: stream stage · Receives microphone audio from the room
- **Speech-to-text**: model stage · Converts incoming audio to text
- **LLM reasoning**: model stage · Chooses responses and decides when to call tools
- **Speech synthesis**: model stage · Synthesizes spoken output
- **MCP client**: tool client · Fetches server tools at runtime over SSE

### External Services

Provider and transport dependencies

- **LiveKit**: external platform · Session and audio transport
- **Model APIs**: external providers · Sarvam, Google, OpenAI, and optional Groq/Deepgram
- **Supabase**: external service · Optional backend for ticketing-related functionality

## Connections

- Server entry → FastMCP: starts · Boots the MCP server process
- FastMCP → Tool registry: loads · Registers all tool modules
- FastMCP → Prompt templates: serves · Exposes reusable prompts to MCP clients
- FastMCP → Knowledge resource: serves · Exposes structured resources
- Tool registry → Web tools: includes · Aggregates web-facing tools
- Tool registry → System tools: includes · Aggregates system utilities
- Tool registry → Utility tools: includes · Aggregates helper utilities
- Config → FastMCP: configures · Provides server settings and endpoints
- Voice entry → LiveKit loop: starts · Boots the LiveKit agent runtime
- LiveKit loop → Audio input: receives · Consumes microphone audio from the session
- Audio input → Speech-to-text: transcribes · Audio is converted to text
- Speech-to-text → LLM reasoning: feeds · Transcribed text enters the reasoning loop
- LLM reasoning → Speech synthesis: speaks · Generated response is synthesized
- LiveKit loop → LiveKit: joins · Connects the agent to a room/session
- Speech-to-text → Model APIs: uses · Speech model provider selection is externalized
- LLM reasoning → Model APIs: uses · LLM provider selection is externalized
- Speech synthesis → Model APIs: uses · TTS provider selection is externalized
- LLM reasoning → MCP client: calls tools · Requests external capabilities when needed
- MCP client → FastMCP: SSE/MCP · Runtime network connection to the tool backend
- MCP client → Tool registry: discovers · Accesses registered tool surface
- FastMCP → Supabase: optional backend · Supports ticket-related tool paths when enabled
