Skip to content

Commit d1b8b76

Browse files
committed
feat(bedrock): show progress updates as text before their tool call
With reasoning off, Bedrock requests display "updates" for Opus 5.5, Fable 5/5.1 and Mythos 5.1 (c7afb17). Under that display only progress-update blocks carry text: short notes the model writes for the user between tool calls. Zoo showed them in the collapsed Thinking box. Anthropic's docs say to render them as text before the tool_use block they introduce: - https://platform.claude.com/docs/en/build-with-claude/thinking#progress-updates - https://platform.claude.com/docs/en/models/opus-5-5/migration-guide#text-between-tool-calls Bedrock now emits that text as a new `progress_update` stream chunk. Task shows it as its own text row, but leaves it out of the assistant text recorded in the API history. The provider expects the original thinking block back, and a text block with the same content would be an edit of the turn. With reasoning on (display "summarized"), reasoning summaries and progress updates can't be told apart, so they stay in the Thinking box. Text blocks now accumulate their own chunks instead of copying the whole-response buffer. Otherwise a text block started after a progress update would repeat the text from before it. See also Zoo-Code-Org#1820.
1 parent 26ec28c commit d1b8b76

6 files changed

Lines changed: 139 additions & 13 deletions

File tree

‎src/api/providers/__tests__/bedrock.spec.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,47 @@ describe("AwsBedrockHandler", () => {
18621862
expect(commandArg.inferenceConfig?.temperature).toBeUndefined()
18631863
})
18641864

1865+
it.each([
1866+
[false, "progress_update"],
1867+
[true, "reasoning"],
1868+
] as const)(
1869+
"with reasoning enabled=%s, streams Claude Opus 5.5 thinking text as %s chunks",
1870+
async (enableReasoningEffort, expectedType) => {
1871+
const provider = new AwsBedrockHandler({
1872+
apiModelId: "global.anthropic.claude-opus-5-5",
1873+
enableReasoningEffort,
1874+
modelMaxTokens: 32_000,
1875+
})
1876+
provider["client"].send = vi.fn().mockResolvedValue({
1877+
stream: asyncStreamFrom([
1878+
{ contentBlockStart: { contentBlockIndex: 0, contentBlock: { reasoningContent: {} } } },
1879+
{
1880+
contentBlockDelta: {
1881+
contentBlockIndex: 0,
1882+
delta: { reasoningContent: { text: "Re-running the check." } },
1883+
},
1884+
},
1885+
{
1886+
contentBlockDelta: {
1887+
contentBlockIndex: 0,
1888+
delta: { reasoningContent: { signature: "sig" } },
1889+
},
1890+
},
1891+
{ messageStop: { stopReason: "tool_use" } },
1892+
]),
1893+
})
1894+
1895+
const chunks = await collectStream(provider.createMessage("System prompt", messages))
1896+
1897+
const thinkingChunks = chunks.filter(
1898+
(chunk) => chunk.type === "progress_update" || chunk.type === "reasoning",
1899+
)
1900+
expect(thinkingChunks.filter((chunk) => chunk.text !== "")).toEqual([
1901+
{ type: expectedType, text: "Re-running the check." },
1902+
])
1903+
},
1904+
)
1905+
18651906
it.each(["anthropic.claude-sonnet-5", "anthropic.claude-opus-5", "anthropic.claude-opus-4-8"])(
18661907
"does not request the updates display beta for %s",
18671908
async (apiModelId) => {

‎src/api/providers/bedrock.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
} from "@roo-code/types"
4040
import { TelemetryService } from "@roo-code/telemetry"
4141

42-
import { ApiStream } from "../transform/stream"
42+
import type { ApiStream, ApiStreamChunk } from "../transform/stream"
4343
import { BaseProvider } from "./base-provider"
4444
import { logger } from "../../utils/logging"
4545
import { Package } from "../../shared/package"
@@ -622,9 +622,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
622622
}
623623

