bedrock: Preserve thinking blocks for Bedrock (#29602)

Fixes a regression from #29055, resolves #29290

Release Notes:

- agent: Fixed a regression that rendered Claude 3.7 Thinking unusable
on Bedrock.
This commit is contained in:
Shardul Vaidya 2025-04-29 12:18:32 -04:00 committed by GitHub
parent 83b8530e1f
commit fa40353fc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View file

@ -11,12 +11,14 @@ pub use aws_sdk_bedrockruntime::types::{
Tool as BedrockTool, ToolChoice as BedrockToolChoice, ToolConfiguration as BedrockToolConfig,
ToolInputSchema as BedrockToolInputSchema, ToolSpecification as BedrockToolSpec,
};
pub use aws_smithy_types::Blob as BedrockBlob;
use aws_smithy_types::{Document, Number as AwsNumber};
pub use bedrock::operation::converse_stream::ConverseStreamInput as BedrockStreamingRequest;
pub use bedrock::types::{
ContentBlock as BedrockRequestContent, ConversationRole as BedrockRole,
ConverseOutput as BedrockResponse, ConverseStreamOutput as BedrockStreamingResponse,
ImageBlock as BedrockImageBlock, Message as BedrockMessage,
ReasoningContentBlock as BedrockThinkingBlock, ReasoningTextBlock as BedrockThinkingTextBlock,
ResponseStream as BedrockResponseStream, ToolResultBlock as BedrockToolResultBlock,
ToolResultContentBlock as BedrockToolResultContentBlock,
ToolResultStatus as BedrockToolResultStatus, ToolUseBlock as BedrockToolUseBlock,

View file

@ -15,10 +15,11 @@ use bedrock::bedrock_client::types::{
StopReason,
};
use bedrock::{
BedrockAutoToolChoice, BedrockError, BedrockInnerContent, BedrockMessage, BedrockModelMode,
BedrockStreamingResponse, BedrockTool, BedrockToolChoice, BedrockToolConfig,
BedrockToolInputSchema, BedrockToolResultBlock, BedrockToolResultContentBlock,
BedrockToolResultStatus, BedrockToolSpec, BedrockToolUseBlock, Model, value_to_aws_document,
BedrockAutoToolChoice, BedrockBlob, BedrockError, BedrockInnerContent, BedrockMessage,
BedrockModelMode, BedrockStreamingResponse, BedrockThinkingBlock, BedrockThinkingTextBlock,
BedrockTool, BedrockToolChoice, BedrockToolConfig, BedrockToolInputSchema,
BedrockToolResultBlock, BedrockToolResultContentBlock, BedrockToolResultStatus,
BedrockToolSpec, BedrockToolUseBlock, Model, value_to_aws_document,
};
use collections::{BTreeMap, HashMap};
use credentials_provider::CredentialsProvider;
@ -626,6 +627,24 @@ pub fn into_bedrock(
None
}
}
MessageContent::Thinking { text, signature } => {
let thinking = BedrockThinkingTextBlock::builder()
.text(text)
.set_signature(signature)
.build()
.context("failed to build reasoning block")
.log_err()?;
Some(BedrockInnerContent::ReasoningContent(
BedrockThinkingBlock::ReasoningText(thinking),
))
}
MessageContent::RedactedThinking(blob) => {
let redacted =
BedrockThinkingBlock::RedactedContent(BedrockBlob::new(blob));
Some(BedrockInnerContent::ReasoningContent(redacted))
}
MessageContent::ToolUse(tool_use) => BedrockToolUseBlock::builder()
.name(tool_use.name.to_string())
.tool_use_id(tool_use.id.to_string())