Skip to content

feat: real-time context usage updates during streaming agent loop #243

Description

@xinhuagu

Feature Request

The status bar's context usage indicator (14/200K (7%)) currently only updates after an entire task completes. During a long multi-step agent loop (LLM → tool → LLM → tool...), the context usage stays frozen, giving the user no visibility into how much context window is being consumed in real-time.

Current Behavior

  1. User sends a prompt → task starts
  2. Agent loop runs 10+ LLM calls with tool use over several minutes
  3. Status bar context usage stays at the value from the previous task
  4. Task finally completes → usage updates in one jump

Desired Behavior

Context usage updates after each LLM call within the agent loop, so the user can see context consumption growing in real-time and decide whether to intervene (cancel, compact, etc.) before hitting the limit.

Implementation Plan

Daemon side (StreamingAgentHandler / StreamingAgentLoop)

After each LLM call in the agent loop, send a notification:

{"jsonrpc": "2.0", "method": "stream.usage", "params": {"inputTokens": 42000, "outputTokens": 8000, "totalTokens": 50000}}

The inputTokens here should be the cumulative input tokens from the most recent API call (which represents current context window consumption).

CLI side (TaskStreamReader + TerminalRepl)

  1. Add case "stream.usage" handler in TaskStreamReader.handleNotification()
  2. Update latestInputTokens on each stream.usage notification
  3. Trigger requestUiRender() so the status bar refreshes immediately

Files to modify

  • aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java — emit stream.usage after each LLM call
  • aceclaw-cli/src/main/java/dev/aceclaw/cli/TaskStreamReader.java — handle stream.usage
  • aceclaw-cli/src/main/java/dev/aceclaw/cli/TerminalRepl.java — update latestInputTokens from notification

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions