think: align generics with Agent/AIChatAgent + multi-session RFC#1350
Merged
threepointone merged 3 commits intomainfrom Apr 21, 2026
Merged
think: align generics with Agent/AIChatAgent + multi-session RFC#1350threepointone merged 3 commits intomainfrom
threepointone merged 3 commits intomainfrom
Conversation
Change `Think<Env, Config>` to `Think<Env, State, Props>` so it threads State and Props through to `Agent<Env, State, Props>`. Subclasses now get properly typed `this.state`, `setState()`, `initialState`, and `this.ctx.props` like they do with `Agent` / `AIChatAgent`. The `Config` class generic was in the slot where `Agent`/`AIChatAgent` put `State`, and only ever typed a single key in the internal `assistant_config` k/v table. Replace it with method-level generics on `configure<T>` / `getConfig<T>()` so the type lives at the call site instead of occupying a class generic slot. Update tests, the assistant example, and all docs (README, docs/think, design/think, cloudflare-docs think.mdx) to the new signature. Breaking change is captured in a changeset. Made-with: Cursor
Propose making multi-session support in Think a composition pattern rather than an internal feature. Core choices: - Ship a `Chats` parent Agent for the session index + shared state; one directory DO per user/tenant, one Think DO per conversation. - Ship generic `RemoteContextProvider` / `RemoteSearchProvider` so a Session on one DO can read/write a context block on another DO via RPC. - Add `Think#parentAgent<P>()` as a thin helper to obtain a typed stub of the immediate facet parent. - Ship a `useChats()` React hook and an `examples/chats` reference. - Cleanup: drop the unused `_sessionId()` stub and `session_id` column from `assistant_config`. Supersedes the unimplemented `SessionManager`-inside-Think plan from think-sessions.md. `SessionManager` stays available as an advanced primitive in agents/experimental but Think itself doesn't use it. Rationale: Durable Objects are single-threaded, so hosting many Sessions inside one DO serializes inference across a user's chats. Per-chat DOs get true parallelism and scale horizontally; the rest is composition. Status: proposed. Includes explicit follow-ups list for everything intentionally left out of v1 (forks, indexed cross-chat search, LLM titles, GC/export, multi-tenant-per-directory, etc.). Made-with: Cursor
🦋 Changeset detectedLatest commit: 4c6e75a 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 |
Formatting-only: realigned a markdown table in docs/think/index.md and converted *italic* to _italic_ in the multi-session RFC. No content changes. Made-with: Cursor
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Merged
This was referenced Apr 21, 2026
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.
Two related changes to
@cloudflare/thinkin one branch.1. Align
Thinkgenerics withAgent/AIChatAgentThink<Env, Config>becomesThink<Env, State, Props>extendingAgent<Env, State, Props>, so subclasses get properly typedthis.state,this.setState(),initialState, andthis.ctx.props— the same wayAIChatAgentdoes.The old
Configclass generic was occupying the slot whereAgent/AIChatAgentputState, and only ever typed a single row in the internalassistant_configk/v table. It's replaced with method-level generics onconfigure<T>()/getConfig<T>()so the config shape lives at the call site instead of consuming a class generic.Migration:
Tests, the assistant example, docs, and the cloudflare-docs
think.mdxpage updated to match. Breaking change captured in a changeset.2. RFC: Think multi-session via composition (
design/rfc-think-multi-session.md)Proposes how to do multi-session in Think before we ship 1.0, while we still have room for breaking changes:
Chatsparent Agent for the session index + shared state; one directory DO per user/tenant, one Think DO per conversation.RemoteContextProvider/RemoteSearchProviderinagents/experimental/memory/session/providersso a Session on one DO can read/write a context block on another DO via RPC.Think#parentAgent<P>()helper.useChats()React hook andexamples/chatsreference._sessionId()stub andsession_idcolumn fromassistant_config.Supersedes the unimplemented
SessionManager-inside-Think plan fromdesign/think-sessions.md.SessionManagerstays available as an advanced primitive inagents/experimentalbut Think itself will not use it.Rationale: DOs are single-threaded, so hosting many Sessions inside one DO would serialize inference across a user's chats. Per-chat DOs get true parallelism and scale horizontally; the rest is composition.
Includes an explicit Follow-ups section for everything intentionally left out of v1 (forks, indexed cross-chat search, LLM titles, GC/export, multi-tenant-per-directory, shared workspace across chats, the
AgentContextProvider→SqliteContextProviderrename, etc.) so none of it is forgotten.Status: proposed. Looking for feedback on the shape before any implementation commits.
Test plan
npm run check— all 74 projects typecheck, oxfmt/oxlint/sherif/exports clean@cloudflare/thinktests: 249/249 passingexamples/assistanttsconfig typechecks@cloudflare/ai-chatprogrammatic-turns.test.ts— flaked once in parallelnx run-many teston my machine; passes 3/3 when run in isolation. Unrelated package to my changes; CI will give the final word.Made with Cursor