Skip to content

The coach

The coach is an AI agent in the app. It reads the training of a person through the same tools as the MCP server, so it sees nothing that the person cannot see. It explains progress with charts, builds routines and programs, imports a workout history that is attached to a message, and checks in on its own. It stays off until you give it a model.

When a person is in the middle of a workout, the coach knows it. It sees which exercise the person is on, which sets are done and what is left, so it can answer “how many sets do I have left?” at once. When the person asks what weight and reps to do, the coach shows today’s sets on a card. Apply puts the numbers on the sets that are still to do, and the sets that are done stay as they were logged. “Suggest weight and reps” in the options of an exercise asks this question, and the answer opens in a sheet over the workout. Anything else in a running workout, such as another exercise, the person changes in the app.

The coach runs on OpenRouter. Create a key, put a spending limit on it, and store it as a secret:

Terminal window
cd apps/web
npx wrangler secret put OPENROUTER_API_KEY

Without a key, the Coach tab and the coach section of the landing page stay hidden, and the app starts on the Workout screen. With a key, the Coach is the first place in the app and its start: /app opens a new conversation, with the next workout and its Start button on top, and the Workout screen moves to /app/routines. A new account starts on the coach too. When a person asks what to train, the coach shows the routine on a card with Start. Any OpenRouter model that supports tool calls works. For photos, the model must also accept images. AGENT_MODEL picks the model.

The credit of the person who asks pays for each answer. You decide how much credit each person starts with. A new account gets AGENT_CREDIT_START_MICRO with its first message. A guest gets the smaller AGENT_GUEST_CREDIT_START_MICRO, which is enough to try the coach. The amounts are in micro-USD: 1,000,000 is one dollar.

An answer costs what OpenRouter reports for each call it makes, including prompt-cache discounts. gymgym puts each call on the answer as the call ends. If something cuts the answer off, it has still paid for what it used.

When someone stops an answer, OpenRouter still bills the call that was running. A call that is cut off does not send its cost, so gymgym asks for it later. About a minute after, a cron job reads OpenRouter’s record of the call and adds the cost to the answer. This job needs the cron trigger that the wrangler.jsonc in the repository has.

A voice message costs what the model that hears it costs (TRANSCRIBE_MODEL). It is a charge of its own on the same credit. When there is no credit left, the coach does not hear it.

When the balance reaches zero, the coach says so and does not call the model. An answer that would cost more than AGENT_TURN_MAX_MICRO stops where it is.

In the admin dashboard, open a person and use “Coach credit” to change the balance. Enter an amount from -100 to 100 dollars. A negative amount takes credit off. The dashboard also shows what the coach spent today, over the last seven days and in total, and the recent charges of each person. The same page lists the conversations of the person (see Where the data goes). The totals include people who are gone: when an account is deleted, what it spent stays in the totals, with no name, so they stay close to your OpenRouter bill. To become an admin, read Admins and invites.

These are plain settings. Put them in the vars block of apps/web/wrangler.jsonc.

Setting Default What it does
AGENT_MODEL anthropic/claude-haiku-5.5 The OpenRouter model
TRANSCRIBE_MODEL google/gemini-3.1-flash-lite The model that turns voice messages into text. It must accept audio
AGENT_CREDIT_START_MICRO 1000000 The credit that an account starts with ($1)
AGENT_GUEST_CREDIT_START_MICRO 50000 The credit that a guest starts with ($0.05)
AGENT_TURN_MAX_MICRO 50000 The most that one answer can cost ($0.05)
AGENT_GUEST_DAILY_LIMIT 10 Messages a day for a guest
AGENT_DAILY_LIMIT 50 Messages a day for an account with no credit left
AGENT_FUNDED_DAILY_LIMIT 200 Messages a day for an account that still has credit (never below AGENT_DAILY_LIMIT)

The wrangler.jsonc in the repository has the values of gymgym.club for the starting credits, the funded limit and the prompt cache. Change them to what you want to spend before you let other people in.

