Per-bot spending limits and alerts

Aperta
#210 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start by reading docs/guide/llm-call-ledger.md and crates/agent-core/src/usage.rs, then trace how max_tokens_per_turn is enforced in crates/agent-core. The issue requires agreeing on budget units, periods, scope, unknown usage, stop behavior, and concurrency before implementation; done means an agreed design and the listed backend, alert, UI, localization, schema, and test criteria are met.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: daemon area: desktop-ui enhancement help wanted needs design

size: L · first-timer: no

Please comment before starting so we can agree on the design. What counts as "spend", and what happens when the limit is hit, need to be decided first.

Summary

Add per-bot spending limits and alerts: an optional daily or monthly cap on a bot's model usage (cost where known, tokens otherwise) with a warning threshold, a clear stop behaviour, and visible meters in the app.

Why it matters

Always-on bots and schedules can burn through an API budget while nobody is watching. Users already see what was spent after the fact; they have no way to say "this bot may spend at most this much a month". That is a prerequisite for trusting a bot with unattended work.

Current state

  • Every model call is recorded in the LLM call ledger with a purpose, tokens and optional cost_usd (crates/agent-core/src/usage.rs, docs/guide/llm-call-ledger.md). GET /v1/usage aggregates by bot and purpose; the UI shows it in apps/desktop/ui/src/views/UsageView.tsx.
  • Limits exist only per turn: guards.max_tokens_per_turn in crates/agent-core/src/config.rs, and a subagent gets a quarter of what its parent has left (crates/agent-core/src/subagent.rs). There is no per-bot, per-day or per-month limit and no alerting.
  • Cost can be unknown: tokens may be missing (failed calls, embeddings), CLI engines expose one session invocation rather than token counts, and prices come from the current provider catalog entries (with_catalog_prices in crates/agent-core/src/shared.rs, overridable through LoopConfig::prices). The ledger doc is explicit that unknown tokens do not mean zero.
  • Bot profiles are TOML/JSON profiles with sections such as [router] and [runtime] (docs/guide/bots-and-profiles.md).

Proposal and suggested approach

Settle these in a design note first:

  • the unit (money vs. tokens vs. calls) and how unknown costs are handled so a limit cannot be bypassed by missing data;
  • the period and timezone (rolling 24 h/30 d or calendar day/month);
  • scope (per bot, global, or both) and what includes subagents, scheduled runs and background memory work;
  • the stop behaviour: refuse new runs, stop the current run at the next model call, or ask the user once to continue;
  • concurrency (two runs reading the same remaining budget).

Then implement in slices:

  1. A [budget] section in the bot profile (and an optional global default) with validation and tests.
  2. A budget check in the agent loop before each model dispatch, reading from the ledger; the failure is a typed, human-readable error code (add it to the human-error layer in both locales).
  3. Events and alerts: a warning at a configurable threshold and a hard-stop event; show them as a banner/toast and send them to Telegram if configured.
  4. UI: a meter per bot in the usage view and the bot panel, and fields in the bot editor.
  5. Tests with a fake provider that reports usage, including unknown-usage calls and concurrent runs.

Follow the migration rules in CONTRIBUTING.md if storage changes (numbered, forward-only, check open pull requests for the number).

Acceptance criteria

  • Design note agreed in this issue.
  • A bot with a tiny limit stops with a clear message instead of silently continuing; a bot without a limit behaves exactly as before.
  • Unknown-cost calls are handled according to the agreed rule and covered by tests.
  • Usage UI shows remaining budget; check:i18n, lint, typecheck, cargo test -p agent-core -p daemon-api pass; OpenAPI snapshot and generated schema updated.

Out of scope

Billing integrations, real-time provider balance lookups, per-chat limits, changing prices or the catalog.

How to get started

Read docs/guide/llm-call-ledger.md and crates/agent-core/src/usage.rs, then look at how max_tokens_per_turn is enforced in crates/agent-core. Comment here with your proposed answers to the design questions.

Lingua principale
Rust
Stelle
0
Fork
1
Merge medio
6h 54m
PR unite (30g)
152

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emreocell/Praxi-Bot

Tutte le issue di emreocell/Praxi-Bot

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.