-
Notifications
You must be signed in to change notification settings - Fork 281
fix(api): preserve provider reasoning across tool calls #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,84 @@ describe("convertToBedrockConverseMessages", () => { | |
| ]) | ||
| }) | ||
|
|
||
| it("converts internal reasoning blocks to Bedrock reasoning content", () => { | ||
| // The Anthropic SDK does not model Zoo Code's internal reasoning block, | ||
| // though this converter receives it from persisted conversation history. | ||
| const messages = [ | ||
| { | ||
| role: "assistant", | ||
| content: [{ type: "reasoning", text: "I should inspect the file first.", summary: [] }], | ||
| }, | ||
| ] as unknown as Anthropic.Messages.MessageParam[] | ||
|
|
||
| expect(convertToBedrockConverseMessages(messages)).toEqual([ | ||
| { | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| reasoningContent: { | ||
| reasoningText: { text: "I should inspect the file first." }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it("converts signed thinking blocks to Bedrock reasoning content", () => { | ||
| const messages: Anthropic.Messages.MessageParam[] = [ | ||
| { | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| type: "thinking", | ||
| thinking: "I should inspect the file first.", | ||
| signature: "signed-reasoning", | ||
| }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| expect(convertToBedrockConverseMessages(messages)).toEqual([ | ||
| { | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| reasoningContent: { | ||
| reasoningText: { | ||
| text: "I should inspect the file first.", | ||
| signature: "signed-reasoning", | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]) | ||
| }) | ||
|
Comment on lines
+53
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,105p' src/api/transform/bedrock-converse-format.ts
sed -n '1,115p' src/api/transform/__tests__/bedrock-converse-format.spec.ts
rg -n -C 3 'type: "thinking"|signature\??:|reasoningText' src packagesRepository: Zoo-Code-Org/Zoo-Code Length of output: 44080 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- converter callers ---'
rg -n -C 4 'convertToBedrockConverseMessages' src
printf '%s\n' '--- relevant stream/input types ---'
sed -n '1,75p' src/api/transform/stream.ts
printf '%s\n' '--- Bedrock conversion tests and thinking fixtures ---'
rg -n -C 5 'thinking|signature|reasoningContent|convertToBedrockConverseMessages' src/api/transform/__tests__ src/api/providers/__tests__/bedrock-reasoning.spec.tsRepository: Zoo-Code-Org/Zoo-Code Length of output: 50378 🤖 get_repo_knowledge executed:
Length of output: 13175 Add strict coverage for unsigned thinking blocks.
🤖 Prompt for AI Agents |
||
|
|
||
| it("converts unsigned thinking blocks without adding a signature", () => { | ||
| // Persisted provider output can omit a signature even though the Anthropic SDK requires one. | ||
| const messages = [ | ||
| { | ||
| role: "assistant", | ||
| content: [{ type: "thinking", thinking: "I should inspect the file first." }], | ||
| }, | ||
| ] as unknown as Anthropic.Messages.MessageParam[] | ||
|
|
||
| expect(convertToBedrockConverseMessages(messages)).toStrictEqual([ | ||
| { | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| reasoningContent: { | ||
| reasoningText: { text: "I should inspect the file first." }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it("converts messages with images correctly", () => { | ||
| const messages: Anthropic.Messages.MessageParam[] = [ | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 13835
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 13386
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 23243
Add sequential coverage for signature reset.
MiniMaxHandlerstores the signature on the handler instance, andprepareApiConversationMessagereads it for later history. The current test uses one stream, while each test creates a fresh handler. Add a test that completes a signed request, completes a second request without asignature_delta, and assertshandler.getThoughtSignature()isundefined. Without this coverage, removing the reset can leave the previous signature available for the next request.🤖 Prompt for AI Agents