Setting Default What it does
AGENT_PROMPT_CACHE on, one hour Marks the fixed instructions of the coach, so Anthropic models read them from their prompt cache at a tenth of the price. 5m keeps them for five minutes. This is cheaper to write and better for little traffic. 0 turns the cache off. Other providers cache a repeated prefix by themselves
AGENT_TOOL_TIMEOUT_MS 30000 A tool call must finish in this time, or it fails in view of the person
AGENT_MODEL_TIMEOUT_MS 90000 One model call must answer in this time
AGENT_TURN_BUDGET_MS 150000 A whole answer, with all its model calls and tools, must finish in this time
AGENT_TURN_MAX_OUTPUT_TOKENS 60000 The most that the model can write in one answer
AGENT_HISTORY_MAX_TOKENS 6000 How much of a conversation goes to the model word for word. Older messages become a few lines
AGENT_PRICE_INPUT_MICRO, AGENT_PRICE_OUTPUT_MICRO built in Micro-USD for each prompt token and each completion token. If you set either one, gymgym charges answers at these prices and ignores the cost that OpenRouter reports

Some changes happen at once: logging sets or body weight, adding an exercise of the person’s own, and changing settings. The coach shows other changes as a card. These are new programs and routines, corrections to logged workouts and every deletion. A card changes nothing until the person presses Apply.

The coach knows what happened to its earlier cards. When the person writes, the app adds a short note for the coach: the cards of the last answer and what the person did with them (applied, discarded or not yet). The person does not see the note. The coach never writes a note of its own. If it does, the app removes it from the answer and asks the coach once to make the card it meant.

A Durable Object makes each answer, one for each conversation. The answer goes on when the person closes or reloads the page, and the person can stop it.

