An intelligent, multi-agent AI system that provides personalized running coaching by analyzing your Strava data through a sophisticated Telegram bot interface. Built with LangGraph, Google Gemini AI, and ChromaDB for advanced data processing and insights.
- π€ AI-Powered Coaching: Uses Google Gemini AI to analyze your running data and provide personalized insights
- π± Telegram Bot Interface: Easy-to-use chat interface for asking questions about your runs
- π Strava Integration: Automatically syncs your running activities from Strava with intelligent deduplication
- π Advanced Analytics: Generates plots and visualizations of your running performance
- π₯ Multi-User Support: Each user can have their own Strava account and data
- π§ LangGraph Workflow: Sophisticated 9-agent workflow for intelligent data processing
- π Secure & Private: User data isolation and secure API key management
The system implements a sophisticated 9-agent workflow using LangGraph:
- Personal Info Checker Agent: Validates user information completeness
- Strava Agent: Fetches and processes running activities with intelligent deduplication
- Document Creator Agent: Converts data to natural language summaries using LLM
- Document Storage Agent: Stores processed documents in ChromaDB vector database
- Query Interpreter Agent: Converts natural language to structured queries
- Document Retriever Agent: Performs semantic search and retrieves relevant data
- Coach Agent: Generates personalized coaching insights
- Plotting Agent: Creates AI-powered visualizations with fallback mechanisms
- Response Formatter Agent: Formats final responses for Telegram delivery
- Telegram Bot (
telegram_bot/): Handles user interactions and message routing - AI Workflow (
agents/): LangGraph-powered workflow for intelligent data processing - Strava Client (
strava/): API client for fetching running data with OAuth2 - LLM Integration (
llm/): Google Gemini AI integration with rate limiting - Data Storage (
utils/): ChromaDB vector database and chat context management
- Python 3.11+
- Strava API access
- Google Gemini API key
- Telegram bot token
-
Clone the repository
git clone https://github.com/yourusername/strava-agent.git cd strava-agent -
Install dependencies using uv
cd new_bot uv sync -
Set up environment variables
cp env.example .env # Edit .env with your actual API keys and tokens -
Run the bot
uv run python main.py
Copy env.example to .env and configure:
# Strava Configuration
STRAVA_CLIENT_ID=your_strava_client_id_here
STRAVA_CLIENT_SECRET=your_strava_client_secret_here
STRAVA_REFRESH_TOKEN=your_strava_refresh_token_here
# Google Gemini Configuration
GOOGLE_API_KEY=your_google_api_key_here
MODEL_NAME=gemini-2.0-flash
EMBED_MODEL=models/text-embedding-004
# Telegram Configuration
TELEGRAM_TOKEN=your_telegram_bot_token_here
# Database Configuration
CHROMA_DB_DIR=./chroma_stores
# User Configuration (JSON string)
USERS={"user1": {"chat_id": 123456789, "strava_refresh_token": "token1"}}- Go to https://www.strava.com/settings/api
- Create a new application
- Note down your
Client IDandClient Secret - Set the Authorization Callback Domain to
localhost - Visit the authorization URL to get your refresh token:
https://www.strava.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost&response_type=code&scope=activity:read_all
- Go to https://makersuite.google.com/app/apikey
- Create a new API key
- Enable the Gemini API in your Google Cloud Console
- Message @BotFather on Telegram
- Use the
/newbotcommand - Follow the instructions to create your bot
- Note down the bot token
The USERS variable supports multiple users with different Strava accounts:
{
"etqad": {
"chat_id": "123456789",
"strava_refresh_token": "your_token"
},
"wife": {
"chat_id": "987654321",
"strava_refresh_token": "her_token",
"strava_client_id": "her_client_id",
"strava_client_secret": "her_client_secret"
}
}/start- Initialize the bot and set up personal information/sync- Sync your latest Strava running activities/info- View or update your personal information/clear- Clear chat history/reset- Reset your personal information/help- Show available commands
- "Analyze my easy run from yesterday"
- "Compare my last two long runs"
- "How did my pace improve over the last month?"
- "Show me my heart rate trends for tempo runs"
- "What's my best 10K time?"
- "Compare Tempo Run 1 and 2"
- "How did my easy runs perform in August?"
- Automatic Deduplication: Only fetches new runs from Strava
- Stream Data Extraction: Per-kilometer breakdowns with metrics
- Fallback Handling: Graceful degradation for manual runs
- Rich Metadata: Comprehensive indexing for efficient search
- Complex Queries: Support for date ranges, run types, metrics
- Temporal Expressions: "last 30 days", "August", specific dates
- Specific Run Requests: "Tempo Run 1 and 2"
- Comparative Analysis: Run-to-run comparisons
- Metric Filtering: Heart rate ranges, pace thresholds
- Context-Aware Responses: Consider user preferences and history
- Actionable Insights: Specific recommendations based on data
- Progress Tracking: Trend analysis and goal alignment
- Training Load Analysis: Volume and intensity assessment
- AI-Powered Charts: Context-aware visualization selection
- Multiple Chart Types: Line plots, bar charts, scatter plots
- Performance Trends: Pace, heart rate, power over time
- Comparative Analysis: Side-by-side run comparisons
- Fallback Mechanisms: Graceful degradation to simple plots
- Black: Code formatting (88 character line length)
- Flake8: Linting and style checking
- Pre-commit hooks: Automatic code quality checks
uv run pytestuv run black .uv add package_name
uv add --dev package_name # For development dependenciesstrava-agent/
βββ new_bot/ # Main application directory
β βββ agents/ # AI workflow agents
β β βββ simple_agent.py # Basic agent implementation
β β βββ workflow.py # LangGraph workflow orchestration
β βββ llm/ # Google Gemini integration
β β βββ client.py # LLM client with rate limiting
β βββ strava/ # Strava API client
β β βββ client.py # OAuth2 client with token refresh
β βββ telegram_bot/ # Telegram bot implementation
β β βββ bot.py # Bot interface and command handling
β βββ utils/ # Utility modules
β β βββ chat_context.py # User conversation management
β β βββ chroma_manager.py # Vector database operations
β β βββ plotting_agent.py # Visualization generation
β β βββ token_manager.py # Secure token handling
β β βββ user_mapper.py # User configuration management
β βββ main.py # Application entry point
β βββ config.py # Configuration management
β βββ pyproject.toml # Project configuration
β βββ env.example # Environment template
βββ src/ # Alternative source structure
βββ pyproject.toml # Root project configuration
βββ README.md # This file
- Environment Variables: All secrets stored securely in
.envfiles - User Isolation: Separate databases per user with ChromaDB
- Local Storage: User data stored locally, not in the cloud
- Minimal Collection: Only necessary information is collected
- Secure Token Management: OAuth2 implementation with automatic refresh
- OAuth2 Implementation: Secure Strava authentication
- Rate Limiting: Respectful API usage with exponential backoff
- Token Management: Automatic refresh handling
- Input Validation: Sanitized user inputs
- API Keys: Never committed to version control
- User Tokens: Stored securely in environment variables
- Personal Data: Isolated per user in separate databases
- Chat History: Stored locally with user isolation
- Never commit
.envfiles - they contain sensitive API keys - Keep API keys secure - rotate them periodically
- User data isolation - each user's data is stored separately
- Local storage only - no data is sent to external services
- Fork the repository
- Create a feature branch
- Make your changes
- Run code quality checks:
uv run black . && uv run flake8 - Submit a pull request
- Agent Development: Add new specialized agents to the workflow
- Integration: Support additional data sources and platforms
- Visualization: Enhance plotting capabilities and chart types
- Documentation: Improve guides and API documentation
- User Isolation: Independent databases per user
- Modular Architecture: Easy component replacement and extension
- Efficient Caching: Intelligent data reuse and embedding cache
- Rate Limit Respect: Sustainable API usage with automatic retry
- Error Recovery: Graceful handling of failures and edge cases
- Fallback Mechanisms: Multiple recovery strategies for robustness
- Data Validation: Comprehensive input checking and validation
- Monitoring: Detailed logging and debugging capabilities
- API Rate Limits: Automatic retry with exponential backoff
- Token Expiration: Automatic refresh handling
- Missing Data: Graceful degradation for incomplete data
- Configuration Errors: Clear error messages and setup guides
Enable detailed logging by modifying the logging configuration in main.py:
logging.basicConfig(
level=logging.DEBUG, # Change from INFO to DEBUG
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('bot.log'),
logging.StreamHandler(sys.stdout)
]
)If you encounter issues:
- Check the logs in
bot.log - Verify your API keys are correct
- Ensure all dependencies are installed
- Check that your Strava account has running activities
- Review the Issues page
This project is licensed under the MIT License - see the LICENSE file for details.
- Strava API for running data
- Google Gemini for AI capabilities
- LangGraph for workflow orchestration
- ChromaDB for vector storage
- LangChain for LLM integration framework
- Advanced Analytics: Machine learning-based insights and predictions
- Enhanced Visualization: Interactive charts and dashboards
- Social Features: Group challenges and performance sharing
- Integration Expansion: Additional fitness platforms and wearables
- Mobile Integration: Native app support and notifications
- New Agents: Easy to add specialized agents for specific tasks
- Additional Data Sources: Support for other fitness and health platforms
- Enhanced Analytics: ML models and predictive insights
- Custom Workflows: User-defined analysis workflows
If you need assistance:
- Documentation: This README contains comprehensive setup and usage information
- Issues: Check existing issues or create new ones on GitHub
- Discussions: Use GitHub Discussions for questions and ideas
- Contributing: Submit pull requests for improvements
Happy Running! πββοΈπ¨
This Strava Agent represents a sophisticated implementation of modern AI architecture, combining multi-agent systems, LLM integration, vector databases, and intelligent data processing to provide personalized running coaching through an intuitive Telegram interface.