Skip to content

Bedrock streaming minimal#496

Merged
droot merged 7 commits into
GoogleCloudPlatform:mainfrom
nirmata:bedrock-streaming-minimal
Aug 26, 2025
Merged

Bedrock streaming minimal#496
droot merged 7 commits into
GoogleCloudPlatform:mainfrom
nirmata:bedrock-streaming-minimal

Conversation

@augustintsang
Copy link
Copy Markdown
Contributor

AWS Bedrock Integration Fixes:

Summary
This PR fixes critical issues with AWS Bedrock integration, enabling full streaming support with tool calls and proper conversation history initialization. These changes bring AWS Bedrock to feature parity with other providers and achieve 100% success rate on benchmark tests.

Key Changes

Fixed Streaming Tool Calls
Resolved AWS SDK document marshaler/unmarshaler limitation that caused empty tool arguments in streaming mode
Added tool state tracking to accumulate streaming JSON input
Implemented proper argument parsing in ContentBlockStop handler
Extended bedrockToolPart with pre-parsed arguments for streaming case

Implemented Conversation Initialization
Added full Initialize() method to restore conversation history from previous sessions
Properly converts api.Message to AWS Bedrock types.Message format
Supports both user and assistant message roles

Enhanced Content Processing
Introduced addContentsToHistory() for unified content handling
Added support for FunctionCallResult in conversation history
Refactored Send() and SendStreaming() to use shared content processing logic
Properly handles tool results with AWS Bedrock's ToolResultBlock format

Improved Streaming Response Handling
Added streamingArgs field to pass parsed arguments through streaming pipeline
Updated conversation history to include completed tools from streaming
Removed verbose logging for cleaner output

Performance Impact

Before: 90% success rate (9/10 tests) for Claude Sonnet 4
After: 100% success rate (10/10 tests) for both Claude 3.7 and Claude Sonnet 4, Native tool calling without tool shim enabled

Testing

All benchmark tests passing (10/10)
Streaming tool calls working correctly
Conversation history preservation functional
Usage metadata extraction verified

Breaking Changes
None - All changes are backward compatible.

Related Issues
Fixes streaming tool call failures in AWS Bedrock integration where AsFunctionCalls() would return empty arguments due to AWS SDK internal type limitations.

AIWithShrey and others added 6 commits August 13, 2025 19:25
Addresses the core AWS SDK document marshaler/unmarshaler limitation
identified in streaming mode where AsFunctionCalls() returns empty arguments.

Essential changes only:
- Add args field to bedrockToolPart for pre-parsed streaming arguments
- Update AsFunctionCalls() with fallback logic (streaming -> unmarshaling)
- Add tool state tracking and JSON parsing in ContentBlockStop handler
- Extend streaming response structures to pass parsed arguments
- Update conversation history to include completed tools

Fixes: Empty tool arguments in streaming mode due to AWS SDK internal types
Root cause: Cannot create documentUnmarshaler instances for streaming case
Revert the full Initialize() implementation back to original stub
to keep only essential streaming tool call fixes.

Changes:
- Revert Initialize() from full implementation to error stub
- Remove unnecessary message conversion logic
- Keep only core streaming tool call fixes (6 essential changes)

This maintains the minimal fix approach focused solely on the
AWS SDK document marshaler/unmarshaler limitation.
- Implement proper Initialize() method for conversation history
- Add addContentsToHistory() for better content processing
- Refactor Send() and SendStreaming() to use shared content processing
- Fix tool use block creation with proper Input document
- Add support for FunctionCallResult in conversation history
Both Claude 3.7 Sonnet and Claude Sonnet 4 achieved 10/10 (100%) success rate on standardized Kubernetes benchmark tasks, demonstrating excellent performance with native tool calling implementation.
- Keep AWS Bedrock 100% benchmark results
- Maintain full Initialize() implementation for Bedrock
- Integrate upstream changes for other providers
Comment thread README.md Outdated
@droot droot requested a review from noahlwest August 19, 2025 17:53
- Fix README.md benchmark table ordering (gemini first, remove bold)
- Implement dynamic status detection in Bedrock integration
  - Check Result.error and Result.status fields for failure indicators
  - Set ToolResultStatusError when errors detected
- Fix MCP client to return structured error data instead of Go errors
  - Preserve error content in JSON format for proper LLM processing
  - Prevents conversion of business logic failures to execution errors

This resolves the issue where all tool results were hardcoded as success,
causing LLMs to retry failed operations indefinitely until max iterations.
@droot droot merged commit a805656 into GoogleCloudPlatform:main Aug 26, 2025
1 check passed
@augustintsang augustintsang deleted the bedrock-streaming-minimal branch September 10, 2025 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants