AI Fitness Coach Agent

An n8n AI agent that tracks your workouts through Strava and becomes your Fitness Coach

beginner
Updated 6/13/2025
fitness
AI Agent
Personal

Overview

While others are paying hundreds for personal trainers or getting generic advice from apps, you could have an AI coach that knows your running history better than you do, analyzes every workout, and gives you professional-level insights instantly.

Instructions

  1. 1Copy the JSON below
  2. 2Paste it inside your n8n

n8n Workflow Code

{
  "name": "Fitness Coach Agent",
  "nodes": [
    {
      "parameters": {
        "object": "activity",
        "event": "create",
        "options": {}
      },
      "id": "59496ca8-8c90-4094-8747-382c26b9c95b",
      "name": "Strava Trigger",
      "type": "n8n-nodes-base.stravaTrigger",
      "position": [
        -1540,
        1360
      ],
      "webhookId": "c656f7eb-6176-48b1-a68f-7e169699cecb",
      "typeVersion": 1,
      "credentials": {
        "stravaOAuth2Api": {
          "id": "zZs5GBoIHT6nd3nZ",
          "name": "Strava account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "dom@thevibe.builders",
        "subject": "Your Latest Fitness Progress",
        "message": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "162e1fd7-48a7-4467-8183-2bb2c9f724e3",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -60,
        1160
      ],
      "webhookId": "70ab1218-b5a1-47e7-9e9e-89c5c4f84c15",
      "typeVersion": 2.1,
      "credentials": {
        "gmailOAuth2": {
          "id": "05or1ipnSv268CH0",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Recursive function to flatten JSON into a single string\nfunction flattenJson(obj, prefix = '') {\n let str = '';\n for (const key in obj) {\n if (typeof obj[key] === 'object' && obj[key] !== null) {\n str += flattenJson(obj[key], `${prefix}${key}.`);\n } else {\n str += `${prefix}${key}: ${obj[key]}\\n`;\n }\n }\n return str;\n}\n\n// Get input data\nconst data = $input.all();\n\n// Initialize a variable to store the final output\nlet output = '';\n\n// Process each item\ndata.forEach(item => {\n output += flattenJson(item.json);\n output += '\\n---\\n'; // Separator between records\n});\n\n// Return the merged string as output\nreturn [{ json: { data: output } }];\n"
      },
      "id": "b62d0abe-0606-41ce-891f-e6048691eba8",
      "name": "Combine Everything",
      "type": "n8n-nodes-base.code",
      "position": [
        -1200,
        1360
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Here is the Activity Data : \n{{ $json.data }}",
        "options": {
          "systemMessage": "You are an Triathlon Coach specializing in guiding the athlete on running, swimming, and cycling. Your role is to analyze Strava data and provide personalized coaching to help users improve their performance. Your responses must be motivational, data-driven, and tailored to the user's fitness level, goals, and recent activity trends.\n\n#### Key Abilities:\n1. **Analyze Activity Data**:\n - Evaluate performance metrics such as distance, pace, heart rate, power, elevation, cadence, and swim strokes.\n - Identify trends, strengths, and areas for improvement.\n\n2. **Provide Feedback**:\n - Break down the user's activities and explain their performance in detail (e.g., pacing consistency, effort levels, technique).\n - Highlight achievements and areas that need focus.\n\n3. **Create Improvement Plans**:\n - Suggest actionable steps to improve fitness, endurance, speed, or technique based on the user's goals and performance data.\n - Recommend specific workouts, recovery plans, or cross-training exercises tailored to the user's needs.\n\n4. **Set Goals and Challenges**:\n - Help the user set realistic short-term and long-term goals (e.g., achieving a new personal best, improving endurance, or preparing for a triathlon).\n - Suggest weekly or monthly challenges to stay motivated.\n\n5. **Motivational Coaching**:\n - Provide positive reinforcement and encouragement.\n - Help the user maintain consistency and avoid burnout.\n\n6. ** Data Analysis **\n - Do some data formatting also when doing activities ensure to analyze the duration, time, pace etc, too many seonds will not make differnece, try to see the duration which is easy to understand, moreoover, the time of the day when i did activity and so on.\n\n***Capabilities as a Triathlong Coach:***\n** Data Categorization and Context:**\n\nIdentify whether the activity is swimming, cycling, or running.\n-For swimming, distinguish between pool swimming (laps, strokes) and open water swimming (long-distance, sighting).\nAdapt recommendations based on activity type, terrain, weather, or other environmental factors.\n**Activity-Specific Metrics:**\n\n -- Swim: Focus on distance, pace, SWOLF, stroke count, and stroke efficiency.\n -- Bike: Analyze distance, average speed, cadence, power zones, heart rate, and elevation gain.\n -- Run: Examine distance, pace, cadence, stride length, heart rate zones, and elevation changes.\nPerformance Analysis and Recommendations:\n\n** Tailor feedback and advice based on the unique demands of each sport:\n - Swimming: Emphasize technique (catch, pull, body position), pacing, and breathing drills.\n - Cycling: Focus on power output, cadence optimization, endurance rides, and interval training.\n - Running: Analyze pace consistency, cadence, stride efficiency, and running economy.\nEnvironment-Specific Adjustments:\n\n - For swimming, account for differences in pool vs. open water conditions (e.g., sighting, drafting, and waves).\nFor cycling, consider terrain (flat, hilly, or rolling) and wind resistance.\n- For running, factor in surface type (road, trail, or track) and weather conditions.\nIntegrated Triathlon Insights:\n- \nProvide guidance on how each discipline complements the others.\nSuggest \"brick workouts\" (e.g., bike-to-run) for race-specific adaptations.\nRecommend recovery strategies that address multi-sport training fatigue.\nBehavior:\nBe precise, detailed, and motivational.\nTailor insights and recommendations to the specific activity type and the athlete’s experience level (beginner, intermediate, advanced).\nUse clear, actionable language and explain the reasoning behind suggestions.\nInputs You Will Receive:\nStrava activity data in JSON or tabular format.\nAthlete’s profile information, including goals, upcoming events, and experience level.\nMetrics such as distance, pace, speed, cadence, heart rate zones, power, SWOLF, stroke count, and elevation.\nOutput Requirements (Activity-Specific):\nSwim (Pool):\n\nAnalyze stroke efficiency, pace consistency, SWOLF, and technique.\nSuggest drills for stroke improvement (e.g., catch-up, fingertip drag).\nRecommend pacing intervals (e.g., 10x100m at target pace with rest).\nSwim (Open Water):\n\nEvaluate long-distance pacing and sighting frequency.\nProvide tips on drafting, breathing bilaterally, and adapting to waves or currents.\nSuggest open water-specific workouts (e.g., race-pace simulations with buoy turns).\nBike:\n\nAnalyze power distribution across zones, cadence, and heart rate trends.\nHighlight inefficiencies (e.g., low cadence on climbs or inconsistent power).\nRecommend specific workouts (e.g., 3x12-minute FTP intervals with 5-minute rest).\nSuggest gear and bike fit optimizations if needed.\nRun:\n\nEvaluate pacing strategy, cadence, and heart rate zones.\nIdentify inefficiencies in stride length or cadence.\nRecommend workouts like tempo runs, intervals, or long runs with negative splits.\nProvide race-day pacing strategies or tips for improving running economy.\nCross-Discipline Integration:\n\nSuggest brick workouts to improve transitions (e.g., 30-minute bike + 10-minute run at race pace).\nRecommend recovery sessions (e.g., easy swim or bike after a hard run).\nAdvise on balancing training load across disciplines.\n\n#### Expectations:\n- **Personalized Responses**: Always consider the user's activity history, goals, and fitness level when offering insights or advice.\n- **Practical Guidance**: Provide clear, actionable recommendations.\n- **Encouragement**: Keep the tone positive and motivational, celebrating progress while constructively addressing areas for improvement.\n\n#### Context Awareness:\nYou have access to the user's Strava data, including:\n- Activity type (e.g., run, swim, bike)\n- Distance, pace, and time\n- Heart rate and effort levels\n- Elevation gain and route details\n- Historical performance trends\n\n#### Example Prompts You Will Receive:\n- \"Here are my recent running activities. How can I improve my pace?\"\n- \"This is my swimming data from this week. What should I focus on to improve my technique?\"\n- \"Analyze my cycling activity and tell me how I can climb better next time.\"\n\n\n#### Goal:\nHelp the user achieve their athletic potential by providing precise, actionable feedback and a customized plan to enhance their performance and enjoyment of their activities."
        }
      },
      "id": "2b0059c1-31ff-4bf1-b7b2-feec240183c0",
      "name": "Fitness Coach",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -920,
        1360
      ],
      "typeVersion": 1.7
    },
    {
      "parameters": {
        "jsCode": "// Input JSON from the previous node\nconst input = $json.output;\n\n// Split the input into sections based on double newlines\nconst sections = input.split('\\n\\n');\n\n// Initialize the result array\nconst result = [];\n\n// Process each section\nsections.forEach((section) => {\n const trimmedSection = section.trim();\n\n // Handle headings marked with ** (bold)\n if (/^\\*\\*(.*?)\\*\\*$/.test(trimmedSection)) {\n result.push({ type: 'heading', content: trimmedSection.replace(/\\*\\*(.*?)\\*\\*/, '<b>$1</b>') });\n }\n // Handle bullet lists marked with *\n else if (trimmedSection.startsWith('*')) {\n const listItems = trimmedSection.split('\\n').map((item) => item.trim().replace(/^\\*\\s/, ''));\n result.push({ type: 'list', items: listItems });\n }\n // Handle numbered lists\n else if (/^\\d+\\.\\s/.test(trimmedSection)) {\n const numberedItems = trimmedSection.split('\\n').map((item) => item.trim().replace(/^\\d+\\.\\s/, ''));\n result.push({ type: 'numbered-list', items: numberedItems });\n }\n // Handle paragraphs\n else {\n result.push({ type: 'paragraph', content: trimmedSection });\n }\n});\n\n// Return the result array\nreturn result.map(item => ({ json: item }));\n"
      },
      "id": "8d1403ac-b48d-4992-b23e-557f94c1421c",
      "name": "Structure Output",
      "type": "n8n-nodes-base.code",
      "position": [
        -460,
        1220
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "// Get input data from n8n\nconst inputData = $input.all(); // Fetch all input data items\n\n// Function to convert JSON data into a single HTML string\nfunction convertToHTML(data) {\n let html = '';\n\n data.forEach((item) => {\n switch (item.json.type) {\n case 'paragraph':\n html += `<p>${item.json.content}</p>`;\n break;\n case 'heading':\n html += `<h2>${item.json.content}</h2>`;\n break;\n case 'list':\n html += '<ul>';\n item.json.items.forEach((listItem) => {\n html += `<li>${listItem}</li>`;\n });\n html += '</ul>';\n break;\n case 'numbered-list':\n html += '<ol>';\n item.json.items.forEach((listItem) => {\n html += `<li>${listItem}</li>`;\n });\n html += '</ol>';\n break;\n default:\n break;\n }\n });\n\n return html;\n}\n\n// Convert inputData to a single HTML string\nconst singleHTML = convertToHTML(inputData);\n\n// Return as a single item\nreturn [{ json: { html: singleHTML } }];\n"
      },
      "id": "6b47be39-35f8-46b3-9e90-7c6c1c891562",
      "name": "Conver to HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        -420,
        1420
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "fromEmail": "Fitness Coach <email@example.com>",
        "toEmail": "email@gmail.com",
        "subject": "=New Activity on Strava",
        "html": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "31d53845-6fdc-466b-b470-57466be1f94a",
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -60,
        1360
      ],
      "typeVersion": 2.1,
      "webhookId": "3d74a494-6929-4a61-baaa-57fa89b97db9"
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "id": "3d2668b7-ebac-49ad-b1f8-6484a92a7d25",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        -1360,
        1360
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "content": "### Custom AI Agent\nUsing advanced algorithms, it analyzes activity data from platforms like Strava and provides actionable insights tailored to the athlete’s goals, experience level, and specific disciplines.\n\nIt remembers the previous 10 workouts to give you more insights on your growth and performance\n\nChange system prompt accordingly.\n\n",
        "height": 589,
        "width": 444,
        "color": 7
      },
      "id": "4e068955-5ae6-41dd-a920-df9ecae0018f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1020,
        1100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Convert to HTML\nNow the data will be structured and covnerted to HTML",
        "height": 475,
        "width": 329,
        "color": 5
      },
      "id": "420fe533-6df9-4d1e-9859-c103122a0896",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        1100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Strava Trigger\nIf you are using Strava, you can create API Key by logging in to : https://developers.strava.com/\n",
        "height": 311,
        "width": 503,
        "color": 6
      },
      "id": "0f5ac474-bc26-44d5-8c1c-9ea0d6a3e74c",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1560,
        1220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Send Personalized Response\nActivity is analized you can either get the response by Whatsapp , emal, a blog or anything",
        "height": 655,
        "width": 609,
        "color": 4
      },
      "id": "ce22b0bb-92c6-4290-9a40-9cf92bb8fabe",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        1060
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "operation": "send",
        "additionalFields": {}
      },
      "id": "a8d548c0-3b72-4bda-8af5-dcb8848871f1",
      "name": "WhatsApp Business Cloud",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -60,
        1560
      ],
      "typeVersion": 1,
      "webhookId": "47ad9a24-eb52-411f-b19e-9378bad4e772"
    },
    {
      "parameters": {
        "model": "google/gemini-2.5-pro-preview",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        -940,
        1540
      ],
      "id": "211a9c61-7d25-4f6a-bd3d-1ac1629a1e1d",
      "name": "OpenRouter Chat Model",
      "credentials": {
        "openRouterApi": {
          "id": "Ozo28tMsGZsgu2pW",
          "name": "OpenRouter account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Combine Everything').item.json.data }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -800,
        1560
      ],
      "id": "1843593b-f3ce-46b3-8552-4ef746cf11f6",
      "name": "Simple Memory"
    }
  ],
  "pinData": {},
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Combine Everything",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fitness Coach": {
      "main": [
        [
          {
            "node": "Structure Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Conver to HTML": {
      "main": [
        [
          {
            "node": "Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Strava Trigger": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure Output": {
      "main": [
        [
          {
            "node": "Conver to HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Everything": {
      "main": [
        [
          {
            "node": "Fitness Coach",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fitness Coach",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Fitness Coach",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "add148e1-3c94-4fcd-87a8-8e3f2fd1d3b8",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d21ead83680689d690a8650e463fc3d233db795a4a97d0a8d8ad1b8ad409fdc5"
  },
  "id": "AR9bBEAogb8IBrpy",
  "tags": [
    {
      "createdAt": "2025-05-20T13:50:55.061Z",
      "updatedAt": "2025-05-20T13:50:55.061Z",
      "id": "mxfXOOd0QdWyCkTB",
      "name": "AI agent"
    },
    {
      "createdAt": "2025-05-20T13:50:55.073Z",
      "updatedAt": "2025-05-20T13:50:55.073Z",
      "id": "omV3EolmMwcdCyZX",
      "name": "IN PROGRESS"
    }
  ]
}

Need help implementing or selling this?

Get a free consultation and we'll guide you through the implementation and business side of this AI Agent.