Skip to content

Conversation

@dcieslak19973
Copy link
Contributor

Adds support for environment variables to override context window limits for different model configurations:

  • GOOSE_CONTEXT_LIMIT: Global context limit override
  • GOOSE_LEAD_CONTEXT_LIMIT: Override for lead models in lead/worker mode
  • GOOSE_WORKER_CONTEXT_LIMIT: Override for worker models in lead/worker mode
  • GOOSE_PLANNER_CONTEXT_LIMIT: Override for planner models

This resolves issues with LiteLLM proxy models and other custom models that don't match Goose's predefined model name patterns and were defaulting to 32k context limits.

Changes:

  • Add ModelConfig::new_with_context_env() for custom env var support
  • Add get_context_limit_with_env_override() with precedence logic
  • Update lead/worker and planner model creation to use specific env vars
  • Fix CLI context display to use proper model config instead of hardcoded 32k
  • Add comprehensive tests for env var override behavior
  • Update documentation with usage examples

Fully backward compatible - existing behavior unchanged when env vars not set.

Adds support for environment variables to override context window limits
for different model configurations:

- GOOSE_CONTEXT_LIMIT: Global context limit override
- GOOSE_LEAD_CONTEXT_LIMIT: Override for lead models in lead/worker mode
- GOOSE_WORKER_CONTEXT_LIMIT: Override for worker models in lead/worker mode
- GOOSE_PLANNER_CONTEXT_LIMIT: Override for planner models

This resolves issues with LiteLLM proxy models and other custom models
that don't match Goose's predefined model name patterns and were
defaulting to 32k context limits.

Changes:
- Add ModelConfig::new_with_context_env() for custom env var support
- Add get_context_limit_with_env_override() with precedence logic
- Update lead/worker and planner model creation to use specific env vars
- Fix CLI context display to use proper model config instead of hardcoded 32k
- Add comprehensive tests for env var override behavior
- Update documentation with usage examples

Fully backward compatible - existing behavior unchanged when env vars not set.
Copilot AI review requested due to automatic review settings July 6, 2025 03:31
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

Adds support for overriding model context window limits via environment variables, enabling custom limits for main, lead, worker, and planner models without changing code defaults.

  • Introduce ModelConfig::new_with_context_env and get_context_limit_with_env_override with precedence logic
  • Update provider factory (create_lead_worker_from_env) and CLI (display_context_usage, planner setup) to use the new env‐aware constructors
  • Extend documentation and add unit tests for context limit overrides

Reviewed Changes

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

File Description
documentation/docs/guides/environment-variables.md Add GOOSE_*_CONTEXT_LIMIT table and examples
crates/goose/src/providers/factory.rs Replace ModelConfig::new with new_with_context_env for lead/worker
crates/goose/src/model.rs Implement new_with_context_env, get_context_limit_with_env_override, update new, add tests
crates/goose-cli/src/session/mod.rs Use model_config.context_limit() in CLI display; use planner-specific env var
Comments suppressed due to low confidence (3)

crates/goose-cli/src/session/mod.rs:1306

  • Add a unit or integration test for display_context_usage to verify it reports the correct limit from model_config.context_limit() instead of the old hardcoded value.
        let context_limit = model_config.context_limit();

