Skip to content

Commit 004e913

Browse files
iamhitarthclaude
andcommitted
fix(agents): preserve thinking/redacted_thinking blocks in stripThoughtSignatures
stripThoughtSignatures removes thought_signature fields from content blocks for cross-provider compatibility. However, it also modifies thinking and redacted_thinking blocks, which Anthropic's API requires to be identical to the original response. When these modified blocks appear in the latest assistant message on a subsequent turn, the API rejects the request with: "thinking or redacted_thinking blocks in the latest assistant message cannot be modified" Skip thinking/redacted_thinking block types in stripThoughtSignatures to preserve them unchanged. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 5d51e99 commit 004e913

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/agents/pi-embedded-helpers/bootstrap.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export function stripThoughtSignatures<T>(
6565
if (!block || typeof block !== "object") {
6666
return block;
6767
}
68+
// Never modify thinking/redacted_thinking blocks — Anthropic requires these
69+
// to be identical to the original API response.
70+
const blockType = (block as { type?: unknown }).type;
71+
if (blockType === "thinking" || blockType === "redacted_thinking") {
72+
return block;
73+
}
6874
const rec = block as ContentBlockWithSignature;
6975
const stripSnake = shouldStripSignature(rec.thought_signature);
7076
const stripCamel = includeCamelCase ? shouldStripSignature(rec.thoughtSignature) : false;

0 commit comments

Comments
 (0)