Skip to content

feat(think): bundle workers-ai-provider and accept model id strings#1832

Merged
threepointone merged 1 commit into
mainfrom
think-string-model-provider
Jun 29, 2026
Merged

feat(think): bundle workers-ai-provider and accept model id strings#1832
threepointone merged 1 commit into
mainfrom
think-string-model-provider

Conversation

@threepointone

@threepointone threepointone commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the common model-configuration case in @cloudflare/think zero-boilerplate. Instead of installing workers-ai-provider, importing createWorkersAI, and wiring it up in every agent, getModel() can now just return a model id string:

export class MyAgent extends Think<Env> {
  getModel() {
    return "@cf/moonshotai/kimi-k2.7-code"; // or "openai/gpt-5.5"
  }
}

Think bundles workers-ai-provider (plus the @ai-sdk/openai / @ai-sdk/anthropic wire-format plugins) and resolves the string off your AI binding:

  • @cf/... ids hit Workers AI directly, with sessionAffinity wired in automatically for prefix-cache hits.
  • Any other "<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 LanguageModel from getModel() still works unchanged for full control over provider/gateway options.

What's included

Core (packages/think)

  • getModel() is typed to return ThinkModel — a newly exported alias for LanguageModel | 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).
  • New getAIBinding() override (default this.env.AI) controls which binding the string resolver uses.
  • New public resolveModel(model?) (defaults to resolving getModel()) returns a concrete LanguageModel. Use it for side inference calls (summarization/compaction generateText) instead of passing a possibly-string getModel() straight to the AI SDK.
  • Per-turn override TurnConfig.model (from beforeTurn) and per-step override StepConfig.model (from beforeStep) now accept ThinkModel too; string overrides are resolved before the step is handed to the AI SDK.
  • workers-ai-provider + @ai-sdk/openai + @ai-sdk/anthropic are now direct dependencies of @cloudflare/think.

Scaffolder + templates + docs

  • think init scaffolds a string-returning getModel(); workers-ai-provider removed from THIRD_PARTY_DEPENDENCIES.
  • All starter templates and non-starter examples that used the createWorkersAI(...)("@cf/...") boilerplate now return strings, with workers-ai-provider dropped from their package.json.
  • Docs (getting-started, index, lifecycle-hooks) updated to the string pattern.

Deliberately left using createWorkersAI directly: examples/experiments that exist to exercise low-level provider behavior (deploy-churn mock + BYOK recovery harness, gateway-resume-think capture/re-attach models, wip/issue-1691-live multi-provider switch, raw Agent + generateText session-* experiments).

Note: resume: true is intentionally not set as a provider-level default — that capability hasn't rolled out to everyone yet. Users who want it can return a fully-constructed LanguageModel with their own resume setting.

Test plan

  • pnpm run check (sherif + export checks + oxfmt + oxlint + typecheck, 114 projects) passes
  • pnpm exec nx run think:test (CLI + workers + react suites) passes
  • Type-level autocomplete works for @cf/... ids while arbitrary gateway slugs remain assignable
  • Manual smoke: a scaffolded agent returning "@cf/..." and one returning "openai/gpt-5.5" both run a turn end-to-end

Made with Cursor


Open in Devin Review

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-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e05bc34

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/think Minor

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

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1832

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1832

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1832

create-think

npm i https://pkg.pr.new/create-think@1832

hono-agents

npm i https://pkg.pr.new/hono-agents@1832

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1832

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1832

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1832

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1832

commit: e05bc34

@threepointone threepointone merged commit 51ec433 into main Jun 29, 2026
5 checks passed
@threepointone threepointone deleted the think-string-model-provider branch June 29, 2026 01:07
@github-actions github-actions Bot mentioned this pull request Jun 29, 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.

1 participant