crates/goose-cli/src/session/mod.rs:1453

  • Add a test for planner mode to ensure GOOSE_PLANNER_CONTEXT_LIMIT is correctly applied when creating the reasoner.
    let model_config = ModelConfig::new_with_context_env(

documentation/docs/guides/environment-variables.md:126

  • [nitpick] Consider removing the comma in 128,000 to match numeric formatting used elsewhere (e.g., 128000) for consistency.
| `GOOSE_CONTEXT_LIMIT` | Override context limit for the main model | Integer (number of tokens) | Model-specific default or 128,000 |

- Preserve user-specified context_limit from default_model when creating worker model config
- Apply environment variable overrides (GOOSE_WORKER_CONTEXT_LIMIT, GOOSE_CONTEXT_LIMIT) with proper precedence
- Maintain all other original model settings (temperature, max_tokens, toolshim)
- Add test to verify context limit preservation behavior
- Addresses PR comment about discarding explicit context limits from config files

Fixes issue where new_with_context_env() was discarding context_limit from original config
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

its a lot of new env vars. but looks ok to me (and documented)

@dcieslak19973
Copy link
Contributor Author

@michaelneale thanks; I'm not 100% on how to make the failing check succeed. any pointers? The bot here doesn't seem to be able to help

@angiejones angiejones self-assigned this Jul 7, 2025
@angiejones
Copy link
Collaborator

@dianed-square @emma-squared can one of you review the doc piece?


### Context Limit Configuration

These variables allow you to override the default context window size (token limit) for your models. This is particularly useful when using LiteLLM proxies or custom models that don't match Goose's predefined model patterns.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @dcieslak19973 -- do you have a good link target for "LiteLLM proxies" we can add for readers who would like additional context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not affiliated with LiteLLM (though I do use it and like it a lot):

https://docs.litellm.ai/
https://github.com/BerriAI/litellm

Copy link
Contributor

@dianed-square dianed-square left a comment

Choose a reason for hiding this comment

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

Thanks! Approved with a request to add a link for "LiteLLM proxies" if feasible

@dcieslak19973
Copy link
Contributor Author

Thanks! Approved with a request to add a link for "LiteLLM proxies" if feasible

I'm not affiliated with LiteLLM (though I do use it and like it a lot):

@dianed-square
Copy link
Contributor

@michaelneale thanks; I'm not 100% on how to make the failing check succeed. any pointers? The bot here doesn't seem to be able to help

@dcieslak19973 -- I've been able to resolve this by rebasing against the latest main branch

@dianed-square dianed-square merged commit a360134 into block:main Jul 7, 2025
10 of 11 checks passed
zanesq added a commit that referenced this pull request Jul 8, 2025
* 'main' of github.com:block/goose:
  feat: Add environment variables to override model context limits (#3260)
  chore(release): release version 1.0.34 (#3285)
  fix(devcontainer): install protoc to fix build (#3267)
  Enabling npx command to install on Windows Desktop (#3283)
  Fix: Allow native Cmd+Up/Down cursor movement when user has typed text (#3246)
  chore(release): release version 1.0.33 (#3284)
  fix Windows Env Vars (#3282)

# Conflicts:
#	ui/desktop/src/components/ChatInput.tsx
dianed-square added a commit to dianed-square/goose that referenced this pull request Jul 8, 2025
* update-to-v1.0.35: (57 commits)
  chore(release): release version 1.0.35 (block#3292)
  docs: enhanced code editing topic (block#3287)
  fix cu (block#3291)
  feat: Add environment variables to override model context limits (block#3260)
  chore(release): release version 1.0.34 (block#3285)
  fix(devcontainer): install protoc to fix build (block#3267)
  Enabling npx command to install on Windows Desktop (block#3283)
  Fix: Allow native Cmd+Up/Down cursor movement when user has typed text (block#3246)
  chore(release): release version 1.0.33 (block#3284)
  fix Windows Env Vars (block#3282)
  feat: bedrock image content support (block#3266)
  Add support in goose configure for streaming http mcp tools (block#3256)
  docs: add Alby MCP tutorial (block#3217)
  refactor(tests): make logging test in goose-cli less flaky on macos (block#3273)
  feat: cli can work with gui generated recipes (block#3254)
  Goose projects docs (block#3272)
  feat: add support for 'cu' command in extension installation (block#3261)
  Docs: Add cloudinary mcp tutorial (block#3268)
  fix: Enable agent to see instruction to use final output tool when it wasn't called (block#3253)
  Use command line to run sub agent and sub recipe (in sequence or parallel) (block#3190)
  ...
lifeizhou-ap added a commit that referenced this pull request Jul 9, 2025
* main: (23 commits)
  docs: VS Code MCP video (#3307)
  docs: fixed broken link (#3306)
  Add YouTube video to Netlify MCP documentation (#3302)
  docs: add sub-recipes topic (#3241)
  docs: move topics to tutorials section (#3297)
  site analytics (#3293)
  chore(release): release version 1.0.35 (#3292)
  docs: enhanced code editing topic (#3287)
  fix cu (#3291)
  feat: Add environment variables to override model context limits (#3260)
  chore(release): release version 1.0.34 (#3285)
  fix(devcontainer): install protoc to fix build (#3267)
  Enabling npx command to install on Windows Desktop (#3283)
  Fix: Allow native Cmd+Up/Down cursor movement when user has typed text (#3246)
  chore(release): release version 1.0.33 (#3284)
  fix Windows Env Vars (#3282)
  feat: bedrock image content support (#3266)
  Add support in goose configure for streaming http mcp tools (#3256)
  docs: add Alby MCP tutorial (#3217)
  refactor(tests): make logging test in goose-cli less flaky on macos (#3273)
  ...
michaelneale added a commit that referenced this pull request Jul 9, 2025
* main: (23 commits)
  docs: VS Code MCP video (#3307)
  docs: fixed broken link (#3306)
  Add YouTube video to Netlify MCP documentation (#3302)
  docs: add sub-recipes topic (#3241)
  docs: move topics to tutorials section (#3297)
  site analytics (#3293)
  chore(release): release version 1.0.35 (#3292)
  docs: enhanced code editing topic (#3287)
  fix cu (#3291)
  feat: Add environment variables to override model context limits (#3260)
  chore(release): release version 1.0.34 (#3285)
  fix(devcontainer): install protoc to fix build (#3267)
  Enabling npx command to install on Windows Desktop (#3283)
  Fix: Allow native Cmd+Up/Down cursor movement when user has typed text (#3246)
  chore(release): release version 1.0.33 (#3284)
  fix Windows Env Vars (#3282)
  feat: bedrock image content support (#3266)
  Add support in goose configure for streaming http mcp tools (#3256)
  docs: add Alby MCP tutorial (#3217)
  refactor(tests): make logging test in goose-cli less flaky on macos (#3273)
  ...
GaryZhous pushed a commit to GaryZhous/goose that referenced this pull request Jul 9, 2025
ahau-square pushed a commit that referenced this pull request Jul 11, 2025
atarantino pushed a commit to atarantino/goose that referenced this pull request Jul 14, 2025
…ck#3260)

Co-authored-by: dianed-square <[email protected]>
Co-authored-by: Angie Jones <[email protected]>
Signed-off-by: Adam Tarantino <[email protected]>
s-soroosh pushed a commit to s-soroosh/goose that referenced this pull request Jul 18, 2025
kwsantiago pushed a commit to kwsantiago/goose that referenced this pull request Jul 19, 2025
…ck#3260)

Co-authored-by: dianed-square <[email protected]>
Co-authored-by: Angie Jones <[email protected]>
Signed-off-by: Kyle Santiago <[email protected]>
cbruyndoncx pushed a commit to cbruyndoncx/goose that referenced this pull request Jul 20, 2025
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.

4 participants