Cost Budget Auto-Stop
TheCostTracker now checks budgets after every tool roundtrip, not just before the loop starts. This prevents a multi-roundtrip agent from blowing through its budget.
How It Works
When acostTracker is configured on an agent, the onRoundtripComplete loop hook automatically:
- Tracks incremental token usage after each roundtrip
- Checks if any budget limit is exceeded
- If exceeded, gracefully stops the LLM loop and returns the last assistant message
Configuration
New CostTracker Methods
Behavior
| Scenario | Before | After |
|---|---|---|
| 10-roundtrip loop, budget hit at roundtrip 3 | Budget only checked before loop | Loop stops at roundtrip 3 |
| Cost tracking | Only after full loop completes | Tracked incrementally each roundtrip |