Agent cost control
Cost scales with tokens processed, and most waste is context that was never needed. Controlling it is mostly about what you send rather than about using a weaker model.
Method
- Reduce context before reducing model. Trimming irrelevant files preserves quality while cutting cost; a weaker model may not (see context-compression).
- Use prompt caching for stable prefixes. Instructions and reference material that repeat across turns can be cached at substantially lower cost (see prompt-caching).
- Match the model to the task. Routine mechanical edits do not need the strongest model, while architectural work does (see agent-progressive-disclosure).
- Start fresh sessions for new tasks. Continuing in a long session carries the entire history into every subsequent turn.
- Avoid re-reading unchanged files. Repeated reads of the same large file across a session are pure duplication.
- Bound autonomous loops. An agent iterating without a cap can consume a large budget on a task it cannot complete (see agent-loop-until-exhausted).
- Measure cost per task, not per token. A more expensive model finishing in one pass often costs less than a cheap one iterating five times.
Boundaries
Cost optimisation must not compromise verification on consequential work (see agent-human-checkpoint). Pricing and caching behaviour differ by provider and change. The engineer's time is usually more expensive than the tokens, which bounds how much optimisation is worth.