# I made an AI health coach agent 15x cheaper.

The agent turns a blood test into a personal diet and workout plan. Now rules make the decisions and AI only writes.

Aditya Kumar, Founding Software Engineer. He built it alone, including the quality checks and stress tests.

## What the AI costs for one plan

- First version: $0.83
- Today, on Gemini: $0.14
- Cheaper GLM 5.2 model, same quality: $0.054

## Results

- **15x** lower AI cost for each plan, from $0.83 down to $0.054
- **780** plans an hour from one small server
- **0** plans lost when 100 patients sent their forms in the same minute
- **505** sample questionnaires the rules are tested on
- **1,000+** diet and workout plans made so far

## A diet and workout plan in minutes, built from a blood test

Labs offer the agent to patients after their blood test.

1. **Patient fills a short form:** goals, food habits, daily routine, and the blood report from the lab.
2. **Rules make the decisions:** they work out daily calories, find results out of range, and shortlist the diet styles that fit. Same answer every time.
3. **AI writes the plans:** it writes all four PDFs, stays inside the limits the rules set, and runs on a smaller, cheaper model.
4. **Sent on WhatsApp:** diet plan, workout plan, Habit Guide and Food Guide, each as a PDF.

A lab with 100 patients a day would have paid about $2,490 a month in AI fees. Now it pays $416, or $160 with the cheaper model.

## The first version used AI for six jobs. Most of them didn't need it.

That made each plan cost $0.83, and running it twice for the same patient could give two different plans.

| Job | First version (six AI calls, $0.83) | Rebuilt (three AI calls, $0.14) |
| --- | --- | --- |
| Calorie maths | AI double checked each patient's calorie numbers and explained its working. | Rules: now a simple formula. It costs nothing and answers instantly. |
| Diet approach | AI read through every diet style, and sometimes made up a new one. | Rules shortlist the diet styles that fit. AI picks one from that list, and any other answer is rejected. |
| Methods | AI picked the habits and diet methods, and wrote a reason for each. | Rules: now chosen from the patient's answers and blood results. |
| Care summary | AI wrote the patient's whole care story, about 13,000 characters. | Removed. Each step gets the patient's facts straight from the rules. |
| Meal plan | The biggest, most expensive model wrote a 7 day plan. | A smaller model writes it, inside the numbers the rules set. |
| Documents | Nine separate AI calls, each sending the same patient details again. | One AI call writes the workout plan, the Habit Guide and the Food Guide. |

With the cheaper GLM 5.2 model, the same plan costs $0.054.

## Why it was built this way

**Rules for decisions, AI for writing.** Even a cheaper AI can give the same patient two different plans. Rules give the same answer every time, and they can be tested. The rules are tested on 505 sample questionnaires.

**Smaller models, once the rules were in place.** With rules setting the numbers, the meal plan no longer needed the biggest model. The cheaper GLM 5.2 model ran on 100 patients at $0.054 a plan. In a separate check, a second AI compared its plans with the top model's plans for the same patients (the "LLM as a judge" method), and they matched.

**Let a rush wait in line.** The server makes two PDFs at a time on purpose. When many patients arrive at once, they wait a few extra minutes and nothing breaks.

## 100 patients in one minute. Every plan delivered.

A stress test ran on a copy of the live server, a small machine with two processors. 100 test patients sent their forms in the same minute.

- First plans arrived after 6.8 minutes, 50 by 10 minutes, 90 by 13 minutes, and all 100 by 14.1 minutes.
- Once busy, the server finishes about 13 plans every minute: **780 plans an hour** at full speed.
- The server never used more than about a ninth of its memory.

100 patients in one minute is as many as a typical small lab sees in a whole day.

## One server is enough for about 90 typical labs

Patients a day, next to how many plans one server can make in a 12 hour day:

- Standalone lab (most labs in India): 100 patients a day
- Medium lab: 400 patients a day
- Regional chain (1.1M patients a year): about 3,100 patients a day
- One server, 12 hour day: 9,360 plans a day

India has more than 1.3 lakh diagnostic labs, and most of them are small, single labs. Bigger chains need more servers: the largest national chain would need about nine.

## Built with

Python, FastAPI, Gemini on Vertex AI (Google Cloud), MongoDB, Playwright, the WhatsApp Cloud API and Claude Code.

## Method notes

Costs come from the AI providers' token counts, shown in US dollars. Load tests ran on a copy of the production server. Lab sizes: Primedeq (https://www.primedeq.com/blog/equipment-planning-for-small-and-medium-pathology-lab/) and CareEdge (https://www.careratings.com/uploads/newsfiles/1699261512_Indian%20Diagnostics%20Industry_CareEdge%20Report.pdf).
