mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 13:04:08 +00:00
fix(ai): signature support for non-Anthropic models in Amazon Bedrock provider (#727)
* Add Amazon Bedrock models test suite for agent package Tests basic prompts, multi-turn conversations with thinking, and synthetic thinking signatures across all Bedrock models. Known issues are categorized and skipped: - Models requiring inference profile (5) - Invalid model IDs for us-east-1 region (6) - Max tokens config exceeds model limit (2) - No signature support in reasoningContent (10) - Rejects reasoning content in user messages (25) - Validates signature format - Anthropic newer models (7) * Fix Bedrock signature support for non-Anthropic models Only include the signature field in reasoningContent.reasoningText for Anthropic Claude models. Other models (OpenAI, Qwen, Minimax, Moonshot, etc.) reject this field with: "This model doesn't support the reasoningContent.reasoningText.signature field" This fix enables multi-turn conversations with thinking content for 10 additional Bedrock models that previously failed. https://buildwithpi.ai/session?7e39c05f66ea358da3f993c267fe3e29 * Add a CHANGELOG entry
This commit is contained in:
parent
a497fccd06
commit
9a438465eb
3 changed files with 318 additions and 5 deletions
|
|
@ -290,6 +290,17 @@ function supportsPromptCaching(model: Model<"bedrock-converse-stream">): boolean
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the model supports thinking signatures in reasoningContent.
|
||||
* Only Anthropic Claude models support the signature field.
|
||||
* Other models (OpenAI, Qwen, Minimax, Moonshot, etc.) reject it with:
|
||||
* "This model doesn't support the reasoningContent.reasoningText.signature field"
|
||||
*/
|
||||
function supportsThinkingSignature(model: Model<"bedrock-converse-stream">): boolean {
|
||||
const id = model.id.toLowerCase();
|
||||
return id.includes("anthropic.claude") || id.includes("anthropic/claude");
|
||||
}
|
||||
|
||||
function buildSystemPrompt(
|
||||
systemPrompt: string | undefined,
|
||||
model: Model<"bedrock-converse-stream">,
|
||||
|
|
@ -354,11 +365,22 @@ function convertMessages(context: Context, model: Model<"bedrock-converse-stream
|
|||
case "thinking":
|
||||
// Skip empty thinking blocks
|
||||
if (c.thinking.trim().length === 0) continue;
|
||||
contentBlocks.push({
|
||||
reasoningContent: {
|
||||
reasoningText: { text: sanitizeSurrogates(c.thinking), signature: c.thinkingSignature },
|
||||
},
|
||||
});
|
||||
// Only Anthropic models support the signature field in reasoningText.
|
||||
// For other models, we omit the signature to avoid errors like:
|
||||
// "This model doesn't support the reasoningContent.reasoningText.signature field"
|
||||
if (supportsThinkingSignature(model)) {
|
||||
contentBlocks.push({
|
||||
reasoningContent: {
|
||||
reasoningText: { text: sanitizeSurrogates(c.thinking), signature: c.thinkingSignature },
|
||||
},
|
||||
});
|
||||
} else {
|
||||
contentBlocks.push({
|
||||
reasoningContent: {
|
||||
reasoningText: { text: sanitizeSurrogates(c.thinking) },
|
||||
},
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown assistant content type");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue