Rules: Budget
Иерархия бюджетов для контроля расходов на LLM и tools.
Иерархия бюджетов
System daily budget ($50)
└→ Per-agent daily budget ($3-$10)
└→ Per-task budget ($0.3-$10)
└→ Per-tool-call limits
Каждый уровень enforce’ится независимо. Превышение любого → блокировка.
System Budget (MVP defaults)
| Параметр | Значение |
|---|
| Daily | $50 |
| Monthly | $1,000 |
| Alert threshold | 80% → Telegram notification |
| Hard stop | 100% → все pending ждут human reset |
Per-Agent Daily Budget
| Agent | Daily limit |
|---|
| Agent-CEO | $10 |
| Directors (each) | $8 |
| Executors (each) | $3 |
| Cross-cutting (Judge, Librarian) | $5 |
Per-Task Budget
| Task type | Default cost limit |
|---|
| Simple (classification, formatting) | $0.30 |
| Standard (research, analysis) | $1.00 |
| Complex research (multi-agent) | $3.00 |
| Deep research (full pipeline) | $10.00 |
Задаётся в budget_usd при создании task. Наследуется от parent если не указан.
| Tool | Max per task |
|---|
web_fetch | 50 |
web_search | 20 |
memory.write | 100 |
embedding.generate | 200 |
Time Budgets
| Task type | Soft limit | Hard limit |
|---|
| Simple | 2 min | 5 min |
| Standard | 10 min | 30 min |
| Research | 30 min | 2 hours |
| Deep research | 2 hours | 6 hours |
Hard limit превышен → status = 'failed' + escalation.
Token Budgets
| Agent type | Max tokens per task |
|---|
| CEO | 100,000 |
| Directors | 80,000 |
| Executors | 30,000 — 50,000 |
| Judge | 20,000 |
Включает input + output + tool responses.
Enforcement
Real-time Tracking
Policy Engine проверяет до каждого LLM call:
# Redis tracking running totals
budget = redis.get(f"budget:{task.id}")
if budget.tokens_used >= task.budget_tokens * 0.8:
# Inject warning into agent context
context.append("⚠️ You have used 80% of your token budget. Be concise.")
if budget.tokens_used >= task.budget_tokens:
# Hard stop
task.status = 'failed'
task.error = 'budget_exceeded'
escalate(task)
Overrun Handling
| Событие | Реакция |
|---|
| Первое превышение | Warning + escalation |
| 3 превышения / 24ч от одного агента | Agent frozen до review |
| System daily 80% | Telegram alert |
| System daily 100% | Emergency mode |
Emergency Mode
Когда daily cap достигнут:
- Только
priority = 0 задачи выполняются (critical/human-requested)
- Все остальные → очередь до 00:00 UTC reset
- Telegram уведомление: “Daily budget exhausted. Only critical tasks processing.”
- Human может override: увеличить budget или approve specific tasks
Budget Reviews
| Цикл | Содержание |
|---|
| Daily | Автоматический отчёт: spent vs budget, top consumers |
| Weekly | Cost per task type + trends, anomalies |
| Monthly | Review defaults, adjust based on real data |
Связанные документы