Lesson generator cut 22 model calls to 2-5, dropping cost from $0.28 to $0.14 per lesson
Gleb_SV · reddit · 2026-10-20
A follow-up on optimizing a multi-agent lesson generator (planner/builder/checker/fixer producing 5 interactive files per lesson):
Before (open-ended agent loop)
- 22 model calls per run (4 planning, 18 building), 662k input tokens, 74% cache hit
- Uncached input was the biggest cost (42%), then output 24%, reasoning 21%, cached input 12%
- Every call re-sent 30k tokens of context; 45-60% of each build call was identical static instruction text
- $0.28 per lesson over 20 accepted runs, median 4 minutes
After (one job, one call)
- Planner: one structured JSON call, with a repair call on schema failure (1 in 3)
- Builder: one streaming call emitting all 5 files in a tagged format, parsed as each file closes
- Checker: static checks only, no model call; lessons also rendered in a headless browser
- Fixer: small patches only when flagged
- Result: 2-5 calls per lesson; latest round 6/6 passed, averaging $0.144 and 3 minutes; first production run $0.13 in 2 minutes
Two surprises
- A 74% cache hit rate hid the real problem—the loop kept re-sending the same context; cutting call count is what moved cost
- Capping the planner's thinking budget cut time-to-first-token from 36s to 3s and that call's cost by 35% (only 3 runs, grain of salt)
The author asks: when is an agent loop actually worth it, and has anyone kept a loop and made it cheap?
More from coding & agent
- Proof of Agent: an experimental network where AI agents mine, grade and self-govern — adamamcbride · 2026-10-20
- Supabase monitoring tool drops table limit — free plan now watches unlimited tables — santiviquez · 2026-10-20
- Dev's disk-saving trick: purge old git worktrees to reclaim 70% of disk space — intellectronica · 2026-10-20
- Claude Code ships a --tmux flag for built-in terminal pane layouts — wateriscoding · 2026-10-20
- DeepLearning.AI launches free Context Engineering course with Chroma to fight Context Rot — DeepLearningAI · 2026-10-20
- Dev who shipped 100+ apps lays out step-by-step path to building your first AI app — PrajwalTomar_ · 2026-10-20