mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
- Add EmailState model for Flow state management - Create EmailProcessingFlow class with event-based automation - Update tools and crews for Flow integration - Add comprehensive Flow tests - Implement error handling and state tracking - Add mock implementations for testing This implementation uses CrewAI Flow features to create an event-based email processing system that can analyze emails, research senders, and generate appropriate responses using specialized AI crews. Co-Authored-By: Joe Moura <joao@crewai.com>
Email Processing System with CrewAI
A smart email processing system that uses CrewAI to analyze Gmail messages and automatically generate appropriate responses based on context and history.
Quick Start
# Install required packages
pip install crewai 'crewai[tools]'
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
Example Usage
from email_analysis_crew import EmailAnalysisCrew
from response_crew import ResponseCrew
from gmail_tool import GmailTool
# Initialize Gmail connection
gmail = GmailTool()
gmail.authenticate()
# Create analysis crew
analysis_crew = EmailAnalysisCrew(
gmail_tool=gmail,
config={
"check_similar_threads": True,
"analyze_sender_history": True
}
)
# Process new emails
new_emails = gmail.get_new_emails()
for email in new_emails:
# Analyze email and decide on response
analysis = analysis_crew.analyze_email(email)
# If analysis determines response is needed
if analysis["response_needed"]:
# Create new crew for response generation
response_crew = ResponseCrew(
email_context=analysis,
gmail_tool=gmail
)
# Generate and send response
response = response_crew.generate_response()
gmail.send_response(response)
How It Works
-
Email Analysis
- System connects to Gmail
- Retrieves new emails
- Analyzes email context and history
- Checks for similar threads
- Researches sender and company
-
Response Decision The analysis crew decides whether to respond based on:
- Email urgency
- Sender relationship
- Previous interactions
- Business context
- Similar thread history
-
Response Generation If a response is needed:
- New response crew is created
- Analyzes email context
- Generates appropriate response
- Reviews for tone and content
- Sends through Gmail
Setup Instructions
-
Install Dependencies
pip install crewai 'crewai[tools]' pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib -
Gmail Setup
- Visit Google Cloud Console
- Create new project
- Enable Gmail API
- Create OAuth credentials
- Download as
credentials.json
-
Configure Authentication
from gmail_tool import GmailTool gmail = GmailTool() gmail.authenticate() # Opens browser for auth
Configuration
# Analysis configuration
config = {
"check_similar_threads": True, # Look for similar conversations
"analyze_sender_history": True, # Check previous interactions
"research_company": True, # Research sender's company
"priority_threshold": 0.7 # Threshold for response
}
# Create crews
analysis_crew = EmailAnalysisCrew(
gmail_tool=gmail,
config=config
)
response_crew = ResponseCrew(
email_context=analysis,
gmail_tool=gmail
)
Components
EmailAnalysisCrew: Analyzes emails and makes response decisionsResponseCrew: Generates appropriate responsesGmailTool: Handles Gmail integrationEmailTool: Provides email processing utilities
Error Handling
The system includes handling for:
- Gmail API connection issues
- Authentication errors
- Rate limiting
- Invalid email formats
Contributing
- Fork the repository
- Create feature branch
- Submit pull request
License
MIT License