Before the coach builds a program, it asks for what it does not know yet: the goal, the experience, the days and the minutes for each session, the equipment and any injuries. Then it sets the numbers with rules from sports research. The Sources page lists every study and guideline behind them, each linked to PubMed.

  • The goal sets the reps and the rest. For muscle, most sets have 6 to 12 reps. Sets of 5 to 30 reps also build muscle if they stop 1 to 3 reps before failure. Thus, with light equipment, the coach gives more reps. The rest is 2 to 3 minutes after big lifts and 1 to 2 minutes after small ones. For strength, the main lifts get 3 to 6 reps and 3 to 5 minutes of rest. For health and endurance, sets have 10 to 20 reps and shorter rests. Sets to failure are not necessary. The rest of each exercise comes from the rules in Warm-up and rest.
  • Volume. A beginner gets about 10 hard sets for each muscle in a week. A trained person gets 10 to 20. Each muscle works at least twice a week. The number of sets fits the minutes that the person has.
  • Progress. Most routines use double progression. The reps go up to the top of the range in each set, and then the weight goes up by the smallest step. Every 4 to 8 weeks, or when progress stops, the coach plans an easier week.
  • Each exercise has its numbers. A card from the coach shows the sets, the reps or a time, and the rest. A new routine must give a rest for every exercise except cardio. An exercise with equipment also has a starting weight. The coach takes it from the last workout. If the person gives a maximum, the coach calculates a part of it. For example, 3 × 8 with 2 reps in reserve on a 100 kg bench press starts at about 75 kg. With no data, the coach picks a careful weight and tells the person to adjust it after the first set. If a card has no weight for an exercise with equipment, has no rest, or has another mistake in it, it goes back to the coach. The person sees the card only when it is complete.
  • Rest. The rest is different for each exercise. It is longer for a heavy lift with many joints and for sets of few reps, and shorter for work on one joint and for sets of many reps. It is also longer when a set ends near failure. The rest changes a little with the person: a beginner rests less, a woman rests a little less between moderate sets, and a person past 60 or in a pregnancy rests more. The coach asks the exercise_guide tool for the numbers of each routine, and it adds the rest when it gives a weight and reps. The rule for each number, and the research for it, are in Warm-up and rest.
  • Warm-ups. The first heavy lift of a routine gets 2 or 3 warm-up sets. A heavy lift uses many joints and a big load, such as a squat, a bench press or a leg press. A second heavy lift that moves in another way gets 1 or 2 sets, for example a deadlift after a row, because the first lift did not warm up that movement. A routine has five warm-up sets at most. The coach gives only the number of sets. The app plans them as a ramp toward the first work weight, at about 50, 75 and 87.5 % of it with fewer reps each time, and one set is 75 % for 5 reps. It fills in the weights on the day. A person past 60 gets one more set, a beginner and a person in a pregnancy get two at most, and a lift that loads a place that hurts gets one more, lighter set. Warm-up sets do not count as sets of the routine, and they do not count for volume, records or progression. Work on one joint, such as curls and raises, gets none. Body weight, holds, cardio and light work get none too, and neither does a routine that is a warm-up or a cool-down. A routine that the coach builds from your history keeps the warm-ups that you logged. In a workout, in the history and in the routine editor, you can mark any set as a warm-up. Research says that a warm-up helps, and that a set near the work weight (about 80 %) helps more than light sets only. It does not say how many sets are best. Coaches use 2 or 3.
  • Supersets. The coach uses supersets to save time, when the person is short of minutes or asks for them, and not to build more muscle: the research shows the same muscle and strength with the same sets in a third to a half less time. It pairs opposing muscles first, for example a bench press with a row or a curl with a pushdown, and an upper-body exercise with a lower-body one second. It does not pair exercises for the same muscles, and it keeps heavy lifts at 6 reps or fewer, the main lifts of a strength goal and two heavy leg lifts as straight sets. The exercise_guide tool reviews each pair, gives the rest, and lists the pairs that a routine could make. The person can make a superset in the app in the routine editor or in a workout: tap ⋯ on the first exercise and choose Superset with next. The rules and the research are in Supersets.
  • Replacements. When an exercise must change, the coach asks the exercise_alternatives tool. It lists exercises that train the same main muscle with the same kind of movement, with the equipment of the active equipment profile. If a place hurts, the exercises that spare it come first. The coach picks two or three, says what is the same and what is different, and puts the new exercise in the routine with a card.
  • Exercises that are not in the library. The coach adds them as exercises of the person, with a short description in the language of the person: how to start and two or three points about the form. The description has no sets, reps or weights, because the routine has them. The exercise sheet shows the description.
  • Where you are in your training. The coach knows the date, the weekday and the time where you are. When you start a workout, it reads the rhythm of your last weeks: the days since your last workout, the workouts of each week and the number of full weeks in a row with no easy week. A week is easy when its load is 70 % or less of the three weeks before it, and a week with no workout is a break. After a break of two weeks or more, the coach starts you lighter: about 10 % after two to four weeks, 20 % after five to eight weeks and more after longer, with 3 reps in reserve for the first sessions. After eight full weeks in a row with no easy week, it asks how you feel and offers an easy week. It is an offer and never a rule, because research does not show that a lighter week is needed. If you say yes, the coach makes a folder of routines with the same exercises, about 60 % of the sets and 90 % of the weights, marked as a light week. You can delete the folder after the week. The coach says all this once in a conversation and never after a no.
  • Tips. When the numbers do not say everything, the coach adds a short tip to an exercise in the routine, for example “down to a box, where the knee does not hurt” or “1-second pause on the chest”. The workout shows the tip above the sets. The person can change or remove it in the routine editor.
  • Why each exercise has its numbers. The coach writes a reason for every exercise of a new routine: one or two sentences about why the exercise has these sets, reps and rest for the person. The reason is saved with the exercise. When the person asks, for example, why an exercise has two sets, the coach reads the reason and answers from it. In a workout, the coach reads the reason of the routine that the workout came from. The app does not show the reason in a workout, because the tip is for that. If the person changes the sets, the reps or the rest of an exercise, the app removes the old reason, because it no longer fits. The coach writes a new reason when it changes those numbers. A routine from before this feature has no reasons. The coach says so, and it gives its own view as a suggestion and not as what was planned.
  • Only the equipment of the person. The coach counts all the equipment that an exercise needs. For example, a dumbbell bench press also needs a bench. The coach never gives a weight that is heavier than the equipment.
  • Who the person is. People can tell the coach their sex, year of birth, height and weight in About you. The app asks it on the first visit. If they put it off, it asks once more on a later day. They can change the answers in Settings, under About you, and they can also tell the coach in the chat. These answers do not change the reps, the sets or the progression, because women build muscle and strength at the same rate as men for where they start. They change where a plan starts and what it leaves out, and a little the rest and the warm-up sets. With no history and no max, a woman starts lighter, most of all on upper-body lifts. A person past 60 starts carefully and gets a balance exercise in every routine except a warm-up or a cool-down. In a pregnancy, the coach keeps the effort moderate and leaves out exercises that lie flat on the back and jumps. After a baby, it starts with the pelvic floor and deep core. After menopause, it plans heavy strength work and some impact for the bones. The coach plans nothing around the menstrual cycle. In a language that marks gender, such as Russian, the coach speaks to the person in the form their sex calls for: «ты прав» to a man, «ты права» to a woman. If the sex is not given, it words the sentence so that no form is needed. If the person writes about themselves in a form, such as «я устала», it uses that form. Each coach character also keeps one gender for itself in every answer. A card that lies down or jumps in a pregnancy, or a new routine with no balance exercise past 60, goes back to the coach before the person sees it.
  • Injuries. The coach removes the movements that hurt. It replaces them with movements that do not hurt and that train the same muscles, and it keeps training the area. For example, a person with sore knees gets box squats to a depth with no pain, step-ups and wall sits, but no deep lunges and no jumps. The coach tells the tools which places hurt (neck, shoulder, elbow, wrist, lower back, hip, knee or ankle). The exercise_guide tool marks the exercises that load them, and the coach replaces those or keeps them to a range with no pain. Mild discomfort is acceptable if it is 3 of 10 or less and goes away by the next day. The coach does not diagnose. If pain is new, sharp or gets worse, the coach tells the person to see a doctor or a physiotherapist first.
  • Where the numbers come from. When the person asks what a number or a rule is based on, the coach calls the method_sources tool. The tool returns studies and guidelines from the Sources page, each with its PubMed link. The coach says what the research shows and where it is thin, and it gives a few of the links. It cannot cite a study that is not on that page, because the tool, the docs page and the landing page read the same list.

