feat(ai-chat): tool approval continuation + autoContinue default true#919
Merged
threepointone merged 3 commits intomainfrom Feb 16, 2026
Merged
feat(ai-chat): tool approval continuation + autoContinue default true#919threepointone merged 3 commits intomainfrom
threepointone merged 3 commits intomainfrom
Conversation
Add auto-continuation for tool approvals: CF_AGENT_TOOL_APPROVAL now accepts an optional autoContinue flag and, when approved and requested, triggers the agent to continue the conversation. The client hook forwards autoContinue when autoContinueAfterToolResult is enabled. Also add a cross-message fallback to handle tool-output-available / tool-output-error events that refer to tool calls in previous assistant messages (fixes silent data loss during continuation streams). Updates include type additions and multiple tests (e2e and unit) to cover approval/no-approval/autoContinue behaviors and a new changeset note.
Change the default behavior so autoContinueAfterToolResult is true. Updated useAgentChat implementation and JSDoc/default param, refreshed docs and README to reflect the new default, and added React tests verifying default=true, explicit false, and approvals behavior. Also added a changeset describing the minor version change. To restore previous behavior set autoContinueAfterToolResult: false in useAgentChat.
🦋 Changeset detectedLatest commit: 0e4ad43 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 |
commit: |
Contributor
Author
|
/bonk review this pr |
This comment was marked as resolved.
This comment was marked as resolved.
The fallback now checks `foundInCurrentMessage` independently of applyChunkToParts' return value, since it returns true for recognized chunk types even when the target part isn't found. Co-authored-by: Cursor <cursoragent@cursor.com>
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
Two related changes to
@cloudflare/ai-chatthat improve the tool approval (needsApproval) and auto-continuation experience:1. Tool approval auto-continuation (patch)
Ref: #918
The original issue reported a crash (
"Tool invocation not found") that was already fixed in main — theapplyChunkToPartshandler no longer throws. However, the bonk analysis identified two real remaining gaps:Missing continuation plumbing for
CF_AGENT_TOOL_APPROVAL. When a tool withneedsApproval: trueis approved,_applyToolApprovalupdates the tool state toapproval-respondedand returns — but nothing triggers the LLM to continue. Compare this toCF_AGENT_TOOL_RESULTwhich has fullautoContinuesupport (waits for active stream, callsonChatMessage, merges continuation into last assistant message). This PR adds the same continuation logic toCF_AGENT_TOOL_APPROVAL, gated behindautoContinue: trueandapproved: true.Silent data loss for cross-message tool outputs. When a continuation stream emits
tool-output-availablefor a tool call that lives in a previous assistant message (common in the approval flow),applyChunkToPartsonly searches the current streaming message's parts — the update is silently dropped. This PR adds a fallback in_streamSSEReplythat uses_findAndUpdateToolPart(which searches across all messages with retry logic) when the tool part isn't found in the current message.2.
autoContinueAfterToolResultdefaultfalse→true(minor)Server-executed tools already auto-continue via
streamText's multi-step. Client tools and approvals defaulting tofalsecreates an asymmetry where the same conceptual flow (LLM calls tool → tool runs → LLM responds) behaves differently depending on where the tool executes. This made every developer using client tools orneedsApprovaldiscover and enable the option to get expected behavior.Now
autoContinueAfterToolResultdefaults totrue. The escape hatch isautoContinueAfterToolResult: false.Changes
src/types.tsautoContinuetoCF_AGENT_TOOL_APPROVALmessage typesrc/index.ts_streamSSEReplysrc/react.tsxtrue,sendToolApprovalToServernow passesautoContinuesrc/tests/client-tool-duplicate-message.test.tssrc/react-tests/use-agent-chat.test.tsxtruesends correct wire valuese2e/client-tools.spec.tsREADME.md,docs/chat-agents.md,docs/client-tools-continuation.mdNotes for reviewers
autoContinueis optional onCF_AGENT_TOOL_APPROVAL. Clients that don't send it get the same behavior as before (no continuation). Existing server-side unit tests pass unchanged since they explicitly setautoContinuein WebSocket messages.approved: true. Rejections (approved: false) never trigger continuation, even withautoContinue: true. This is intentional — a rejected tool shouldn't cause the LLM to continue as if the tool succeeded.input-available,input-streaming,approval-responded,approval-requested) to handle tool outputs arriving for tools in various lifecycle stages.autoContinueAfterToolResult, so they all silently pick up the better default.Test plan
truesendsautoContinue: trueon tool results and approvalsMade with Cursor