Skip to content

feat(chat): add session context budget API and chat budget visibility panel#237

Open
Congregalis wants to merge 2 commits intodataelement:mainfrom
Congregalis:feat/context-budget-endpoint
Open

feat(chat): add session context budget API and chat budget visibility panel#237
Congregalis wants to merge 2 commits intodataelement:mainfrom
Congregalis:feat/context-budget-endpoint

Conversation

@Congregalis
Copy link
Copy Markdown
Contributor

Summary

This PR introduces session-level context budget visibility in two parts:

  • Backend: adds a lightweight session context budget API to estimate current context load.
  • Frontend: adds a chat-side context budget indicator + hover details panel in Agent Detail chat.

Commits included:

What Changed

1) Backend: Session Context Budget Endpoint

Added:

  • GET /api/agents/{agent_id}/sessions/{session_id}/context-budget

Returns minimal budget fields:

  • window_size_messages
  • session_messages_total
  • estimated_tokens_current_window
  • budget_tokens
  • usage_ratio

Implementation notes:

  • Estimates tokens from window message content using existing char-based estimator.
  • Uses a fixed default budget_tokens baseline for now.
  • Read-only endpoint; does not change chat behavior.

2) Frontend: Context Budget Indicator in Chat UI

Added session budget visualization in Agent Detail chat:

  • Circular budget progress indicator near send controls.
  • Hover card showing detailed context budget fields.
  • Progress ring and percentages bound to usage_ratio.
  • i18n labels for EN/ZH.

Notes / Scope

  • This PR is observability only for context budget.

ScreenShots

image image

Follow-up

To keep this PR focused and easier to review, I’ve kept it to the context‑budget endpoint and UI only, and would implement auto compaction logic separately if you think it’s a good fit for the project.

A follow‑up PR with auto compaction would:

  • proactively reduce the risk of context overflow and hard failures when long‑running sessions grow large;

  • avoid silent quality degradation from models receiving overly long, noisy histories;

Checklist

  • Tested locally
  • No unrelated changes included

@Congregalis Congregalis force-pushed the feat/context-budget-endpoint branch from 601d5a2 to d0ba16c Compare March 31, 2026 11:32
@Congregalis Congregalis force-pushed the feat/context-budget-endpoint branch from d0ba16c to 5d08051 Compare April 1, 2026 17:01
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