--- title: Customer EMAIL Agent emoji: 📧 colorFrom: blue colorTo: indigo sdk: docker pinned: false --- # 📧 Customer Support Email Agent An AI-powered customer support email agent built with **LangGraph**, **LangChain**, and **FastAPI**. The agent automatically classifies incoming support emails, retrieves relevant knowledge, drafts responses, and optionally escalates complex issues — all orchestrated as a stateful LangGraph workflow. ## Architecture ``` Incoming Email │ ▼ ┌─────────────┐ │ Classifier │ ← Categorizes intent (billing, technical, general, etc.) └──────┬──────┘ │ ▼ ┌─────────────┐ │ Retriever │ ← Fetches relevant knowledge base articles └──────┬──────┘ │ ▼ ┌─────────────┐ │ Responder │ ← Drafts a reply using context + LLM └──────┬──────┘ │ ▼ ┌─────────────┐ │ Escalation │ ← Routes to human agent if confidence is low └─────────────┘ ``` ## Project Structure ``` cust_support_system/ ├── src/ │ ├── main.py # FastAPI application entry point │ ├── api/ # API routes & dependencies │ ├── core/ # Config, logging, constants │ ├── graph/ # LangGraph workflow definition │ ├── nodes/ # Individual graph nodes │ ├── schemas/ # Pydantic models │ ├── services/ # Email & LLM services │ ├── prompts/ # Prompt templates │ └── utils/ # Helper utilities ├── knowledge_base/ # Support articles & FAQ docs ├── tests/ # Pytest test suite ├── requirements.txt ├── .env.example # Credential-free configuration template └── README.md ``` ## Setup ```bash # 1. Create & activate a virtual environment (Python 3.12) python3.12 -m venv venv source venv/bin/activate # 2. Install dependencies pip install -r requirements.txt # 3. Configure environment variables cp .env.example .env # then fill in your keys # 4. Run the server uvicorn src.main:app --reload ``` ### OpenAI inference configuration Chat and knowledge-base embeddings use the backend-only `OPENAI_API_KEY`: ```dotenv OPENAI_API_KEY=your-openai-api-key LLM_BASE_URL=https://api.openai.com/v1 LLM_MODEL=gpt-6-luna EMBEDDING_MODEL=text-embedding-3-small ``` The chat model ID `gpt-6-luna` is passed through exactly as configured. Its availability and API compatibility have not been verified; it must be accessible on your OpenAI account. The application no longer uses `GITHUB_TOKEN` for inference. Do not use a GitHub token as an OpenAI key or expose provider keys in frontend `VITE_*` variables. For an existing installation, update the provider entries in `.env` rather than replacing the file and losing unrelated credentials. Environment variables take precedence over `.env`, which takes precedence over the code defaults. On your backend host (for example, Hugging Face Spaces), set `OPENAI_API_KEY` as a secret and update or remove stale `LLM_BASE_URL`, `LLM_MODEL`, and `EMBEDDING_MODEL` overrides. Restart the backend after configuration changes. `/config` reports the effective chat model; it does not modify inference settings. Embeddings remain on the `text-embedding-3-small` model family with default dimensions. The migration does not rebuild the FAISS index. If the old index used a different embedding model or dimensions, rebuild it explicitly with `python -m src.services.kb_service` after setting a valid key; that command makes billable embedding requests. ### Backend API authentication Set `API_TOKEN` in the backend environment to a long random value. Production startup fails when `APP_ENV=production` and the token is missing. For local development, the frontend sends the same value from `frontend/.env` as `VITE_API_TOKEN`; this value is visible to browser users and should not be treated as a production-grade user authentication secret. ## Tech Stack | Layer | Technology | | ------------- | --------------------- | | LLM | OpenAI (`gpt-6-luna`) | | Orchestration | LangGraph + LangChain | | API | FastAPI | | Validation | Pydantic v2 | | Language | Python 3.12 |