Email AI Agent With Knowledgebase using n8n
Learn how to build an automated email agent that sends personalized messages to contacts stored in a Pinecone knowledge base using n8n's workflow automation platform
Email AI Agent With Knowledgebase Tutorial
In this tutorial, you'll learn how to build a sophisticated AI-powered email agent using n8n that automatically searches for contacts in a Pinecone knowledge base and sends personalized emails. The system consists of three main components working together to streamline your email communication process.
System Overview
The Email AI Agent With Knowledgebase is a multi-agent system that consists of:
- Main Email Agent - Orchestrates the email sending workflow
- Contact Search Tool - Searches Pinecone vector database for contact information
- Gmail Send Agent - Handles the actual email sending process
Main Email Agent Configuration
The main agent acts as the orchestrator, coordinating contact search and email sending based on user requests.
System Prompt for Main Agent
## **Role**
You are an **Email Agent** that helps users send professional emails.
Your core responsibilities are:
1. Find the recipient's email address using the search_contacts tool.
2. Automatically frame the subject line and email body based on the user's instructions and conversation context.
3. Trigger the email workflow once the recipient is confirmed using send_email tool.
## **Instructions**
1. **Always** use the `search_contacts` tool to find the recipient's email address.
2. **Never** assume or fabricate email addresses. If none is found, stop and inform the user.
3. Automatically generate a **subject line** that is short, clear, and contextually relevant.
4. Automatically generate the **email body** from the user's request and conversation context.
- Keep it concise, polite, and professional.
- If the tone is implied (casual, formal, follow-up), adapt accordingly.
5. Call the `send_email` tool with a structured response in the following format:
{
"query": "sendTo=<email>&subject=<subject>&body=<body>"
}
## **Tools**
- **search_contacts** → Searches the Pinecone vector database for contacts. Must always be used to retrieve email addresses.
- **send_email** → Triggers the email workflow by passing the simplified query structure.
## **Rules**
- **Mandatory search**: Always confirm the email address via `search_contacts`.
- **Disambiguation**: If multiple contacts are found, ask the user to clarify.
- **Fallback**: If no contact is found, stop and ask for clarification.
- **Framing**:
- Subject: Max 8–10 words, action-oriented.
- Body: 2–4 paragraphs depending on context. Always professional.
- **No repetition**: Do not ask the user again for subject or body.
- **Output format**: Always return the final response in the format above.
- **Never Leave any fields as blank**
- **Always Sign Off with Growth Rise Agency**
## **Tool Prompts**
### Contact Search Tool
Call this tool to search for contact information
### Send Email Tool
Call this tool to send email to contacts.
Contact Search AI Tool
This tool searches the Pinecone vector database to find contact information based on user queries.
Configuration
Tool Description: Call this tool to search for contact information
Features:
- Search the Pinecone vector database with semantic similarity
- Use OpenAI embeddings for accurate contact matching
- Return relevant contact information including email addresses
- Operate within the "Contacts" namespace in Pinecone
- Enable semantic search capabilities for finding contacts with partial or fuzzy queries
- Connect to your Pinecone knowledge base where contact information is stored as vectors
Gmail Send AI Agent
This agent handles the actual email sending process by parsing the structured query and sending emails through Gmail.
Configuration
User Prompt: Parse the below query into JSON - {{ $json.query }}
System Features:
- Parses structured email queries into JSON format
- Extracts recipient email, subject, and body content
- Sends emails through Gmail with proper formatting
- Automatically signs emails with "Growth Rise Agency"
- Handles error cases gracefully
Expected Input Format:
{
"query": "sendTo=john@example.com&subject=Meeting Follow-up&body=Hi John, Thank you for the great meeting today..."
}
Expected Output Format:
{
"sendTo": "john@example.com",
"subject": "Meeting Follow-up",
"body": "Hi John, Thank you for the great meeting today..."
}
Setup Process
1. Pinecone Knowledge Base Setup
Before using the email agent, you need to populate your Pinecone knowledge base with contact information:
- Prepare Contact Data: Organize your contacts in a structured format (Google Docs, CSV, etc.)
- Use Setup Agent: Run the Setup KB Agent to vectorize and store contacts
- Verify Storage: Ensure contacts are properly indexed in the "Contacts" namespace
2. Gmail Integration
Configure Gmail integration for sending emails:
- OAuth Setup: Connect your Gmail account with proper permissions
- Sender Configuration: Set "Growth Rise Agency" as the default sender name
- Test Connection: Verify email sending functionality
3. Agent Deployment
Deploy the complete email agent system:
- Import Templates: Use the provided n8n workflow templates
- Configure Credentials: Set up OpenAI, Pinecone, and Gmail credentials
- Test Workflow: Run end-to-end tests with sample contacts
Usage Examples
Example 1: Simple Email Request
User Input: "Send an email to John about the project update"
Agent Process:
- Searches contacts for "John"
- Finds john@company.com
- Generates subject: "Project Update"
- Creates professional email body
- Sends email through Gmail
Example 2: Follow-up Email
User Input: "Follow up with Sarah from last week's meeting"
Agent Process:
- Searches contacts for "Sarah"
- Finds sarah@business.com
- Generates subject: "Following Up - Last Week's Meeting"
- Creates follow-up email with meeting context
- Sends personalized follow-up
Next Steps
With this AI email agent system in place, you can:
- Build Contact Database - Populate Pinecone with your contact information
- Customize Email Templates - Adjust the agent prompts for your specific use cases
- Monitor Email Performance - Track email delivery and responses
- Scale Operations - Handle multiple email requests efficiently
- Integrate with CRM - Connect with your existing customer management systems
This system automates the entire email process from contact lookup to professional email composition and delivery, saving significant time while maintaining personalization and professionalism.