Skip to content

Move context management into goose-providers crate - #10728

Closed
jamadeo wants to merge 2 commits into
mainfrom
provider-compaction
Closed

Move context management into goose-providers crate#10728
jamadeo wants to merge 2 commits into
mainfrom
provider-compaction

Conversation

@jamadeo

@jamadeo jamadeo commented Jul 27, 2026

Copy link
Copy Markdown
Member

Move compaction functionality into goose-providers.

We could also consider making this a separate crate offering, but this seems right for now.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 TokenCounter and usage estimation logic into crates/goose-providers, and re-exported them from crates/goose to preserve existing call sites.
  • Moved compaction prompt templates into goose-providers and updated goose’s template loader to use the provider-owned defaults with user override support.
  • Refactored compaction to use an injected CompactionModel trait so provider/model selection stays in the application layer (goose) while compaction logic lives in goose-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.

Comment thread crates/goose-providers/src/token_counter.rs
@jamadeo
jamadeo marked this pull request as ready for review July 31, 2026 16:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/goose-providers/src/context_mgmt/structured.rs
@jamadeo
jamadeo requested a review from alexhancock July 31, 2026 18:34
alexhancock added a commit that referenced this pull request Aug 7, 2026
…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.
@jamadeo

jamadeo commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

superseded by #11042

@jamadeo jamadeo closed this Aug 11, 2026
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