Move context management into goose-providers crate - #10728
Conversation
Compaction logic is now app-layer-free: config reads and fast-model selection are injected via new CompactionModel trait and CompactionSettings. Thin wrappers in goose keep existing call sites unchanged. token_counter and usage_estimator moved along as dependencies; compaction prompt templates are embedded in goose-providers as the single source of truth.
# Conflicts: # crates/goose-providers/src/context_mgmt/mod.rs
There was a problem hiding this comment.
Pull request overview
This PR moves context-compaction and token-counting utilities into the goose-providers crate, leaving compatibility re-exports in goose while updating prompt/template plumbing to source compaction templates from the new location.
Changes:
- Moved
TokenCounterand usage estimation logic intocrates/goose-providers, and re-exported them fromcrates/gooseto preserve existing call sites. - Moved compaction prompt templates into
goose-providersand updatedgoose’s template loader to use the provider-owned defaults with user override support. - Refactored compaction to use an injected
CompactionModeltrait so provider/model selection stays in the application layer (goose) while compaction logic lives ingoose-providers.
Reviewed changes
Copilot reviewed 11 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/goose/src/token_counter.rs | Re-export token counter APIs from goose-providers. |
| crates/goose/src/providers/usage_estimator.rs | Re-export usage estimation from goose-providers. |
| crates/goose/src/prompt_template.rs | Uses provider-owned compaction templates as defaults; adds user_template_override. |
| crates/goose/src/context_mgmt.rs | New wrapper around provider compaction APIs, injecting fast-model completion and honoring user overrides. |
| crates/goose/Cargo.toml | Removes tiktoken-rs from goose; dependency adjustments for the move. |
| crates/goose-providers/src/usage_estimator.rs | New home for ensure_usage_tokens (plus tests). |
| crates/goose-providers/src/token_counter.rs | New home for token counting + caching (plus tests). |
| crates/goose-providers/src/lib.rs | Exposes new context_mgmt, token_counter, and usage_estimator modules publicly. |
| crates/goose-providers/src/context_mgmt/structured.rs | Renders summaries from a passed-in template string instead of looking up by name. |
| crates/goose-providers/src/context_mgmt/prompts/compaction.md | Adds provider-owned compaction prompt template. |
| crates/goose-providers/src/context_mgmt/prompts/compaction_summary.md | Adds provider-owned summary-rendering template. |
| crates/goose-providers/src/context_mgmt/mod.rs | Refactors compaction to use injected completion via CompactionModel + CompactionSettings; embeds templates; updates tests accordingly. |
| crates/goose-providers/Cargo.toml | Adds dependencies needed for moved modules/templates. |
| Cargo.lock | Lockfile updates reflecting dependency moves/additions. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ffc4570e71
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…odel I/O An alternative direction to #10728: instead of moving context management into goose-providers, compaction lives in its own minimal crate depending only on goose-provider-types. All model input/output goes through a single CompactionModel trait (complete + count_tokens), so provider selection, fast-model fallback, session attribution, config reads, and tokenizer choice all stay in the application layer. The goose crate keeps its existing public API via a thin facade that adapts the fast-model path and user template overrides. Token counting for usage estimation is part of the trait, so the crate carries no tiktoken/lru/blake3 dependencies and usage_estimator is folded into the compaction flow.
|
superseded by #11042 |
Move compaction functionality into goose-providers.
We could also consider making this a separate crate offering, but this seems right for now.