Skip to content

Comments

fix(agent): decouple context_window from max_tokens#556

Open
repfigit wants to merge 2 commits intosipeed:mainfrom
repfigit:fix/context-window-default
Open

fix(agent): decouple context_window from max_tokens#556
repfigit wants to merge 2 commits intosipeed:mainfrom
repfigit:fix/context-window-default

Conversation

@repfigit
Copy link

Summary

  • Add configurable context_window field to AgentDefaults with a 128K default
  • Fix bug where ContextWindow was incorrectly set to MaxTokens (typically 8192), causing overly aggressive context trimming
  • Add .gitattributes to enforce LF line endings

Test plan

  • go build ./...
  • go test ./pkg/config/... ./pkg/agent/...
  • Test with a config that omits context_window — should default to 128K
  • Test with a config that sets context_window: 64000 — should use 64K

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 20, 2026 22:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug where the agent's context window was incorrectly set to the max tokens value (typically 8192), causing premature context trimming. The fix decouples context_window from max_tokens by adding a dedicated configurable field with a sensible 128K default, aligning with modern LLM capabilities.

Changes:

  • Added ContextWindow field to AgentDefaults config struct with environment variable support
  • Fixed NewAgentInstance to use dedicated context window value (defaulting to 128K) instead of max tokens
  • Added .gitattributes to enforce LF line endings across the repository

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/config/config.go Adds ContextWindow field to AgentDefaults struct with JSON and environment variable tags
pkg/agent/instance.go Introduces context window initialization logic with 128K default and uses it instead of max tokens
.gitattributes Enforces LF line endings for all text files to ensure consistency across platforms

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ImageModel string `json:"image_model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_IMAGE_MODEL"`
ImageModelFallbacks []string `json:"image_model_fallbacks,omitempty"`
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
ContextWindow int `json:"context_window,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ContextWindow field uses omitempty in its JSON tag, which is inconsistent with similar integer fields like MaxTokens (line 177) and MaxToolIterations (line 180) that don't use omitempty. For consistency and to match the existing pattern for integer configuration fields with defaults in AgentDefaults, consider removing omitempty from the JSON tag.

Suggested change
ContextWindow int `json:"context_window,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`
ContextWindow int `json:"context_window" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`

Copilot uses AI. Check for mistakes.
Comment on lines +86 to +89
contextWindow := defaults.ContextWindow
if contextWindow == 0 {
contextWindow = 128000
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ContextWindow field lacks test coverage. Similar fields like MaxTokens and Temperature have dedicated tests in instance_test.go (e.g., TestNewAgentInstance_UsesDefaultsTemperatureAndMaxTokens). Consider adding tests to verify:

  1. ContextWindow uses the configured value when provided
  2. ContextWindow defaults to 128000 when not configured (zero value)
    This is important because ContextWindow affects critical behavior like context trimming in loop.go (lines 727 and 892).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since picoclaw is intended to work on low-end machine, by default we should set a smaller value (better to keep 8192, the current value). Users with devices that have larger memory could set this value explicitly in the config file.

Please also update the README.md for this feature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@repfigit repfigit force-pushed the fix/context-window-default branch from 03a6b3a to 8afe597 Compare February 20, 2026 23:09
Add configurable context_window field to AgentDefaults with a 128K
default. Previously ContextWindow was incorrectly set to MaxTokens
(typically 8192), causing overly aggressive context trimming.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 20, 2026 23:36
@repfigit repfigit force-pushed the fix/context-window-default branch from 8afe597 to 06ee821 Compare February 20, 2026 23:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 177 to 180
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
ContextWindow int `json:"context_window" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`
Temperature *float64 `json:"temperature,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextWindow is added without omitempty, but DefaultConfig() (used by onboarding + SaveConfig) does not set this field yet. As a result, newly generated config files will likely include "context_window": 0, which conflicts with the stated 128K default and is confusing for users. Consider either setting ContextWindow to 128000 in DefaultConfig() (preferred if you want the default to be visible) or adding omitempty to this JSON tag so the field is omitted when unset.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@repfigit I didn't see the DefaultConfig changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to change this file in a fix PR?


contextWindow := defaults.ContextWindow
if contextWindow == 0 {
contextWindow = 128000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please at the very least state your rationale here. I share the same concern that @zenixls2 has raised.

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.

3 participants