This project is an AI-powered customer support resolution system with:
- Email ingestion from company inbox (IMAP)
- LangGraph agent to decide whether an email can be auto-resolved
- Pinecone retrieval from company policies/documents
- Automatic reply to customers for resolvable queries (SMTP)
- Human escalation path for unresolved queries
- Multi-company onboarding with company admin login
- Role-based auth (
company_admin,human_agent) - Postgres storage for unresolved tickets
- Support team web console for login and manual ticket resolution
- Poll unread emails from inbox.
- For each email, run LangGraph workflow:
- Retrieve company-specific policy context from Pinecone namespace.
- Ask LLM if issue can be resolved using policy context.
- If resolvable, send AI reply to customer.
- Else, create unresolved ticket in Postgres for that company.
- Human support agents login and resolve escalated tickets.
- Backend: FastAPI
- Agent orchestration: LangGraph
- LLM: Gemini via
langchain-google-genai - Vector DB: Pinecone
- Relational DB: PostgreSQL
- UI: Static HTML/CSS/JS served by FastAPI
backend/app/main.py: FastAPI entrypointbackend/app/agent/graph.py: LangGraph workflowbackend/app/pinecone_client.py: Pinecone retrieval helperbackend/app/email_client.py: IMAP/SMTP integrationbackend/app/services/email_processor.py: end-to-end email processingbackend/app/routers/*: APIs for auth, ingestion, and ticketsbackend/app/static/*: support team dashboardbackend/scripts/index_policies.py: policy indexing script
Ensure PostgreSQL is installed and running on your machine, and create database customer_care.
Example with psql:
psql -U postgres -c "CREATE DATABASE customer_care;"cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtcopy .env.example .envUpdate .env values:
GEMINI_API_KEYGEMINI_MODELGEMINI_EMBEDDING_MODELPINECONE_API_KEYPINECONE_INDEX_NAMEDATABASE_URLEMAIL_USER,EMAIL_PASSWORDIMAP_HOST,SMTP_HOSTif different from defaultsHUMAN_SUPPORT_EMAIL
Place docs under backend/data (.txt or .md) and run:
python scripts/index_policies.py --docs ./datauvicorn app.main:app --reloadOpen: http://localhost:8000
- Register human agent via
POST /api/auth/register/human-agentusingusername + company_email + password. - Human login via
POST /api/auth/login/humanusingusername + password. - Customer care agents see and resolve unresolved tickets only for their own company.
The built-in web console now supports:
- simple customer care login with username and password
- unresolved ticket listing and resolution
POST /api/auth/register/human-agent- human agent registration (username + company email + password)POST /api/auth/login/human- human agent login (username + password)GET /api/auth/me- get current authenticated user profilePOST /api/ingest/poll- poll current company inbox + process unread emails (auth required)GET /api/tickets- list company unresolved/resolved tickets (auth required)PATCH /api/tickets/{ticket_id}- resolve/update ticket (auth required)GET /health- health check
- Auto-resolved messages are replied by AI and do not create unresolved tickets.
- Escalated tickets are replied by human agents on resolve.
- A ticket prevents duplicate customer replies from multiple responders.
- Add scheduler/worker (e.g., APScheduler, Celery, or cron) to invoke
/api/ingest/pollautomatically. - Replace default login with proper user management + password reset.
- Add audit logs and role-based permissions.
- Secure email credentials via secret manager.
- Add robust JSON parsing in
graph.pyand guardrails for AI outputs.
Use AI_Services/app as the service root directory.
- Root directory:
AI_Services/app - Build command:
pip install -r requirements.txt - Start command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Health check path:
/health
Required environment variables:
DATABASE_URL(from Render PostgreSQL connection string)SECRET_KEYGEMINI_API_KEYPINECONE_API_KEYPINECONE_INDEX_NAME
Recommended production values:
DEBUG_MODE=falseAUTO_POLL_ENABLED=false