How dashankanadeeshandesilva/crm_ai_workflow_automation_to_handle_and_respond_customer_emails works
Project Type and Purpose
• This is a backend AI workflow service (FastAPI) containerized with Docker, designed to automate customer email handling and responses using an internal knowledge base and LLM.
High-Level Architecture Components
a. External Triggers & Clients
• Scheduler / Cron (inside container) – periodically kicks off the workflow
• Email Client (Google Gmail API) – fetch incoming emails & send replies
• External Services:
– OpenRouter API (LLM endpoint)
– Remote SQL Database (tickets)
– Google Sheets API (logging)
b. AI Agent Microservice (Docker Container)
• FastAPI App (app/main.py) exposes REST endpoints and houses the scheduler
• Services Layer (app/services/)
– email_processor.py: fetches and parses new emails
– intent_classification.py: coarse intent tagging
– create_ticket.py: writes to remote SQL DB
– log_activity.py: writes to Google Sheets
– utils.py: shared helpers
• Reasoning Engine (app/reasoning_engine/)
– llm.py: handles LLM API calls via LangChain/OpenRouter
– reasoning_engine.py: orchestrates classification, KB lookup, ticket decisions, response generation
– reasoning_engine_helpers.py: prompt assembly & context curation
• Knowledge Base (app/knowledge_base/)
– documents/ (Markdown source files)
– chroma.sqlite3 (vector DB)
– knowledge_base.py: loader & retriever
• Prompts (app/prompts/): reusable prompt templates for classification, retrieval, ticketing, response generation
Data Flow & Interactions
1. Scheduler → triggers EmailProcessor
2. EmailProcessor → Gmail API → returns new emails
3. For each email:
a. IntentClassification → tag intent
b. ReasoningEngine →
i. Decide if KB lookup needed → query Chroma
ii. Decide if ticket required → CreateTicket → Remote SQL DB
iii. Generate reply → LLM (with context, prompts)
c. EmailProcessor → send reply via Gmail API
d. LogActivity → record actions to Google Sheets
Architectural Patterns & Principles
• Modular, single‐responsibility services (email processing, classification, ticketing, logging)
• Orchestration layer (reasoning_engine) coordinating AI calls and business decisions
• Adapter patterns for external systems (Gmail, LLM, SQL, Sheets)
• Separation of concerns: prompts, KB, services, engine
Technology Stack Callouts
• Python 3.10, FastAPI for HTTP/scheduler
• LangChain + OpenRouter for LLM orchestration
• Chroma (SQLite) as local vector store
• Google APIs for email & Sheets
• Remote SQL (Postgres/MySQL) for ticket persistence
• Docker + GitHub Actions CI/CD → AWS EC2 deployment