feat(agentloop): Token-/Kosten-Budget mit Hard-Cap (issue #151) - #228
Conversation
What ships:
- cmd/sin-code/internal/agentloop/loop.go:
- New Completion.Usage + Usage struct (PromptTokens, CompletionTokens, TotalTokens).
- New Loop.MaxTokens field: 0 disables (backwards-compatible).
- New Loop.BudgetWarnRatio field: fraction of MaxTokens that fires hooks.BudgetWarn.
- Token accumulator state (totalTokens, warnedBudget).
- Budget check after appending msgs: if total >= MaxTokens, fires
BudgetExhausted + records TypeTokenBudgetExhausted + either
returns an error or a checkpointed Result (AllowContinuation).
- cmd/sin-code/internal/ledger/store.go: new EntryType TypeTokenBudgetExhausted.
- cmd/sin-code/internal/hooks/hooks.go: new events BudgetWarn, BudgetExhausted.
- cmd/sin-code/internal/agentloop/loop_token_test.go: 3 tests
(disabled, exhausts, allow-continuation).
Acceptance criteria (from #151):
- [x] MaxTokens caps cumulative tokens across the run.
- [x] MaxTokens=0 disables the guard (legacy behavior).
- [x] BudgetWarnRatio fires hooks.BudgetWarn once when crossed.
- [x] AllowContinuation converts the cap into a checkpoint.
- [x] go test ./cmd/sin-code/internal/agentloop/... all green.
Hard mandates honored:
- M2: no new deps.
- M3: token accounting is post-verify; never short-circuits the gate.
- M7: 3/3 tests pass under go test -race -count=1.
Refs: #151
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed with the following error: Learn More: https://vercel.com/ronaldokrause-9559s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/einskarst-2238s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/karstenblau45-2395s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/sagamundis-1139s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/aragonheld-7756s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/mariobatrhs-9606s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/cristianoronalodbau-9053s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/spriterfrau-5830s-projects?upgradeToPro=build-rate-limit |
|
Deployment failed with the following error: Learn More: https://vercel.com/manheiler-8784s-projects?upgradeToPro=build-rate-limit |
🏆 CEO Audit — A+ (100.0/100)
📥 Download full report (Markdown)
|
🏆 CEO Audit — A+ (100.0/100)
📥 Download full report (Markdown) Run ID:
|
| TypeStallDetected EntryType = "stall_detected" | ||
| // TypeTokenBudgetExhausted is recorded when cumulative token usage exceeds | ||
| // MaxTokens and the run stops spending (issue #151). | ||
| TypeTokenBudgetExhausted EntryType = "token_budget_exhausted" |
Implements issue #151. MaxTokens + BudgetWarnRatio + Completion.Usage.
Closes #151