Skip to content

feat(agent): persist and report context usage#239

Merged
jiahe0510 merged 2 commits into
mainfrom
jiahe/feat/context-usage
Jul 23, 2026
Merged

feat(agent): persist and report context usage#239
jiahe0510 merged 2 commits into
mainfrom
jiahe/feat/context-usage

Conversation

@jiahe0510

Copy link
Copy Markdown
Collaborator

Summary

  • Persist a versioned context_state in session state.json, including current context usage, usage source, compact/microcompact counts, and update time.
  • Restore context accounting across restarts and update it after user input, provider responses, tool results, and successful compaction.
  • Add /context and /context all with category estimates, and expose AgentEngine::context_status() for SDK hosts.
  • Keep existing session files backward-compatible through serde defaults; the effective context window remains runtime configuration and is not persisted.

Why

AionCore needs aionrs to own the effective context window and compaction decisions. Previously, the current context watermark and compaction history were runtime-only, so restarts lost that status and hosts could not query a consistent context view.

Non-goals

  • This PR does not add AionCore/AionUi structured context-status events or UI rendering.
  • This PR does not introduce model-specific context limits in AionUi.
  • This PR does not persist the runtime context window or request-shape fingerprints.

Validation

  • just push -u origin jiahe/feat/context-usage
    • cargo fix --allow-dirty --allow-staged
    • cargo clippy --fix --workspace --all-targets --allow-dirty --allow-staged -- -D warnings
    • cargo fmt --all
    • cargo nextest run --workspace --profile default
    • cargo hakari generate --diff
    • cargo hakari manage-deps --dry-run
    • cargo hakari verify
  • cargo test -p aion-agent
  • cargo check --workspace
  • git diff --check

Follow-up

After this lands and is released, AionCore can consume AgentEngine::context_status() and emit a structured context-status event for AionUi.

@jiahe0510
jiahe0510 force-pushed the jiahe/feat/context-usage branch from af55592 to b3c78a6 Compare July 23, 2026 09:27
@jiahe0510
jiahe0510 marked this pull request as ready for review July 23, 2026 10:00
@jiahe0510
jiahe0510 merged commit bda1c18 into main Jul 23, 2026
13 checks passed
@jiahe0510
jiahe0510 deleted the jiahe/feat/context-usage branch July 23, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant