AI Fitness Coach

Inspiration

Endurance athletes (runners, cyclists, and triathletes) generate vast amounts of data across fragmented ecosystems—Strava for GPS routes, heart rate streams, and segment splits; Garmin Connect for 24/7 biometric telemetry like sleep stages, Heart Rate Variability (HRV), Resting Heart Rate (RHR), Body Battery, and Acute/Chronic Workload Ratios (ACWR).

However, private human coaching is costly ($150–$300+/month), and traditional training apps offer rigid, one-size-fits-all training plans that ignore how well your body actually recovered last night. Athletes frequently fall into the trap of either overtraining into injury or undertraining with generic plans.

We set out to build an autonomous AI fitness coach: a true background "Taskmaster" agent that eliminates manual logging and chatbots entirely. It listens to wearable telemetry, applies rigorous exercise physiology principles, and delivers hyper-personalized coaching and custom Zwift workout files straight to the athlete's inbox.


What it does

  • Autonomous, Zero-Chat Operation: Operates purely as a background agent. It automatically wakes up via Strava Webhooks whenever a workout is uploaded, and executes on schedule via Google Cloud Scheduler for daily Morning Readiness Briefings (9:00 AM) and Evening Workout Previews (10:00 PM).
  • Biometric & Telemetry Synthesis: Aggregates and correlates Strava workout data (pace, power, heart rate zones, lap splits, cardiac drift) with Garmin recovery metrics (RHR trends, HRV status, sleep architecture, stress levels, and training load balance).
  • Sports Science Engine: Applies validated exercise physiology frameworks:
    • 80/20 Polarized Training (80% low-intensity Zone 2 volume).
    • 10% Progressive Overload Rule to prevent injury.
    • Tiered Metric Hierarchy (prioritizing cardiovascular recovery baselines like RHR/HRV over transient single-night sleep dips).
    • ACWR Sweet Spot Analysis (0.8–1.3 optimal, 1.3–1.5 progressive building zone, >1.5 elevated fatigue risk).
    • Cardiac Drift Detection to evaluate aerobic decoupling versus heat/hydration strain.
    • Garmin Training Load Balance Interpretation (distinguishing low-aerobic surpluses from anaerobic deficiencies).
  • Auto-Generated Zwift Workout Files (.zwo): Every prescribed workout automatically generates two structured Zwift workout XML files (one for cycling and one for running) with power targets (FTP fractions), pace targets, and live on-screen <textevent> coaching cues and form reminders.
  • Responsive HTML Coaching Briefings: Sends clean, color-coded HTML emails with metric badges, trend arrows, lap tables, and attached ready-to-ride .zwo files.

How we built it

  • Agent Framework: Built using the Google Agent Development Kit (ADK) (google-adk), orchestrating multi-tool retrieval across fitness and biometric services.
  • LLM Reasoning: Powered by Gemini 3.7 Flash via Google Vertex AI for ultra-fast reasoning, physiological metric synthesis, and complex XML generation.
  • Backend & Cloud Infrastructure: Developed with FastAPI and containerized with Docker, deployed serverlessly to Google Cloud Run in project margolis-fitness-coach.
  • Event-Driven Architecture:
    • Strava Webhook API for real-time post-activity triggers.
    • Google Cloud Scheduler for daily cron triggers.
  • Integrations & Data Sources:
    • Strava API v3 (activities, stream telemetry, split laps).
    • Garmin Connect API (sleep stages, HRV status, daily resting heart rate, training status, body battery).
    • Gmail SMTP for secure delivery of HTML briefings with .zwo XML attachments.

Challenges we ran into

  • Physiological Data Interpretation: Early iterations of the agent misconstrued Garmin's raw phrase AEROBIC_LOW_FOCUS as a deficiency rather than a surplus of low-aerobic volume. We built explicit load-balance parsing and established a strict Metric Hierarchy so the agent wouldn't prescribe unnecessary rest when primary recovery markers (RHR and HRV) were optimal.
  • Precise Zwift .zwo XML Generation: Ensuring that LLM-generated .zwo files strictly adhered to Zwift XML schema requirements. We had to enforce rigid validation to distinguish time-based intervals (in seconds) from distance-based workouts (in meters) and correctly map intensity levels to accurate percentages of FTP (e.g., 50–75% for Zone 2 vs. 175–200% for all-out sprint repeats).
  • Asynchronous Cloud Run Lifecycles: Handling the verification handshake for Strava webhooks while concurrently orchestrating multi-step ADK agent runs without exceeding Cloud Run request timeouts.
  • Token Refresh & Secrets Management: Managing OAuth 2.0 refresh cycles for both Strava and Garmin Connect seamlessly in production while maintaining strict secrets hygiene.

Accomplishments that we're proud of

  • True Background Autonomy: Delivered a completely hands-off agentic experience that runs without requiring prompts, chats, or manual inputs from the user.
  • Dual Cycling & Running .zwo Generation: Engineered an automated pipeline that creates valid, ready-to-load Zwift workouts with synchronized on-screen coaching prompts.
  • Evidence-Based Sports Intelligence: Built a coaching persona that balances empathy with empirical rigor, accurately spotting cardiac drift, managing progressive overload, and tailoring prescriptions to specific race goals.
  • Production Serverless Deployment: Shipped a robust, end-to-end cloud deployment on Google Cloud Run leveraging Gemini 3.7 Flash on Vertex AI.

What we learned

  • LLM Prompting for Structured Physiology: LLMs perform significantly better on complex biometric data when given clear mathematical boundary rules (e.g., ACWR ranges) and explicit metric hierarchies rather than open-ended coaching heuristics.
  • Separation of Tool Trajectories in Google ADK: Breaking down data gathering into discrete ADK tools (Strava activities, Garmin sleep, Garmin HRV, goal states) enables clean reasoning traces and reliable error recovery.
  • Bridging AI with Physical Workouts: Discovered how frictionless wearable APIs and open workout formats (.zwo) make AI-generated training directly actionable on indoor smart trainers and treadmills.

What's next for Fitness Coach

  • Direct Device Sync (Garmin / Wahoo): Pushing structured workouts directly to Garmin Connect and Wahoo ELEMNT bike computers via their respective cloud APIs.
  • Multimodal Form Analysis: Integrating Gemini vision capabilities to analyze video clips of running gait or bike fit for biomechanical efficiency and cadence optimization.
  • Dynamic Long-Term Periodization: Implementing multi-month marathon and triathlon training blocks that automatically re-taper and adapt when workouts are missed or sickness occurs.
  • Multi-Sport & Swimming Metrics: Extending support to swimming analytics (SWOLF, stroke rate) and multi-discipline brick workouts (bike-to-run transitions).

Built With

Share this project:

Updates

Submission history