Skip to content

[Feature Request]: Implement Bedrock V2 Client (ModelClientV2) #2346

@priyansh4320

Description

@priyansh4320

Is your feature request related to a problem? Please describe.

Implement Bedrock V2 Client (ModelClientV2)

Why Implement Bedrock V2 Client?

The current Bedrock client (api_type: "bedrock") uses the legacy ModelClient interface, which returns flattened ChatCompletion responses. This limits access to rich content types and creates inconsistencies across providers.

Current Limitations (V1 Client)

  1. Lost Rich Content: Tool calls, images, and other structured content are flattened or lost during response processing
  2. Provider-Specific Parsing: Requires manual parsing of nested structures to access different content types
  3. No Type Safety: Responses are untyped dictionaries, making it easy to introduce bugs
  4. Limited Forward Compatibility: New Bedrock features require code changes to support
  5. Inconsistent API: Different response formats across OpenAI, Anthropic, Gemini, and Bedrock clients

Benefits of V2 Client

  1. Rich Content Preservation

    • All content types (text, images, tool calls, citations) preserved as typed ContentBlock objects
    • No data loss during response transformation
    • Direct access to structured content
  2. Better Developer Experience

   # V1 - Manual parsing
   response = client.create(params)
   messages = client.message_retrieval(response)
   content = messages[0] if messages else ""
 
   # V2 - Direct property access
   response = client.create(params)
   text = response.text                    # All text content
   tool_calls = response.get_tool_calls()   # Tool calls as objects
   images = response.get_content_by_type("image")  # Image content blocks
   

Type Safety

  • Pydantic models with automatic validation
  • Typed content blocks (TextContent, ImageContent, ToolCallContent, etc.)
  • Enum-based content types
  • IDE autocomplete and type checking support
  1. Forward Compatibility

    • Unknown content types automatically handled via GenericContent
    • No code changes needed when Bedrock adds new features
    • Future-proof architecture
  2. Provider-Agnostic Format

    • Unified response format across OpenAI, Anthropic, Gemini, and Bedrock
    • Easier to switch between providers
    • Consistent developer experience across all LLM providers
  3. Backward Compatible

    • Can use create_v1_compatible() to get V1 format when needed
    • Works seamlessly with existing V1 clients in group chats
    • No breaking changes to existing code
  4. Alignment with AG2 Architecture

    • Follows the ModelClientV2 protocol already implemented for OpenAI
    • Supports the unified response model across all providers

Use Cases Enabled

  • Structured Outputs: Better support for Pydantic models and JSON schemas
  • Multimodal Applications: Proper handling of images and other media types
  • Tool Calling: Rich access to tool call information
  • Cost Tracking: Built-in cost calculation per response
  • Future Features: Ready for new Bedrock capabilities without code changes

Migration Path

Migration is simple - just change api_type:

# V1
{"api_type": "bedrock", "model": "...", ...}

V2 (recommended)

{"api_type": "bedrock_v2", "model": "...", ...} # All other configuration parameters remain identical.

Implementation Status

Completed: Bedrock V2 client implementation with full ModelClientV2 protocol support
Completed: Comprehensive unit tests
Completed: Integration tests
Completed: Documentation updates
Completed: Backward compatibility layer

Related

  • OpenAI V2 Client: Reference implementation

Describe the solution you'd like

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions