Repository navigation
Commit ff10d2b
authored
feat: add token budget circuit breaker and session log to agent loop (#245)
**Key Changes:**
- Introduced token budget circuit breaker to halt agent loop when
cumulative input/output token limits are exceeded
- Added append-only JSONL session log for crash recovery and debugging
- Enhanced context compaction with proactive and reactive trimming and
semantic recap
- Exposed new configuration options for budget, logging, and prompt
cache through environment variables
**Added:**
- Token budget enforcement (`BudgetConfig`) that ends loops with
`BudgetExceeded` reason when input, output, or total token budgets are
reached; configurable via env vars
- Append-only JSONL session log (`SessionLog` and `SessionLogConfig`)
that records all conversation events, tool results, usage stats, and
outcomes for each agent loop in a crash-tolerant manner
- Proactive context compaction logic, including semantic recap of
trimmed messages, with configurability for compaction cadence and
thresholds
- New public exports for session logging and budget configs in agent
loop modules and library root
**Changed:**
- Agent loop runner now checks token budgets each iteration and exits
early if limits are exceeded
- Context compaction upgraded to support both proactive
(threshold-based) and reactive (hard ceiling) trimming, with detailed
logging and semantic recaps of dropped content
- Anthropic provider now attaches prompt-cache breakpoints to
system/tool blocks when enabled, improving cache hit rates and
efficiency
- Configuration loading for agent loop now layers environment variable
overrides on top of defaults for agent, context, budget, and session log
settings
- All agent loop terminal paths (success, error, budget, assistance) now
consistently log outcomes to the session log if enabled
**Removed:**
- Previous static context trimming that lacked proactive compaction and
semantic recaps
- Unused or redundant context compaction code paths in favor of unified
`maybe_compact` and semantic recap mechanism1 parent 53ca3c9 commit ff10d2b
19 files changed
Lines changed: 1702 additions & 157 deletions
File tree
- ares-cli/src
- orchestrator
- blue
- dispatcher
- worker
- ares-llm
- examples
- src
- agent_loop
- provider
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
402 | 424 | | |
403 | 425 | | |
404 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
0 commit comments