Skip to content

Remove context indicators from model-facing environment detailsΒ #5165

@hannesrudolph

Description

@hannesrudolph

What specific problem does this solve?

Who is affected: All users interacting with AI models, especially those working on large projects with high context usage

When this happens: During every model interaction when environment details are sent to the API

Current behavior: Context indicators like "Current Context Size (Tokens)" and percentage values (e.g., "72%") are included in environment details sent to models, causing models to interpret these as instructions and modify their behavior inappropriately

Impact: Models like Sonnet 4 respond with shorter messages when context approaches 100%, complete tasks prematurely when they see high percentages, and generally alter their behavior based on perceived token budget constraints rather than actual task requirements


πŸ› οΈ Contributing & Technical Analysis

βœ… I'm interested in implementing this feature
βœ… I understand this needs approval before implementation begins

How should this be solved?

What will change:

  • Remove context token count and percentage from environment details sent to models
  • Context indicators will be completely excluded from the XML <environment_details> block
  • Token information remains available internally for UI display and system monitoring

User interaction:

  • Users will see no change in functionality - context information will still be visible in the UI
  • Models will no longer receive token usage information that influences their responses
  • Task completion decisions will be based purely on task requirements, not perceived token constraints

Acceptance Criteria

Given I am working on a task with high context usage (>70%)
When the model receives environment details
Then the environment details should not contain any token count or percentage information
And the model should not modify response length based on context usage
And the model should complete tasks based on requirements, not token concerns

Given I am monitoring context usage in the UI
When I view the task information
Then I should still see current context size and percentage
And this information should be accurate and up-to-date
But this data should not be transmitted to the model

Given the system needs to make context management decisions
When determining if truncation is needed
Then token calculations should still function normally
And automatic context condensing should work as before
But context indicators should not appear in model-facing content

Technical Considerations

Implementation approach:

  • Key files to modify: src/core/environment/getEnvironmentDetails.ts (lines 206-207)
  • Current architecture: Environment details are constructed in getEnvironmentDetails() and appended to user content in Task.ts
  • Integration points: Environment details are sent to models via Task.ts:1226 during API requests
  • Similar patterns in codebase: Other conditional environment detail sections based on user settings

Root cause analysis:

  • Lines 206-207 in getEnvironmentDetails.ts add context token information:
    details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? `${contextTokens.toLocaleString()} (${contextPercentage}%)` : "(Not available)"}`
  • This data is included in the <environment_details> XML block sent to models
  • Models interpret this as instruction context rather than metadata

Performance implications:

  • Minimal performance impact - simply removing lines that add context information
  • Token calculations still occur for internal use but aren't transmitted

Compatibility concerns:

  • No breaking changes to external APIs
  • Internal token usage calculations remain unchanged
  • UI context display functionality preserved

Trade-offs and Risks

Alternatives considered:

  • Move context info to separate metadata block: More complex, still risks model interpretation
  • Use different formatting that models ignore: Unreliable, models may still interpret formatted numbers
  • Make context indicators optional via settings: Adds complexity, most users would want this behavior

Potential risks:

  • None identified: This change only removes potentially harmful information from model context
  • Debugging: Context information remains available through UI and internal metrics

Breaking changes:

  • None - this is purely removing information that shouldn't affect model behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.enhancementNew feature or requestproposal

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions