Normalize Bedrock Mantle commentary before replay (#62095)

## Why

Bedrock Mantle's reasoning prefix omits empty `annotations` on assistant commentary. Replayed commentary needs to preserve that form to keep the prefix stable.

## What changed

Add a provider hook to normalize completed output items before they enter model history. For Mantle, omit empty `annotations` from assistant commentary text while preserving nonempty annotations, final answers, and Bedrock Runtime output.

## Testing

Add regression coverage for Mantle and Runtime that checks commentary replay across a tool continuation and a subsequent turn, including reasoning and tool item ordering and preservation of final-answer content.

GitOrigin-RevId: ecd5b9b5dca8c24956a6379c9d0fb643e4427af3
This commit is contained in:
Adnan Hajar
2026-11-17 18:55:30 +00:00
committed by copyberry
parent 04cfdee311
commit cb64621bf3
4 changed files with 122 additions and 0 deletions
+1
View File
@@ -2962,6 +2962,7 @@ where
};
let event = match event {
Ok(ResponseEvent::OutputItemDone(mut item)) => {
provider.normalize_completed_output_item(&mut item);
// Assign IDs after interceptors, which may replace provider items.
// Reuse the added event's ID so tracing and the harness agree.
if item.id().is_none_or(|id| id.is_empty()) {