Spaces:
Sleeping
Sleeping
Architecture β Personal AI Digital Twin
System Overview
A FastAPI backend serving a glassmorphic chat UI, backed by a tool-calling AI agent that runs on Groq's inference API. The agent is stateful per session (in-memory), speaks in Arun's voice from injected context files, and pushes live notifications to a Telegram bot for every new session and message.
Components
Entry Point (app.py)
FastAPI application setup. Mounts the static UI at /static, serves index.html at the root, includes the API router, and binds to the PORT environment variable for Render compatibility.
API Router (api.py)
- Single
POST /chatendpoint - Manages per-session conversation history in
SESSIONSdict (keyed bysession_id) - Triggers a Telegram push notification on new session start
- Forwards every user message and AI response to Telegram in real time
- Delegates all AI logic to the
Meagent class
Agent Core (services/me_agent.py β the Me class)
The most important module. Responsibilities:
- Context loading: Reads
me/summary.txtat startup to build Arun's persona context - System prompt assembly: Injects persona context + behavioral rules into every LLM request
- Tool-calling agentic loop: Runs up to 3 iterations per user message β if the model calls a tool, it executes it and feeds results back into the conversation before generating the final response
- Multi-model fallback: Tries 4 Groq models in sequence β any model failure (rate limit, timeout) automatically falls through to the next
- Artifact cleanup: Strips
<function=...>tags that Llama 3 occasionally leaks into output
Tools (services/tools.py)
save_lead: Saves lead contact info locally when the agent detects hiring/collaboration interestsave_unknown_questions: Logs questions the agent couldn't answer for Arun to review laterpush: Sends Telegram notifications via HTTP to Arun's bot
Identity Data (me/summary.txt)
Plain-text file containing Arun's professional background β injected directly into the system prompt on every request. This is the source of truth for the agent's persona.
Data Flow
User message (browser)
β
POST /chat (FastAPI)
β
Session history lookup β append user message
β
Me.chat() β build messages [system prompt + history]
β
Groq LLM call (model fallback chain if rate limited)
β
If tool_calls β execute tools β re-invoke LLM (up to 3x)
β
Final response β push to Telegram β return to browser
Deployment
- Host: Render (free tier)
- Port: Dynamic via
PORTenv var - Config:
.envforGROQ_API_KEYand Telegram bot token