feat(context): implement budget-aware file truncation and summarization for context assembly #7612

Open
opened 2026-04-10 23:45:14 +00:00 by HAL9000 · 2 comments
Owner

Background

Part of Epic #5167 (Context Budget Enforcement). When context assembly exceeds budget limits, the system needs to intelligently truncate or summarize files rather than simply dropping them. This issue implements budget-aware truncation strategies that preserve the most relevant portions of files when the full content exceeds the configured token budget.

Expected Behavior

When a file exceeds the per-file token budget, the ContextBudgetEnforcer applies a truncation strategy (head, tail, or summary) to reduce the file to fit within budget. The truncation strategy is configurable per context policy.

Acceptance Criteria

  • ContextBudgetEnforcer applies truncation when file exceeds max_file_size budget
  • Three truncation strategies supported: head (keep first N tokens), tail (keep last N tokens), summary (LLM-generated summary)
  • Truncation strategy configurable via context policy YAML (truncation_strategy: head|tail|summary)
  • Truncated files are marked with a [TRUNCATED] annotation in the assembled context
  • summary strategy uses a lightweight LLM call (configurable model)
  • Total context budget is enforced after per-file truncation
  • Pyright strict mode passes
  • nox -s lint passes

Metadata

  • Branch: feat/v3.4.0/context-budget-truncation
  • Commit Message: feat(context): implement budget-aware file truncation and summarization
  • Milestone: v3.4.0
  • Parent Epic: #5167

Dependencies

  • Must be done after: #5231 (ContextBudgetCalculator), #5232 (context view validation)

Subtasks

  • Create ContextBudgetEnforcer class with truncation strategies
  • Implement head truncation strategy
  • Implement tail truncation strategy
  • Implement summary truncation strategy (LLM-based)
  • Add [TRUNCATED] annotation to truncated content
  • Add truncation_strategy to context policy YAML schema
  • Write Behave scenarios for each truncation strategy
  • Write unit tests with FakeListLLM for summary strategy

Definition of Done

  • All subtasks completed
  • Budget enforcement never exceeds configured limits
  • nox passes with coverage >= 97%

Automated by CleverAgents Bot
Supervisor: Epic Planner | Agent: epic-planning-pool-supervisor

## Background Part of Epic #5167 (Context Budget Enforcement). When context assembly exceeds budget limits, the system needs to intelligently truncate or summarize files rather than simply dropping them. This issue implements budget-aware truncation strategies that preserve the most relevant portions of files when the full content exceeds the configured token budget. ## Expected Behavior When a file exceeds the per-file token budget, the `ContextBudgetEnforcer` applies a truncation strategy (head, tail, or summary) to reduce the file to fit within budget. The truncation strategy is configurable per context policy. ## Acceptance Criteria - [ ] `ContextBudgetEnforcer` applies truncation when file exceeds `max_file_size` budget - [ ] Three truncation strategies supported: `head` (keep first N tokens), `tail` (keep last N tokens), `summary` (LLM-generated summary) - [ ] Truncation strategy configurable via context policy YAML (`truncation_strategy: head|tail|summary`) - [ ] Truncated files are marked with a `[TRUNCATED]` annotation in the assembled context - [ ] `summary` strategy uses a lightweight LLM call (configurable model) - [ ] Total context budget is enforced after per-file truncation - [ ] Pyright strict mode passes - [ ] `nox -s lint` passes ## Metadata - **Branch**: `feat/v3.4.0/context-budget-truncation` - **Commit Message**: `feat(context): implement budget-aware file truncation and summarization` - **Milestone**: v3.4.0 - **Parent Epic**: #5167 ## Dependencies - Must be done after: #5231 (ContextBudgetCalculator), #5232 (context view validation) ## Subtasks - [ ] Create `ContextBudgetEnforcer` class with truncation strategies - [ ] Implement `head` truncation strategy - [ ] Implement `tail` truncation strategy - [ ] Implement `summary` truncation strategy (LLM-based) - [ ] Add `[TRUNCATED]` annotation to truncated content - [ ] Add `truncation_strategy` to context policy YAML schema - [ ] Write Behave scenarios for each truncation strategy - [ ] Write unit tests with `FakeListLLM` for summary strategy ## Definition of Done - [ ] All subtasks completed - [ ] Budget enforcement never exceeds configured limits - [ ] `nox` passes with coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Epic Planner | Agent: epic-planning-pool-supervisor
HAL9000 added this to the v3.4.0 milestone 2026-04-10 23:45:14 +00:00
Author
Owner

Label Compliance Fix Needed

This issue has no labels. Per CONTRIBUTING.md, every issue must have exactly one State/, Priority/, and Type/* label.

Recommended labels based on title/content (feat = feature):

  • State/Unverified (id:846)
  • Priority/Backlog (id:862)
  • Type/Feature (check org labels for ID)

Automated by CleverAgents Bot
Supervisor: Backlog Groomer | Agent: backlog-grooming-pool-supervisor

## Label Compliance Fix Needed This issue has **no labels**. Per CONTRIBUTING.md, every issue must have exactly one State/*, Priority/*, and Type/* label. **Recommended labels based on title/content** (feat = feature): - `State/Unverified` (id:846) - `Priority/Backlog` (id:862) - `Type/Feature` (check org labels for ID) --- **Automated by CleverAgents Bot** Supervisor: Backlog Groomer | Agent: backlog-grooming-pool-supervisor
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: High — Budget-aware file truncation and summarization for context assembly. Core ACMS v1 feature.
  • Milestone: v3.4.0 (M5: ACMS v1) — Budget enforcement is an explicit M5 acceptance criterion
  • Story Points: 5 (L) — Algorithm implementation with budget constraints
  • MoSCoW: Must Have — Budget enforcement is required for M5 acceptance

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

Issue triaged by project owner: - **State**: Verified - **Priority**: High — Budget-aware file truncation and summarization for context assembly. Core ACMS v1 feature. - **Milestone**: v3.4.0 (M5: ACMS v1) — Budget enforcement is an explicit M5 acceptance criterion - **Story Points**: 5 (L) — Algorithm implementation with budget constraints - **MoSCoW**: Must Have — Budget enforcement is required for M5 acceptance --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#7612
No description provided.