Skip to content

feat: add live context token counter after each orchestrator loop#3351

Open
carTloyal123 wants to merge 1 commit into
tailcallhq:mainfrom
carTloyal123:feat/live-context-counter
Open

feat: add live context token counter after each orchestrator loop#3351
carTloyal123 wants to merge 1 commit into
tailcallhq:mainfrom
carTloyal123:feat/live-context-counter

Conversation

@carTloyal123
Copy link
Copy Markdown

Summary

Adds an inline debug-style context usage line after each LLM round-trip in the orchestrator loop, so users can monitor context growth in real time during multi-tool-call turns.

What it does

After each iteration of the orchestrator's while !should_yield loop (i.e., after the LLM response + tool results are folded into the context), a TitleFormat::debug message is emitted showing:

  • Current token count (actual or approximate with ~ prefix)
  • Compaction threshold (if configured, shown as / 900.0k)

Example output:

● [14:32:05] Context 45.2k / 900.0k
● [14:32:12] Context ~82.1k / 900.0k

Changes

  • crates/forge_app/src/orch.rs: Added emit_context_usage() helper and humanize() formatter. Emits context line after each loop iteration at the point where context is fully updated.
  • crates/forge_domain/src/agent.rs: Added unit test test_compaction_threshold_claude_opus_4_6_with_1m_context_window verifying the compaction threshold calculation for 1M-context models.

Testing

  • New unit test passes: cargo test -p forge_domain test_compaction_threshold_claude_opus_4_6
  • cargo check passes across workspace
  • Manually verified inline output during multi-tool-call sessions

Co-Authored-By: ForgeCode noreply@forgecode.dev

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 17, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label May 17, 2026
Display an inline debug-style context usage line after each LLM
round-trip in the orchestrator loop. Shows current token count,
approximate prefix, and compaction threshold so users can monitor
context growth in real time during multi-tool-call turns.

Also adds a unit test verifying Claude Opus 4.6 compaction threshold
computes correctly as min(1M, 1M * 0.9) = 900k with the user's
token_threshold and token_threshold_percentage config.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
@carTloyal123 carTloyal123 force-pushed the feat/live-context-counter branch from 0bcc1ea to 6c6a755 Compare May 17, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants