Allow non-chat Think agent tools to complete#1483
Draft
whoiskatrin wants to merge 2 commits intomainfrom
Draft
Conversation
🦋 Changeset detectedLatest commit: a0dcd20 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
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
Fixes #1482.
Think agent-tool children previously treated "completed" as "the child produced assistant text after the run started." That made chat-like helpers work, but forced workflow/tool-step agents to emit sentinel text just to avoid an error terminal state.
This PR separates the agent-tool concerns:
A Think child agent-tool run can now complete successfully without emitting assistant text. Assistant text remains the default summary for chat-like helpers, while non-chat children can provide structured output via
getAgentToolOutput()and customize display text withgetAgentToolSummary().Follow-up:
isServerStreamingstuck after reconnectAfter the initial fix, @uuouter noted that
useAgentChat().isServerStreamingcould sometimes staytrueafter reconnect / finish.The issue was a race between two resume paths in
useAgentChat:cf_agent_stream_resumingbefore the AI SDK transport is awaiting resume.useAgentChattakes the fallback observer path, marks the stream as observed, and setsisServerStreamingtotrue.resumeStream()/ transport path later starts awaiting the same stream id.cf_agent_stream_resumingfor that same id is handled by the transport, which adds the id tolocalRequestIdsRef.cf_agent_use_chat_response { done: true }then goes through the transport-owned/local-request branch.isServerStreamingstucktrue.This PR now clears fallback observer state when a terminal local-request response belongs to the same stream id.
Changes
errorsolely because no assistant text was emitted.protected getAgentToolSummary(runId, output)as the summary hook paired with existinggetAgentToolOutput(runId).cf_agent_tool_child_runs.output_jsonso completed output survives later inspection.useAgentChat().isServerStreamingcleanup when a stream first enters the fallback resume observer path and later becomes transport-owned.docs/agent-tools.mdand update the design doc.@cloudflare/think.Testing
npm run checkcompletes successfully. It still prints existingsherifwarnings for package-less workspace directories, unrelated to this change.