fix(bedrock): drop ActionRequired and ToolConfirmationRequest blocks instead of sending blank text (#12843)
This commit is contained in:
@@ -165,6 +165,12 @@ pub fn to_bedrock_message_with_caching(
|
||||
.content
|
||||
.iter()
|
||||
.filter(|content| {
|
||||
if matches!(
|
||||
content,
|
||||
MessageContent::ActionRequired(_) | MessageContent::ToolConfirmationRequest(_)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if !thinking_is_stale {
|
||||
return true;
|
||||
}
|
||||
@@ -196,11 +202,11 @@ pub fn to_bedrock_message_with_caching(
|
||||
pub fn to_bedrock_message_content(content: &MessageContent) -> Result<bedrock::ContentBlock> {
|
||||
Ok(match content {
|
||||
MessageContent::Text(text) => bedrock::ContentBlock::Text(text.text.to_string()),
|
||||
MessageContent::ToolConfirmationRequest(_tool_confirmation_request) => {
|
||||
bedrock::ContentBlock::Text("".to_string())
|
||||
MessageContent::ToolConfirmationRequest(_) => {
|
||||
bail!("ToolConfirmationRequest should be filtered before Bedrock conversion")
|
||||
}
|
||||
MessageContent::ActionRequired(_action_required) => {
|
||||
bedrock::ContentBlock::Text("".to_string())
|
||||
MessageContent::ActionRequired(_) => {
|
||||
bail!("ActionRequired should be filtered before Bedrock conversion")
|
||||
}
|
||||
MessageContent::Image(image) => {
|
||||
bedrock::ContentBlock::Image(to_bedrock_image(&image.data, &image.mime_type)?)
|
||||
@@ -1666,4 +1672,42 @@ mod tests {
|
||||
assert!(!bedrock_model_supports_temperature(&config));
|
||||
assert_eq!(inference_config.temperature(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_elicitation_message_becomes_empty() {
|
||||
use crate::conversation::message::{ActionRequired, ActionRequiredData};
|
||||
use rmcp::model::Role;
|
||||
|
||||
let elicitation_request = Message::new(
|
||||
Role::Assistant,
|
||||
Utc::now().timestamp(),
|
||||
vec![MessageContent::ActionRequired(ActionRequired {
|
||||
data: ActionRequiredData::Elicitation {
|
||||
id: "elicit-1".to_string(),
|
||||
message: "Choose something".to_string(),
|
||||
requested_schema: serde_json::json!({}),
|
||||
},
|
||||
})],
|
||||
);
|
||||
|
||||
let elicitation_response = Message::new(
|
||||
Role::User,
|
||||
Utc::now().timestamp(),
|
||||
vec![MessageContent::ActionRequired(ActionRequired {
|
||||
data: ActionRequiredData::ElicitationResponse {
|
||||
id: "elicit-1".to_string(),
|
||||
user_data: serde_json::json!({"choice": "yes"}),
|
||||
action: rmcp::model::ElicitationAction::Accept,
|
||||
},
|
||||
})],
|
||||
);
|
||||
|
||||
let request_result =
|
||||
to_bedrock_message_with_caching(&elicitation_request, false, None).unwrap();
|
||||
let response_result =
|
||||
to_bedrock_message_with_caching(&elicitation_response, false, None).unwrap();
|
||||
|
||||
assert!(request_result.content().is_empty());
|
||||
assert!(response_result.content().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user