-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add environment variables to override model context limits #3260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add environment variables to override model context limits #3260
Conversation
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.
There was a problem hiding this 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_envandget_context_limit_with_env_overridewith 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_usageto verify it reports the correct limit frommodel_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_LIMITis 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,000to 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
michaelneale
left a comment
There was a problem hiding this 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)
|
@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 |
|
@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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
dianed-square
left a comment
There was a problem hiding this 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
Co-authored-by: Angie Jones <[email protected]>
I'm not affiliated with LiteLLM (though I do use it and like it a lot): |
@dcieslak19973 -- I've been able to resolve this by rebasing against the latest main branch |
* '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
* 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) ...
* 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) ...
* 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) ...
…ck#3260) Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]>
Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]>
…ck#3260) Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]> Signed-off-by: Adam Tarantino <[email protected]>
…ck#3260) Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]> Signed-off-by: Soroosh <[email protected]>
…ck#3260) Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]> Signed-off-by: Kyle Santiago <[email protected]>
…ck#3260) Co-authored-by: dianed-square <[email protected]> Co-authored-by: Angie Jones <[email protected]>
Adds support for environment variables to override context window limits for different model configurations:
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:
Fully backward compatible - existing behavior unchanged when env vars not set.