Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CORRESPA AI


image alt

Correspa AI is an autonomous, multi-agent email support system that monitors a business inbox, understands each incoming message, and produces accurate, on-brand draft replies, without a human having to read every ticket first.

It is built around a LangGraph-orchestrated pipeline in which specialized AI agents collaborate to categorize incoming mail, research answers from internal knowledge using Retrieval-Augmented Generation (RAG), draft a response, and proofread it before it ever reaches a customer.

Why Correspa AI

Support teams are expected to respond quickly, accurately, and consistently, even as ticket volume grows. Manually triaging, researching, and drafting every email is slow and error-prone, and inconsistent answers erode customer trust.

Correspa AI addresses this by giving each stage of the response process to a dedicated AI agent, so incoming mail is classified correctly, answered with information grounded in real company documentation, and checked for quality before being queued as a Gmail draft, reducing response time while keeping a human in the loop for final approval.

Key Capabilities

Inbox monitoring & triage

  • Continuously polls a connected Gmail inbox for new, unanswered messages
  • Classifies each email as a product inquiry, customer complaint, customer feedback, or unrelated
  • Filters out irrelevant messages automatically so agents only spend effort where it counts

Grounded response generation

  • For product or service questions, generates targeted retrieval queries and pulls relevant context from a vector store built on the company's own documents (RAG)
  • For complaints and feedback, drafts an empathetic, context-aware reply directly
  • Produces natural, personalized email copy rather than generic templates

Automated quality review

  • A dedicated proofreading agent checks tone, accuracy, and formatting against the original customer message
  • Emails that don't meet the bar are sent back for a rewrite, up to a bounded number of attempts, before being queued
  • Approved responses are saved as Gmail drafts, keeping a human in the loop before anything is sent

How It Works

  1. Load inbox: the workflow fetches unanswered emails from Gmail via the Gmail API.
  2. Categorize: an LLM agent classifies the email as a product inquiry, complaint/feedback, or unrelated.
  3. Route:
    • Product inquiry → the system builds RAG queries, retrieves supporting context from the vector store, and passes it to the writer agent.
    • Complaint / feedback → the writer agent drafts a reply directly.
    • Unrelated → the email is skipped.
  4. Draft: the writer agent composes a response using the email content (and any retrieved context).
  5. Proofread: a reviewer agent checks the draft; if it doesn't pass, it's sent back to the writer for revision (bounded by a retry limit).
  6. Queue for send: once approved, the reply is saved as a Gmail draft, and the workflow moves on to the next email in the inbox.

This loop repeats until the inbox has no more unanswered emails to process.

image alt

Tech Stack

Layer Technology
Agent orchestration LangChain & LangGraph
LLM inference Groq (Llama 3.3 70B) & Google Gemini
Retrieval / vector store Chroma, Google Generative AI Embeddings
Email integration Gmail API (google-api-python-client)
API deployment FastAPI & LangServe
Language Python

Project Structure

correspa-ai/
├── main.py                    # Entry point — runs the workflow as a continuous local process
├── deploy_api.py               # Exposes the workflow as a FastAPI/LangServe endpoint
├── create_index.py             # Builds/refreshes the Chroma vector store from source documents
├── requirements.txt             # Python dependencies
├── workflow.png                # Visual diagram of the LangGraph workflow
├── data/
│   └── agency.txt               # Source knowledge documents used to ground RAG responses
├── db/                          # Persisted Chroma vector store (generated by create_index.py)
├── src/
│   ├── agents.py                 # Defines each LLM-backed agent (categorizer, RAG chain, writer, proofreader)
│   ├── graph.py                  # Assembles the agents into the LangGraph state machine
│   ├── nodes.py                  # Node functions executed at each step of the graph
│   ├── prompts.py                # Prompt templates driving each agent's behavior
│   ├── state.py                  # Shared graph state and Email data model (Pydantic)
│   ├── structure_outputs.py      # Structured output schemas for LLM responses
│   └── tools/
│       └── GmailTools.py          # Gmail API wrapper - fetch, read, and draft emails

Getting Started

Prerequisites

  • Python 3.7+
  • A Groq API key
  • A Google Gemini API key (used for embeddings)
  • Gmail API credentials for the inbox you want to automate

Setup

  1. Clone the repository
   git clone https://github.com/<your-username>/correspa-ai.git
   cd correspa-ai
  1. Create and activate a virtual environment
   python -m venv venv
   source venv/bin/activate   # On Windows: venv\Scripts\activate
  1. Install dependencies
   pip install -r requirements.txt
  1. Configure environment variables

    Create a .env file in the project root:

   MY_EMAIL=your_email@gmail.com
   GROQ_API_KEY=your_groq_api_key
   GOOGLE_API_KEY=your_gemini_api_key
  1. Enable the Gmail API

    Follow Google's Python quickstart guide to enable the Gmail API and obtain your OAuth credentials.

Running Correspa AI

Run the workflow locally

python main.py

The application will continuously check the inbox, categorize new emails, generate responses, and verify them before queuing drafts.

Deploy as an API

python deploy_api.py

This starts a FastAPI/LangServe server on localhost:8000. API docs are available at /docs, and an interactive LangServe playground is available at /playground.

Customization

  • Adjust agent behavior by editing the corresponding methods in src/nodes.py or the prompt templates in src/prompts.py.
  • Add your own company/product knowledge to the data/ folder, then rebuild the vector index:
  python create_index.py

Attribution

This project is derived from the work of Aimen Kerrour (@kaymen99). The original implementation can be found at langgraph-email-automation.

Contributing

Contributions are welcome. Please open an issue to discuss proposed changes or submit a pull request directly.

License

This project is licensed under the MIT License.


Author

MOSTAFA ABDELHAMED | Junior AI & DS Researcher | NVIDIA Gen AI Certified LinkedIn

About

An automated customer support email handling system with a multi-agent LangGraph workflow that combines categorization, retrieval-augmented generation, and automated quality review.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages