feat(think): bundle workers-ai-provider and accept model id strings#1832
Merged
Conversation
Make the common model-config case zero-boilerplate: `getModel()` (and the `beforeTurn`/`beforeStep` per-turn/per-step overrides) now accept a model id string resolved through a built-in `workers-ai-provider` instance, so users no longer install/import/wire the provider themselves. - getModel() returns `ThinkModel` (new exported alias for `LanguageModel | ThinkModelId`); `ThinkModelId` gives `@cf/...` autocomplete while accepting any gateway slug string. - Bundle `workers-ai-provider` + `@ai-sdk/openai`/`@ai-sdk/anthropic` wire plugins as deps; `@cf/...` ids hit Workers AI (with sessionAffinity), other `<provider>/<model>` slugs route through AI Gateway. - Add `getAIBinding()` (default `env.AI`) and public `resolveModel(model?)` for side inference calls (summarization/compaction). - Widen `TurnConfig.model` and `StepConfig.model` to `ThinkModel`; resolve string overrides before handing the step to the AI SDK. - Scaffolder + all starters + non-starter examples + docs use string models; drop `workers-ai-provider` from their deps and from THIRD_PARTY_DEPENDENCIES. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: e05bc34 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the common model-configuration case in
@cloudflare/thinkzero-boilerplate. Instead of installingworkers-ai-provider, importingcreateWorkersAI, and wiring it up in every agent,getModel()can now just return a model id string:Think bundles
workers-ai-provider(plus the@ai-sdk/openai/@ai-sdk/anthropicwire-format plugins) and resolves the string off yourAIbinding:@cf/...ids hit Workers AI directly, withsessionAffinitywired in automatically for prefix-cache hits."<provider>/<model>"slug (openai/gpt-5.5,anthropic/claude-sonnet-4-5,google/gemini-2.5-pro,xai/grok-4,groq/...) routes through AI Gateway.Returning a fully-constructed
LanguageModelfromgetModel()still works unchanged for full control over provider/gateway options.What's included
Core (
packages/think)getModel()is typed to returnThinkModel— a newly exported alias forLanguageModel | ThinkModelId.ThinkModelId(also exported) gives editor autocomplete for the Workers AI text-generation catalog while still accepting any string (gateway slugs are validated server-side at runtime).getAIBinding()override (defaultthis.env.AI) controls which binding the string resolver uses.resolveModel(model?)(defaults to resolvinggetModel()) returns a concreteLanguageModel. Use it for side inference calls (summarization/compactiongenerateText) instead of passing a possibly-stringgetModel()straight to the AI SDK.TurnConfig.model(frombeforeTurn) and per-step overrideStepConfig.model(frombeforeStep) now acceptThinkModeltoo; string overrides are resolved before the step is handed to the AI SDK.workers-ai-provider+@ai-sdk/openai+@ai-sdk/anthropicare now direct dependencies of@cloudflare/think.Scaffolder + templates + docs
think initscaffolds a string-returninggetModel();workers-ai-providerremoved fromTHIRD_PARTY_DEPENDENCIES.createWorkersAI(...)("@cf/...")boilerplate now return strings, withworkers-ai-providerdropped from theirpackage.json.getting-started,index,lifecycle-hooks) updated to the string pattern.Deliberately left using
createWorkersAIdirectly: examples/experiments that exist to exercise low-level provider behavior (deploy-churnmock + BYOK recovery harness,gateway-resume-thinkcapture/re-attach models,wip/issue-1691-livemulti-provider switch, rawAgent+generateTextsession-* experiments).Test plan
pnpm run check(sherif + export checks + oxfmt + oxlint + typecheck, 114 projects) passespnpm exec nx run think:test(CLI + workers + react suites) passes@cf/...ids while arbitrary gateway slugs remain assignable"@cf/..."and one returning"openai/gpt-5.5"both run a turn end-to-endMade with Cursor