gymgym stores conversations, proposals and the facts that the coach remembers in D1 with the rest of the account. They are deleted with the account. The coach sends messages, and the account data that it reads to answer them, to OpenRouter and to the provider of the model. This data includes what the person gave in About you: sex, year of birth, height and, for a woman, a pregnancy, a baby in the last year or menopause. Tell the people who use your instance.

An admin of your instance can read the conversations of a person. In the admin dashboard, open the person and look under Conversations, or open a day of the list of what the coach spent to see the conversations of that day, from every person (a day in UTC, as the list counts it). A conversation that is gone (its person deleted it, or their account) is not on that list, though what it cost stays in the total of its day. The page of the day counts those answers in a line under the list, so a day that the spending list shows with answers and no conversation says why. The admin sees what the person wrote, what the coach did and answered, each card as it ended (a proposal applied or discarded) and what was recognised in a voice message. The admin never sees photos: gymgym serves them to their owner only, and the admin sees only that a photo was sent. Each time an admin lists the conversations of a person, or of a day (one row for each person on the list), or opens one, gymgym writes a row in the audit log (list_conversations, read_conversation) with the admin, the person and the conversation. Separately, gymgym records that a message was sent (with how many photos and files it had, never the words) as an activity event.

People can send photos (up to four in a message). gymgym shrinks them, strips their metadata and stores them in the R2 bucket under agent/<conversation>/. It deletes them with the conversation or the account. A voice message can last up to three minutes. TRANSCRIBE_MODEL turns it into text as soon as it is recorded. The sound goes to OpenRouter for that, and gymgym never stores it. If OpenRouter does not answer within 45 seconds, gymgym gives up and the person can record the message again.

With Web Push set up, the coach can write first. Nothing is on by default. A person turns on the weekly review and the nudge after a few days without a workout in Settings. The coach can also offer one in a chat, as a card with a Turn on button. It does this only after it has helped with something, never in a first reply, once in a conversation, and never again after a no. A person can also ask for a reminder in a chat. Each one waits until the person taps Turn on. Check-ins go out in the time zone of the person and never between 22:00 and 08:00. They count toward the messages of the day.

For local development, set AGENT_MOCK=1 in .dev.vars. The coach then uses a scripted model that repeats what it hears, so you can try the screens without a key. Use it for development only.