A LangChain + LangGraph agent that processes user submissions by creating Google Docs and sending them via email.
- ✅ Validates user input (name, email, address)
- 📄 Creates Google Doc with formatted submission data
- 💾 Exports Google Doc as DOCX format
- 📧 Sends email with DOCX attachment to fixed recipient
- 🔄 Error handling with retry logic
- 📊 Comprehensive logging and status tracking
pip install -r requirements.txt- Create a Google Cloud project
- Enable the following APIs:
- Google Docs API
- Google Drive API
- Gmail API
- Create OAuth 2.0 credentials (Desktop application)
- Download the client secret JSON file
Create a .env file with your credentials:
# Google OAuth Credentials
GOOGLE_CLIENT_ID=your_client_id_here
GOOGLE_CLIENT_SECRET=your_client_secret_here
GOOGLE_TOKEN_PATH=token.json
# Note: Recipient email is now provided by user input, not environment variable
# Optional: Drive folder ID to organize docs
DRIVE_FOLDER_ID=your_folder_id_hereOn first run, the agent will open a browser window for OAuth consent. This creates a token.json file for subsequent runs.
Launch the Streamlit web app for a user-friendly interface:
# Run the Streamlit app
python3 -m streamlit run streamlit_app.py
# Or use the helper script
python3 run_streamlit.pyThe web interface provides:
- ✅ Clean, intuitive form fields
- ✅ Real-time validation
- ✅ Progress indicators
- ✅ Success/error messages with details
- ✅ Direct links to created documents
# Interactive mode
python main.py --interactive
# Direct arguments
python main.py --name "John Doe" --email "john@example.com" --address "123 Main St, City, State" --recipient "admin@company.com"from adopt.agent import create_agent
# Create agent
agent = create_agent()
# Process submission
result = agent.process_submission(
name="Jane Smith",
email="jane.smith@example.com",
address="456 Oak Avenue, Springfield, IL 62701",
recipient_email="admin@company.com"
)
if result["success"]:
print(f"Document created: {result['document_url']}")
print(f"Email sent: {result['email_message_id']}")
else:
print(f"Error: {result['message']}")python example_usage.pyvalidate_input → create_document → export_docx → send_email → finalize
↓ ↓ ↓ ↓
handle_error ← handle_error ← handle_error ← handle_error
- UserSubmission: Pydantic model for input validation
- GoogleAPIManager: Handles OAuth and API service creation
- CreateGoogleDocTool: Creates and populates Google Docs
- ExportDocxTool: Exports docs to DOCX format
- SendEmailTool: Sends emails with attachments via Gmail API
- SubmissionAgent: LangGraph orchestrator
https://www.googleapis.com/auth/documents- Create and edit Google Docshttps://www.googleapis.com/auth/drive.file- Export docs and manage created fileshttps://www.googleapis.com/auth/gmail.send- Send emails
Each submission creates a Google Doc with:
Title: Submission - [Name] - [ISO Timestamp]
Content:
Name: [User Name]
Email: [User Email]
Address: [User Address]
- Subject:
New Submission: [Name] - Body: Summary with document link
- Attachment: DOCX file with submission data
- Input validation with clear error messages
- Retry logic for transient API errors
- Comprehensive logging at each step
- Graceful failure handling
- OAuth 2.0 with least-privilege scopes
- Secure token storage and refresh
- Input sanitization and validation
- No hardcoded credentials
- OAuth Errors: Ensure APIs are enabled and credentials are correct
- Permission Denied: Check Gmail account has necessary permissions
- Token Expired: Delete
token.jsonto re-authenticate - API Quotas: Check Google Cloud Console for quota limits
The agent provides detailed logging at INFO level. Enable DEBUG for more verbose output:
import logging
logging.basicConfig(level=logging.DEBUG)# Run example with validation tests
python example_usage.py
# Manual testing
python main.py --interactiveadopt/
├── adopt/
│ ├── __init__.py
│ ├── agent.py # LangGraph workflow
│ └── tools.py # Google API tools
├── main.py # CLI interface
├── example_usage.py # Usage examples
├── requirements.txt # Dependencies
└── README.md # This file