How sgundala/gmail-agent works
Gmail Reply Agent is a web application that signs users in with Google, lets them browse email threads, generates editable replies using persona/rules/past-email memory, sends replies through Gmail, and learns from edits. The graph follows the documented frontend-to-router-to-agent flow and preserves the separate MCP, RAG, and shared-core subsystems. Several backend routers and RAG stages are represented from the README and source index; their internal implementation was not sampled.
Main entry points: client.ts API client · App.tsx Web app routing · agent.py Draft orchestrator · tools.py Agent tools
Components 26
Web application
- Web app routing
frontend/src/App.tsx - Auth state
frontend/src/store/authStore.ts - Inbox page
frontend/src/pages/InboxPage.tsx - Thread and draft page
frontend/src/pages/EmailThreadPage.tsx - Settings page
frontend/src/pages/SettingsPage.tsx - API client
frontend/src/api/client.ts
HTTP and auth
- Authentication routes
backend/app/routers/auth.py - Email routes
backend/app/routers/emails.py - Draft routes
backend/app/routers/drafts.py - Settings routes
backend/app/routers/settings.py - Token and identity
backend/app/core/auth.py
Reply agent
- Draft orchestrator
backend/app/agent/agent.py - Prompt state
backend/app/agent/state.py - Agent tools
backend/app/agent/tools.py - LLM provider chain
backend/app/core/llm.py
RAG memory
- Memory indexing
backend/app/rag/index.py - Memory retrieval
backend/app/rag/retrieve.py - Send and edit learning
backend/app/rag/learn.py
Gmail MCP
- Gmail MCP client
backend/app/mcp/client.py - MCP transport
backend/app/mcp/transport.py - Gmail tool server
backend/app/mcp/server.py - Gmail capability
backend/app/mcp/gmail.py
Other components
- Email user
- Google OAuth
- Supabase and pgvector
- Gmail API
Connections 33
- Email user → Web app routing: uses
- Web app routing → Inbox page: routes to
frontend/src/App.tsx - Web app routing → Thread and draft page: routes to
frontend/src/App.tsx - Web app routing → Settings page: routes to
frontend/src/App.tsx - Web app routing → Auth state: checks session
frontend/src/App.tsx - Auth state → API client: fetches profile
frontend/src/store/authStore.ts - Inbox page → API client: requests email data
frontend/src/pages/InboxPage.tsx - Thread and draft page → API client: requests thread and draft
frontend/src/pages/EmailThreadPage.tsx - Settings page → API client: requests settings
- API client → Authentication routes: calls HTTP API
- API client → Email routes: calls HTTP API
- API client → Draft routes: calls HTTP API
- API client → Settings routes: calls HTTP API
- Email user → Google OAuth: signs in
- Authentication routes → Token and identity: handles OAuth
backend/app/routers/auth.py - Token and identity → Google OAuth: exchanges tokens
backend/app/core/auth.py - Email routes → Gmail MCP client: reads Gmail
backend/app/routers/emails.py - Draft routes → Draft orchestrator: requests draft
- Settings routes → Memory indexing: indexes persona
backend/app/routers/settings.py - Draft orchestrator → Prompt state: builds context
backend/app/agent/agent.py - Draft orchestrator → Agent tools: uses tools
backend/app/agent/agent.py - Draft orchestrator → LLM provider chain: generates reply
backend/app/agent/agent.py - Prompt state → Memory retrieval: loads memory
backend/app/agent/state.py - Agent tools → Gmail MCP client: calls Gmail tools
backend/app/agent/tools.py - Agent tools → Send and edit learning: records learning
backend/app/agent/tools.py - Memory indexing → Supabase and pgvector: writes vectors
- Memory retrieval → Supabase and pgvector: searches memory
backend/app/rag/retrieve.py - Send and edit learning → Memory indexing: indexes updates
backend/app/rag/learn.py - Send and edit learning → LLM provider chain: summarizes edits
backend/app/rag/learn.py - Gmail MCP client → MCP transport: opens session
backend/app/mcp/client.py - MCP transport → Gmail tool server: sends tool calls
- Gmail tool server → Gmail capability: delegates tools
backend/app/mcp/server.py - Gmail capability → Gmail API: reads and sends