strands.models.sagemaker
Amazon SageMaker model provider.
UsageMetadata
Section titled “UsageMetadata”@dataclassclass UsageMetadata()Defined in: src/strands/models/sagemaker.py:28
Usage metadata for the model.
Attributes:
total_tokens- Total number of tokens used in the requestcompletion_tokens- Number of tokens used in the completionprompt_tokens- Number of tokens used in the promptprompt_tokens_details- Additional information about the prompt tokens (optional)
FunctionCall
Section titled “FunctionCall”@dataclassclass FunctionCall()Defined in: src/strands/models/sagemaker.py:45
Function call for the model.
Attributes:
name- Name of the function to callarguments- Arguments to pass to the function
__init__
Section titled “__init__”def __init__(**kwargs: dict[str, str])Defined in: src/strands/models/sagemaker.py:56
Initialize function call.
Arguments:
**kwargs- Keyword arguments for the function call.
ToolCall
Section titled “ToolCall”@dataclassclass ToolCall()Defined in: src/strands/models/sagemaker.py:67
Tool call for the model object.
Attributes:
id- Tool call IDtype- Tool call typefunction- Tool call function
__init__
Section titled “__init__”def __init__(**kwargs: dict)Defined in: src/strands/models/sagemaker.py:80
Initialize tool call object.
Arguments:
**kwargs- Keyword arguments for the tool call.
SageMakerAIModel
Section titled “SageMakerAIModel”class SageMakerAIModel(OpenAIModel)Defined in: src/strands/models/sagemaker.py:91
Amazon SageMaker model provider implementation.
client
Section titled “client”type: ignore[assignment]
SageMakerAIPayloadSchema
Section titled “SageMakerAIPayloadSchema”class SageMakerAIPayloadSchema(TypedDict)Defined in: src/strands/models/sagemaker.py:96
Payload schema for the Amazon SageMaker AI model.
Attributes:
max_tokens- Maximum number of tokens to generate in the completionstream- Whether to stream the responsetemperature- Sampling temperature to use for the model (optional)top_p- Nucleus sampling parameter (optional)top_k- Top-k sampling parameter (optional)stop- List of stop sequences to use for the model (optional)tool_results_as_user_messages- Convert tool result to user messages (optional)additional_args- Additional request parameters, as supported by https://bit.ly/djl-lmi-request-schema
SageMakerAIEndpointConfig
Section titled “SageMakerAIEndpointConfig”class SageMakerAIEndpointConfig(TypedDict)Defined in: src/strands/models/sagemaker.py:119
Configuration options for SageMaker models.
Attributes:
-
endpoint_name- The name of the SageMaker endpoint to invoke -
inference_component_name- The name of the inference component to use -
additional_args- Other request parameters, as supported by https://bit.ly/sagemaker-invoke-endpoint-params
__init__
Section titled “__init__”def __init__(endpoint_config: SageMakerAIEndpointConfig, payload_config: SageMakerAIPayloadSchema, boto_session: boto3.Session | None = None, boto_client_config: BotocoreConfig | None = None)Defined in: src/strands/models/sagemaker.py:136
Initialize provider instance.
Arguments:
endpoint_config- Endpoint configuration for SageMaker.payload_config- Payload configuration for the model.boto_session- Boto Session to use when calling the SageMaker Runtime.boto_client_config- Configuration to use when creating the SageMaker-Runtime Boto Client.
update_config
Section titled “update_config”@overridedef update_config(**endpoint_config: Unpack[SageMakerAIEndpointConfig] ) -> NoneDefined in: src/strands/models/sagemaker.py:181
Update the Amazon SageMaker model configuration with the provided arguments.
Arguments:
**endpoint_config- Configuration overrides.
get_config
Section titled “get_config”@overridedef get_config() -> "SageMakerAIModel.SageMakerAIEndpointConfig"Defined in: src/strands/models/sagemaker.py:191
Get the Amazon SageMaker model configuration.
Returns:
The Amazon SageMaker model configuration.
format_request
Section titled “format_request”@overridedef format_request(messages: Messages, tool_specs: list[ToolSpec] | None = None, system_prompt: str | None = None, tool_choice: ToolChoice | None = None, **kwargs: Any) -> dict[str, Any]Defined in: src/strands/models/sagemaker.py:200
Format an Amazon SageMaker chat streaming request.
Arguments:
messages- List of message objects to be processed by the model.tool_specs- List of tool specifications to make available to the model.system_prompt- System prompt to provide context to the model.tool_choice- Selection strategy for tool invocation. Note: This parameter is accepted for interface consistency but is currently ignored for this model provider.**kwargs- Additional keyword arguments for future extensibility.
Returns:
An Amazon SageMaker chat streaming request.
stream
Section titled “stream”@overrideasync def stream(messages: Messages, tool_specs: list[ToolSpec] | None = None, system_prompt: str | None = None, *, tool_choice: ToolChoice | None = None, **kwargs: Any) -> AsyncGenerator[StreamEvent, None]Defined in: src/strands/models/sagemaker.py:301
Stream conversation with the SageMaker model.
Arguments:
messages- List of message objects to be processed by the model.tool_specs- List of tool specifications to make available to the model.system_prompt- System prompt to provide context to the model.tool_choice- Selection strategy for tool invocation. Note: This parameter is accepted for interface consistency but is currently ignored for this model provider.**kwargs- Additional keyword arguments for future extensibility.
Yields:
Formatted message chunks from the model.
format_request_tool_message
Section titled “format_request_tool_message”@override@classmethoddef format_request_tool_message(cls, tool_result: ToolResult, **kwargs: Any) -> dict[str, Any]Defined in: src/strands/models/sagemaker.py:507
Format a SageMaker compatible tool message.
Arguments:
tool_result- Tool result collected from a tool execution.**kwargs- Additional keyword arguments for future extensibility.
Returns:
SageMaker compatible tool message with content as a string.
format_request_message_content
Section titled “format_request_message_content”@override@classmethoddef format_request_message_content(cls, content: ContentBlock, **kwargs: Any) -> dict[str, Any]Defined in: src/strands/models/sagemaker.py:538
Format a content block.
Arguments:
content- Message content.**kwargs- Additional keyword arguments for future extensibility.
Returns:
Formatted content block.
Raises:
TypeError- If the content block type cannot be converted to a SageMaker-compatible format.
structured_output
Section titled “structured_output”@overrideasync def structured_output( output_model: type[T], prompt: Messages, system_prompt: str | None = None, **kwargs: Any) -> AsyncGenerator[dict[str, T | Any], None]Defined in: src/strands/models/sagemaker.py:575
Get structured output from the model.
Arguments:
output_model- The output model to use for the agent.prompt- The prompt messages to use for the agent.system_prompt- System prompt to provide context to the model.**kwargs- Additional keyword arguments for future extensibility.
Yields:
Model events with the last being the structured output.