Skip to content

create_experiment

create_experiment(
    target: ExperimentTarget,
    experiment_type: ExperimentType,
    experiment_config: ExperimentConfig,
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    client_token: Optional[ClientToken] = None,
    name: Optional[ExperimentName] = None,
    description: Optional[Description] = None,
    tags: Optional[TagMap] = None,
) -> CreateExperimentOutput

Creates an experiment. An experiment defines the target its runs are tested against and the configuration for its type; each run specifies the dataset it tests and the evaluators it is scored with. The name, description, and configuration can be changed later, but the target and type cannot. Use GetExperiment to retrieve the experiment, ListExperiments to enumerate experiments, UpdateExperiment to modify it, and DeleteExperiment to remove it.

Parameters:

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

    Idempotency token for safe retries. Repeated requests with the same token return the original result instead of creating a second experiment.

  • name (Optional[ExperimentName], default: None ) –

    The name of the experiment.

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

    An optional description of the experiment. Up to 1,024 characters, with no control characters.

  • target (ExperimentTarget) –

    The target that the experiment tests, including its service name, environment, and definition. Cannot be changed after the experiment is created.

  • experiment_type (ExperimentType) –

    The type of the experiment. Cannot be changed after the experiment is created.

  • experiment_config (ExperimentConfig) –

    The configuration for the experiment's type. Its member must match experimentType: a DATASET experiment takes experimentConfig.dataset. The caller must have iam:PassRole on the execution role, the role must be assumable, and the results log group must exist and use the Standard log class.

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

    The tags to associate with the experiment. Tag keys that begin with the reserved aws: prefix are rejected with a ValidationException.

Raises:

Examples:

Create a DATASET experiment for an AgentCore Runtime agent The following example creates a DATASET experiment that tests an AgentCore Runtime agent. Its runs write their records to the results log group using the execution role. Payloads are shown as JSON; on the wire they are CBOR-encoded.

>>> client.create_experiment(client_token='3f1b2c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d', name='Travel agent regression suite', description='Checks booking accuracy before each release.', target={'name': 'Travel agent', 'serviceName': 'travel-agent', 'environment': 'staging', 'definition': {'agentCoreRuntime': {'runtimeArn': 'arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/travel_agent-a1B2c3D4e5'}}}, experiment_type='DATASET', experiment_config={'dataset': {'executionRoleArn': 'arn:aws:iam::123456789012:role/ExperimentExecutionRole', 'resultsLogGroup': '/experiments/travel-agent/results'}}, tags={'team': 'travel'})
Source code in docs_src/capo_cloudwatchomni/_services/cloud_watch_omni.py
def create_experiment(
    self,
    target: "capo_cloudwatchomni.types.experiment_target.ExperimentTarget",
    experiment_type: "capo_cloudwatchomni.types.experiment_type.ExperimentType",
    experiment_config: "capo_cloudwatchomni.types.experiment_config.ExperimentConfig",
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    client_token: Optional[
        "capo_cloudwatchomni.types.client_token.ClientToken"
    ] = None,
    name: Optional[
        "capo_cloudwatchomni.types.experiment_name.ExperimentName"
    ] = None,
    description: Optional[
        "capo_cloudwatchomni.types.description.Description"
    ] = None,
    tags: Optional["capo_cloudwatchomni.types.tag_map.TagMap"] = None,
) -> "capo_cloudwatchomni.types.create_experiment_output.CreateExperimentOutput":
    """Creates an experiment. An experiment defines the target its runs are tested against and the configuration for its type; each run specifies the dataset it tests and the evaluators it is scored with. The name, description, and configuration can be changed later, but the target and type cannot. Use GetExperiment to retrieve the experiment, ListExperiments to enumerate experiments, UpdateExperiment to modify it, and DeleteExperiment to remove it.

    Args:
        client_token: Idempotency token for safe retries. Repeated requests with the same token return the original result instead of creating a second experiment.
        name: The name of the experiment.
        description: An optional description of the experiment. Up to 1,024 characters, with no control characters.
        target: The target that the experiment tests, including its service name, environment, and definition. Cannot be changed after the experiment is created.
        experiment_type: The type of the experiment. Cannot be changed after the experiment is created.
        experiment_config: The configuration for the experiment's type. Its member must match experimentType: a DATASET experiment takes experimentConfig.dataset. The caller must have iam:PassRole on the execution role, the role must be assumable, and the results log group must exist and use the Standard log class.
        tags: The tags to associate with the experiment. Tag keys that begin with the reserved `aws:` prefix are rejected with a ValidationException.

    Raises:
        capo_cloudwatchomni.errors.access_denied_exception.AccessDeniedException: The caller is not authorized to perform this action.
        capo_cloudwatchomni.errors.conflict_exception.ConflictException: The operation could not be completed because of a conflict with the current state of the resource.
        capo_cloudwatchomni.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_cloudwatchomni.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: A service quota was exceeded.
        capo_cloudwatchomni.errors.throttling_exception.ThrottlingException: The request was throttled due to exceeding the allowed request rate.
        capo_cloudwatchomni.errors.validation_exception.ValidationException: A parameter is specified incorrectly.
        capo_cloudwatchomni.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Create a DATASET experiment for an AgentCore Runtime agent
        The following example creates a DATASET experiment that tests an AgentCore Runtime agent. Its runs write their records to the results log group using the execution role. Payloads are shown as JSON; on the wire they are CBOR-encoded.

        >>> client.create_experiment(client_token='3f1b2c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d', name='Travel agent regression suite', description='Checks booking accuracy before each release.', target={'name': 'Travel agent', 'serviceName': 'travel-agent', 'environment': 'staging', 'definition': {'agentCoreRuntime': {'runtimeArn': 'arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/travel_agent-a1B2c3D4e5'}}}, experiment_type='DATASET', experiment_config={'dataset': {'executionRoleArn': 'arn:aws:iam::123456789012:role/ExperimentExecutionRole', 'resultsLogGroup': '/experiments/travel-agent/results'}}, tags={'team': 'travel'})
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatchomni.types.create_experiment_input.CreateExperimentInput]",
    ) -> OperationResponse[
        "capo_cloudwatchomni.types.create_experiment_output.CreateExperimentOutput"
    ]:
        import capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_experiment

        output, http_response = (
            capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_experiment.create_experiment(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cloudwatchomni.types.create_experiment_input.CreateExperimentInput",
    ) -> dict[str, Any]:
        import capo_cloudwatchomni.types.create_experiment_input

        return capo_cloudwatchomni.types.create_experiment_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_cloudwatchomni.types.create_experiment_output.CreateExperimentOutput",
    ) -> dict[str, Any]:
        import capo_cloudwatchomni.types.create_experiment_output

        return capo_cloudwatchomni.types.create_experiment_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateExperiment",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_cloudwatchomni.types.create_experiment_input.CreateExperimentInput = {
        "target": target,
        "experiment_type": experiment_type,
        "experiment_config": experiment_config,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if name is not None:
        input_["name"] = name
    if description is not None:
        input_["description"] = description
    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