Repository navigation
feat(think): expose the running turn's identity to hooks and tools - #2350
Merged
Merged
Conversation
TurnContext gains requestId, trigger, abortSignal and messenger; ToolCallContext gains requestId; a public activeTurn getter reads the admitted turn from anywhere inside it. Messenger context now travels with the turn instead of an instance field, so concurrent messenger turns no longer read or clear each other's thread. Refs #1894, #2127, #2218, #2240, #2309 Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 9379793 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
threepointone
added this pull request to stack #2357
September 24, 2026 01:08
threepointone
marked this pull request as ready for review
September 24, 2026 01:12
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
…terToolCall activeTurn and getMessengerContext() read AsyncLocalStorage, which async work scheduled by a turn inherits after the turn is released. Both now return undefined once their turn is over. afterToolCall's context carries the turn's requestId, like beforeToolCall's. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
⚪ agents import sizesMeasured 344 runtime imports as minified bundles. The primary size is gzip; raw minified size is included for diagnosis. An existing import growing by more than 10% is marked red. This report is informational.
Compared No import sizes changed. All 344 current runtime imports
Reported by agent-think[bot]. |
Co-authored-by: Cursor <cursoragent@cursor.com>
Merged
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.
Hooks and tools can now tell which turn they are running in.
TurnContext(passed tobeforeTurn) gainsrequestId,trigger,abortSignalandmessenger.ToolCallContext(passed tobeforeToolCall/afterToolCall) gainsrequestId, which matches therequestIdthatonChatResponsereceives, so the three hooks can be correlated.this.activeTurngetter returns{ requestId, trigger, continuation, channel }for the admitted turn, orundefinedoutside a turn.getMessengerContext()now reads per-turnAsyncLocalStorageinstead of a shared field. Two messenger turns that overlap no longer see each other's thread. The regression test holds turn A inbeforeTurn, runs turn B, and then releases A; onmain, B sees anullcontext.Closes #1894
Closes #2127
Closes #2218
Closes #2240
Closes #2309
Docs:
docs/think/lifecycle-hooks.md(TurnContext table and a new "Turn identity" section) anddocs/think/messengers.md.