624624
const thinkingDisplay = additionalModelRequestFields?.thinking
625-
if (thinkingDisplay?.type === "adaptive" && thinkingDisplay.display === "updates") {
625+
// Under "updates" only progress-update blocks carry text, so all streamed thinking text
626+
// is prose for the user, rendered like assistant text ahead of its tool call.
627+
// See https://platform.claude.com/docs/en/build-with-claude/thinking#progress-updates
628+
const thinkingTextIsProgressUpdate =
629+
thinkingDisplay?.type === "adaptive" && thinkingDisplay.display === "updates"
630+
if (thinkingTextIsProgressUpdate) {
626631
anthropicBetas.push(THINKING_DISPLAY_UPDATES_BETA)
627632
}
633+
const thinkingTextChunk = (text: string): ApiStreamChunk =>
634+
thinkingTextIsProgressUpdate ? { type: "progress_update", text } : { type: "reasoning", text }
628635

629636
// Apply anthropic_beta to additionalModelRequestFields if any betas are needed
630637
if (anthropicBetas.length > 0) {
@@ -807,6 +814,13 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
807814

808815
// Check if this is a reasoning block (AWS SDK structure)
809816
if (cbStart.contentBlock?.reasoningContent) {
817+
if (thinkingTextIsProgressUpdate) {
818+
// Each update is followed by its own tool call, which already separates them.
819+
if (cbStart.contentBlock.reasoningContent.text) {
820+
yield thinkingTextChunk(cbStart.contentBlock.reasoningContent.text)
821+
}
822+
continue
823+
}
810824
if (cbStart.contentBlockIndex && cbStart.contentBlockIndex > 0) {
811825
yield { type: "reasoning", text: "\n" }
812826
}
@@ -865,10 +879,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
865879
if (delta) {
866880
// Check for reasoningContent property (AWS SDK structure)
867881
if (delta.reasoningContent?.text) {
868-
yield {
869-
type: "reasoning",
870-
text: delta.reasoningContent.text,
871-
}
882+
yield thinkingTextChunk(delta.reasoningContent.text)
872883
continue
873884
}
874885

@@ -886,10 +897,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
886897

887898
// Handle alternative thinking structure (fallback for older SDK versions)
888899
if (delta.type === "thinking_delta" && delta.thinking) {
889-
yield {
890-
type: "reasoning",
891-
text: delta.thinking,
892-
}
900+
yield thinkingTextChunk(delta.thinking)
893901
} else if (delta.text) {
894902
yield {
895903
type: "text",

‎src/api/transform/stream.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type ApiStream = AsyncGenerator<ApiStreamChunk>
22

33
export type ApiStreamChunk =
44
| ApiStreamTextChunk
5+
| ApiStreamProgressUpdateChunk
56
| ApiStreamUsageChunk
67
| ApiStreamReasoningChunk
78
| ApiStreamThinkingCompleteChunk
@@ -31,6 +32,20 @@ export interface ApiStreamTextChunk {
3132
text: string
3233
}
3334

35+
/**
36+
* Text the model wrote for the user between tool calls, delivered by the provider
37+
* inside a `thinking` block rather than a `text` block.
38+
*
39+
* Rendered like assistant text ahead of the tool call it introduces, but not recorded
40+
* as a `text` block in the API history: the provider expects it back as the original
41+
* thinking block.
42+
* See https://platform.claude.com/docs/en/models/opus-5-5/migration-guide#text-between-tool-calls
43+
*/
44+
export interface ApiStreamProgressUpdateChunk {
45+
type: "progress_update"
46+
text: string
47+
}
48+
3449
/**
3550
* Reasoning/thinking chunk from the API stream.
3651
* For Anthropic extended thinking, this may include a signature field

‎src/core/task/Task.ts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,18 +3552,45 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
35523552
this.presentAssistantMessageSafe()
35533553
break
35543554
}
3555+
case "progress_update": {
3556+
// Shown like assistant text, but kept out of `assistantMessage`:
3557+
// the provider expects it back as its thinking block, not as text.
3558+
const lastBlock = this.assistantMessageContent[this.assistantMessageContent.length - 1]
3559+
if (lastBlock?.type === "text" && lastBlock.partial && lastBlock.progressUpdate) {
3560+
lastBlock.content += chunk.text
3561+
} else {
3562+
if (lastBlock?.type === "text" && lastBlock.partial) {
3563+
lastBlock.partial = false
3564+
}
3565+
this.assistantMessageContent.push({
3566+
type: "text",
3567+
content: chunk.text,
3568+
partial: true,
3569+
progressUpdate: true,
3570+
})
3571+
this.userMessageContentReady = false
3572+
}
3573+
/* v8 ignore next -- streaming presenter; .catch lives in presentAssistantMessageSafe (covered) */
3574+
this.presentAssistantMessageSafe()
3575+
break
3576+
}
35553577
case "text": {
35563578
assistantMessage += chunk.text
35573579

35583580
// Native tool calling: text chunks are plain text.
35593581
// Create or update a text content block directly
3582+
// Blocks accumulate their own chunks: `assistantMessage` spans the whole
3583+
// response and would repeat earlier text in a block started after a progress update.
35603584
const lastBlock = this.assistantMessageContent[this.assistantMessageContent.length - 1]
3561-
if (lastBlock?.type === "text" && lastBlock.partial) {
3562-
lastBlock.content = assistantMessage
3585+
if (lastBlock?.type === "text" && lastBlock.partial && !lastBlock.progressUpdate) {
3586+
lastBlock.content += chunk.text
35633587
} else {
3588+
if (lastBlock?.type === "text" && lastBlock.partial) {
3589+
lastBlock.partial = false
3590+
}
35643591
this.assistantMessageContent.push({
35653592
type: "text",
3566-
content: assistantMessage,
3593+
content: chunk.text,
35673594
partial: true,
35683595
})
35693596
this.userMessageContentReady = false

‎src/core/task/__tests__/Task.spec.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,39 @@ describe("Cline", () => {
963963
])
964964
})
965965

966+
it("shows a progress update as text before its tool call without recording it as text", async () => {
967+
const task = new Task({
968+
provider: mockProvider,
969+
apiConfiguration: mockApiConfig,
970+
task: "progress update test",
971+
startTask: false,
972+
})
973+
vi.spyOn(task.diffViewProvider, "reset").mockResolvedValue(undefined)
974+
vi.spyOn(getTaskTestAccess(task), "safeEnsureModelFetched").mockResolvedValue(stubModelInfo)
975+
vi.spyOn(getTaskTestAccess(task), "presentAssistantMessageSafe").mockImplementation(() => {})
976+
vi.spyOn(task, "attemptApiRequest").mockImplementation(() =>
977+
asyncStreamFrom<ApiStreamChunk>([
978+
{ type: "text", text: "Checking the file." },
979+
{ type: "progress_update", text: "Re-running the " },
980+
{ type: "progress_update", text: "check." },
981+
{ type: "tool_call_partial", index: 0, id: "call_read", name: "read_file" },
982+
{ type: "tool_call_partial", index: 0, arguments: '{"path":"a.ts"}' },
983+
]),
984+
)
985+
986+
await task.recursivelyMakeClineRequests([{ type: "text", text: "progress update test" }])
987+
988+
expect(task.assistantMessageContent.slice(0, 2)).toMatchObject([
989+
{ type: "text", content: "Checking the file." },
990+
{ type: "text", content: "Re-running the check.", progressUpdate: true },
991+
])
992+
const assistantEntry = task.apiConversationHistory.find((message) => message.role === "assistant")
993+
expect(assistantEntry?.content).toEqual([
994+
{ type: "text", text: "Checking the file." },
995+
{ type: "tool_use", id: "call_read", name: "read_file", input: { path: "a.ts" } },
996+
])
997+
})
998+
966999
it("blocks a truncated write_to_file call instead of executing it (issue #1221)", async () => {
9671000
// Regression test for #1221: if the model's stream is cut off mid-way
9681001
// through a write_to_file tool call's `content` argument (e.g. it hits

‎src/shared/tools.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface TextContent {
2121
type: "text"
2222
content: string
2323
partial: boolean
24+
/** Set when the text is a progress update the provider delivered inside a thinking block. */
25+
progressUpdate?: boolean
2426
}
2527

2628
export const toolParamNames = [

0 commit comments

Comments
 (0)