Cost Control
Practical strategies for controlling agent costs — budgets, model selection, and monitoring.
Strategy 1: Set Budget Limits
Always set explicit limits:
budget: {
maxCostUsd: 1.00, // Hard cap
maxTokens: 100_000, // Token cap
warnThreshold: 0.7, // Warn early
},Strategy 2: Choose the Right Model
| Task | Recommended Model | Relative Cost |
|---|---|---|
| Simple queries | Claude Haiku / GPT-3.5 | $ |
| Standard tasks | Claude Sonnet / GPT-4o | $$ |
| Complex reasoning | Claude Opus / GPT-4 | $$$$ |
// Use Haiku for simple tasks
const cheapLLM = createLLM({ provider: 'anthropic', model: 'claude-haiku-4-5-20251001' });
// Use Sonnet for standard tasks
const standardLLM = createLLM({ provider: 'anthropic', model: 'claude-sonnet-4-20250514' });Strategy 3: Limit Steps
const agent = defineAgent({
// ...
maxSteps: 5, // Prevent runaway loops
});Strategy 4: Monitor with Hooks
hooks: {
onStep: (step) => {
metrics.recordTokenUsage(step.tokens.input + step.tokens.output);
},
onComplete: (result) => {
metrics.recordRunCost(result.trace.summary.estimatedCostUsd);
},
},Strategy 5: Escalation Thresholds
policy: {
costEscalationThreshold: 0.50, // Human review at $0.50
},Strategy 6: Multi-Agent Budget
const coordinator = new Coordinator({
agents: { researcher, writer },
budget: {
maxTotalCostUsd: 3.00,
maxCostPerAgent: 1.50,
},
});Next Steps
- Budget Governor — budget API
- Cost Models — per-model pricing