Skip to content

create_ab_test

create_ab_test(
    name: ABTestName,
    gateway_arn: GatewayArn,
    variants: VariantList,
    evaluation_config: ABTestEvaluationConfig,
    role_arn: RoleArn,
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    description: Optional[ABTestDescription] = None,
    gateway_filter: Optional[GatewayFilter] = None,
    enable_on_create: Optional[bool] = None,
    client_token: Optional[ClientToken] = None,
    tags: Optional[TagsMap] = None,
) -> CreateABTestResponse

Creates an A/B test for comparing agent configurations. A/B tests split traffic between a control variant and a treatment variant through a gateway, then evaluate performance using online evaluation configurations to determine which variant performs better.

Parameters:

  • name (ABTestName) –

    The name of the A/B test. Must be unique within your account.

  • description (Optional[ABTestDescription], default: None ) –

    The description of the A/B test.

  • gateway_arn (GatewayArn) –

    The Amazon Resource Name (ARN) of the gateway to use for traffic splitting.

  • variants (VariantList) –

    The list of variants for the A/B test. Must contain exactly two variants: a control (C) and a treatment (T1), each with a configuration bundle or target reference and a traffic weight.

  • gateway_filter (Optional[GatewayFilter], default: None ) –

    Optional filter to restrict which gateway target paths are included in the A/B test.

  • evaluation_config (ABTestEvaluationConfig) –

    The evaluation configuration specifying which online evaluation configurations to use for measuring variant performance.

  • role_arn (RoleArn) –

    The IAM role ARN that grants permissions for the A/B test to access gateway and evaluation resources.

  • enable_on_create (Optional[bool], default: None ) –

    Whether to enable the A/B test immediately upon creation. If true, traffic splitting begins automatically.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, the service ignores the request, but does not return an error.

  • tags (Optional[TagsMap], default: None ) –

    A map of tag keys and values to associate with the A/B test.

Raises:

  • AccessDeniedException –

    The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.

  • ConflictException –

    The exception that occurs when the request conflicts with the current state of the resource. This can happen when trying to modify a resource that is currently being modified by another request, or when trying to create a resource that already exists.

  • InternalServerException –

    The exception that occurs when the service encounters an unexpected internal error. This is a temporary condition that will resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.

  • ServiceQuotaExceededException –

    The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.

  • ThrottlingException –

    The exception that occurs when the request was denied due to request throttling. This happens when you exceed the allowed request rate for an operation. Reduce the frequency of requests or implement exponential backoff retry logic in your application.

  • UnauthorizedException –

    This exception is thrown when the JWT bearer token is invalid or not found for OAuth bearer token based access

  • ValidationException –

    The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_bedrock_agentcore/_services/bedrock_agent_core.py
def create_ab_test(
    self,
    name: "capo_bedrock_agentcore.types.ab_test_name.ABTestName",
    gateway_arn: "capo_bedrock_agentcore.types.gateway_arn.GatewayArn",
    variants: "capo_bedrock_agentcore.types.variant_list.VariantList",
    evaluation_config: "capo_bedrock_agentcore.types.ab_test_evaluation_config.ABTestEvaluationConfig",
    role_arn: "capo_bedrock_agentcore.types.role_arn.RoleArn",
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    description: Optional[
        "capo_bedrock_agentcore.types.ab_test_description.ABTestDescription"
    ] = None,
    gateway_filter: Optional[
        "capo_bedrock_agentcore.types.gateway_filter.GatewayFilter"
    ] = None,
    enable_on_create: Optional[bool] = None,
    client_token: Optional[
        "capo_bedrock_agentcore.types.client_token.ClientToken"
    ] = None,
    tags: Optional["capo_bedrock_agentcore.types.tags_map.TagsMap"] = None,
) -> "capo_bedrock_agentcore.types.create_ab_test_response.CreateABTestResponse":
    """<p>Creates an A/B test for comparing agent configurations. A/B tests split traffic between a control variant and a treatment variant through a gateway, then evaluate performance using online evaluation configurations to determine which variant performs better.</p>

    Args:
        name: <p>The name of the A/B test. Must be unique within your account.</p>
        description: <p>The description of the A/B test.</p>
        gateway_arn: <p>The Amazon Resource Name (ARN) of the gateway to use for traffic splitting.</p>
        variants: <p>The list of variants for the A/B test. Must contain exactly two variants: a control (C) and a treatment (T1), each with a configuration bundle or target reference and a traffic weight.</p>
        gateway_filter: <p>Optional filter to restrict which gateway target paths are included in the A/B test.</p>
        evaluation_config: <p>The evaluation configuration specifying which online evaluation configurations to use for measuring variant performance.</p>
        role_arn: <p>The IAM role ARN that grants permissions for the A/B test to access gateway and evaluation resources.</p>
        enable_on_create: <p>Whether to enable the A/B test immediately upon creation. If true, traffic splitting begins automatically.</p>
        client_token: <p>A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, the service ignores the request, but does not return an error.</p>
        tags: <p>A map of tag keys and values to associate with the A/B test.</p>

    Raises:
        capo_bedrock_agentcore.errors.access_denied_exception.AccessDeniedException: <p>The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.</p>
        capo_bedrock_agentcore.errors.conflict_exception.ConflictException: <p>The exception that occurs when the request conflicts with the current state of the resource. This can happen when trying to modify a resource that is currently being modified by another request, or when trying to create a resource that already exists.</p>
        capo_bedrock_agentcore.errors.internal_server_exception.InternalServerException: <p>The exception that occurs when the service encounters an unexpected internal error. This is a temporary condition that will resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.</p>
        capo_bedrock_agentcore.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.</p>
        capo_bedrock_agentcore.errors.throttling_exception.ThrottlingException: <p>The exception that occurs when the request was denied due to request throttling. This happens when you exceed the allowed request rate for an operation. Reduce the frequency of requests or implement exponential backoff retry logic in your application.</p>
        capo_bedrock_agentcore.errors.unauthorized_exception.UnauthorizedException: <p>This exception is thrown when the JWT bearer token is invalid or not found for OAuth bearer token based access</p>
        capo_bedrock_agentcore.errors.validation_exception.ValidationException: <p>The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.</p>
        capo_bedrock_agentcore.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_bedrock_agentcore.types.create_ab_test_request.CreateABTestRequest]",
    ) -> OperationResponse[
        "capo_bedrock_agentcore.types.create_ab_test_response.CreateABTestResponse"
    ]:
        import capo_bedrock_agentcore._operations.amazon_bedrock_agent_core.create_ab_test

        output, http_response = (
            capo_bedrock_agentcore._operations.amazon_bedrock_agent_core.create_ab_test.create_ab_test(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateABTest")
    )
    input_: capo_bedrock_agentcore.types.create_ab_test_request.CreateABTestRequest = {
        "name": name,
        "gateway_arn": gateway_arn,
        "variants": variants,
        "evaluation_config": evaluation_config,
        "role_arn": role_arn,
    }
    if description is not None:
        input_["description"] = description
    if gateway_filter is not None:
        input_["gateway_filter"] = gateway_filter
    if enable_on_create is not None:
        input_["enable_on_create"] = enable_on_create
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output