Bases: BedrockLLMConfigEntry
LLMConfig entry for Bedrock V2 Client with ModelClientV2 architecture.
This uses the new BedrockV2Client from autogen.llm_clients which returns rich UnifiedResponse objects with typed content blocks (TextContent, ImageContent, ToolCallContent, etc.).
Example:
{
"api_type": "bedrock_v2", # <-- uses ModelClientV2 architecture
"model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
"aws_region": "us-east-1",
"aws_access_key": "...",
"aws_secret_key": "...",
}
Benefits over standard Bedrock client: - Returns UnifiedResponse with typed content blocks - Access to rich content via response.text, response.get_content_by_type() - Forward-compatible with unknown content types via GenericContent - Rich metadata and provider-specific information preserved - Type-safe with Pydantic validation - Supports structured outputs via response_format parameter
api_type class-attribute instance-attribute
max_tokens class-attribute instance-attribute
max_tokens = Field(default=None, ge=0, description='The maximum number of tokens to generate before stopping.')
top_p class-attribute instance-attribute
top_p = Field(default=None, ge=0, le=1, description='An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.So 0.1 means only the tokens comprising the top 10% probability mass are considered.You should either alter `temperature` or `top_p`, but not both.')
temperature class-attribute instance-attribute
temperature = Field(default=None, ge=0, le=1, description="Amount of randomness injected into the response. Use `temperature` closer to `0.0` for analytical / multiple choice, and closer to a model's maximum `temperature` for creative and generative tasks. Note that even with `temperature` of `0.0`, the results will not be fully deterministic.")
model class-attribute instance-attribute
model = Field(..., min_length=1)
api_key class-attribute instance-attribute
api_version class-attribute instance-attribute
base_url class-attribute instance-attribute
http_client class-attribute instance-attribute
voice class-attribute instance-attribute
model_client_cls class-attribute instance-attribute
response_format class-attribute instance-attribute
tags class-attribute instance-attribute
tags = Field(default_factory=list)
model_config class-attribute instance-attribute
model_config = ConfigDict(extra='allow', arbitrary_types_allowed=True)
aws_region instance-attribute
aws_access_key class-attribute instance-attribute
aws_secret_key class-attribute instance-attribute
aws_session_token class-attribute instance-attribute
aws_profile_name class-attribute instance-attribute
top_k class-attribute instance-attribute
k class-attribute instance-attribute
seed class-attribute instance-attribute
cache_seed class-attribute instance-attribute
supports_system_prompts class-attribute instance-attribute
supports_system_prompts = True
price class-attribute instance-attribute
price = Field(default=None, min_length=2, max_length=2)
timeout class-attribute instance-attribute
additional_model_request_fields class-attribute instance-attribute
additional_model_request_fields = None
total_max_attempts class-attribute instance-attribute
max_attempts class-attribute instance-attribute
mode class-attribute instance-attribute
create_client
Create BedrockV2Client instance.
Note: This is typically handled via OpenAIWrapper._register_default_client, but can be called directly if needed.
Source code in autogen/llm_clients/bedrock_v2.py
| def create_client(self) -> ModelClient: # pragma: no cover
"""Create BedrockV2Client instance.
Note: This is typically handled via OpenAIWrapper._register_default_client,
but can be called directly if needed.
"""
# Extract credentials, handling SecretStr
aws_access_key = self.aws_access_key.get_secret_value() if self.aws_access_key else None
aws_secret_key = self.aws_secret_key.get_secret_value() if self.aws_secret_key else None
aws_session_token = self.aws_session_token.get_secret_value() if self.aws_session_token else None
# BedrockV2Client is defined later in this module, but Python resolves it at runtime
# Using globals() to access the class defined in this module
BedrockV2Client = globals()["BedrockV2Client"] # noqa: N806
return BedrockV2Client(
aws_region=self.aws_region,
aws_access_key=aws_access_key,
aws_secret_key=aws_secret_key,
aws_session_token=aws_session_token,
aws_profile_name=self.aws_profile_name,
timeout=self.timeout,
total_max_attempts=self.total_max_attempts,
max_attempts=self.max_attempts,
mode=self.mode,
response_format=None, # Can be set via params in create() call
)
|
apply_application_config
apply_application_config(application_config)
Apply application level configurations.
Source code in autogen/llm_config/entry.py
| def apply_application_config(self, application_config: ApplicationConfig) -> Self:
"""Apply application level configurations."""
new_entry = self.model_copy()
new_entry.max_tokens = new_entry.max_tokens or application_config.max_tokens
new_entry.top_p = new_entry.top_p or application_config.top_p
new_entry.temperature = new_entry.temperature or application_config.temperature
return new_entry
|
check_base_url classmethod
Source code in autogen/llm_config/entry.py
| @field_validator("base_url", mode="before")
@classmethod
def check_base_url(cls, v: HttpUrl | str | None, info: ValidationInfo) -> str | None:
if v is None: # Handle None case explicitly
return None
# Allow WebSocket URLs as well as HTTP(S)
if not str(v).startswith(("https://", "http://", "wss://", "ws://")):
return f"http://{str(v)}"
return str(v)
|
serialize_base_url
Source code in autogen/llm_config/entry.py
| @field_serializer("base_url", when_used="unless-none") # Ensure serializer also respects None
def serialize_base_url(self, v: HttpUrl | None) -> str | None:
return str(v) if v is not None else None
|
serialize_api_key
Source code in autogen/llm_config/entry.py
| @field_serializer("api_key", when_used="unless-none")
def serialize_api_key(self, v: SecretStr) -> str:
return v.get_secret_value()
|
model_dump
model_dump(*args, exclude_none=True, **kwargs)
Source code in autogen/llm_config/entry.py
| def model_dump(self, *args: Any, exclude_none: bool = True, **kwargs: Any) -> dict[str, Any]:
return BaseModel.model_dump(self, exclude_none=exclude_none, *args, **kwargs)
|
model_dump_json
model_dump_json(*args, exclude_none=True, **kwargs)
Source code in autogen/llm_config/entry.py
| def model_dump_json(self, *args: Any, exclude_none: bool = True, **kwargs: Any) -> str:
return BaseModel.model_dump_json(self, exclude_none=exclude_none, *args, **kwargs)
|
get
Source code in autogen/llm_config/entry.py
| def get(self, key: str, default: Any | None = None) -> Any:
val = getattr(self, key, default)
if isinstance(val, SecretStr):
return val.get_secret_value()
return val
|
items
Source code in autogen/llm_config/entry.py
| def items(self) -> Iterable[tuple[str, Any]]:
d = self.model_dump()
return d.items()
|
keys
Source code in autogen/llm_config/entry.py
| def keys(self) -> Iterable[str]:
d = self.model_dump()
return d.keys()
|
values
Source code in autogen/llm_config/entry.py
| def values(self) -> Iterable[Any]:
d = self.model_dump()
return d.values()
|
serialize_aws_secrets
Source code in autogen/oai/bedrock.py
| @field_serializer("aws_access_key", "aws_secret_key", "aws_session_token", when_used="unless-none")
def serialize_aws_secrets(self, v: SecretStr) -> str:
return v.get_secret_value()
|