Skip to content

start_recommendation

start_recommendation(
    name: RecommendationName,
    type: RecommendationType,
    recommendation_config: RecommendationConfig,
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    description: Optional[RecommendationDescription] = None,
    kms_key_arn: Optional[KmsKeyArn] = None,
    client_token: Optional[ClientToken] = None,
    tags: Optional[TagsMap] = None,
) -> StartRecommendationResponse

Starts a recommendation job that analyzes agent traces and generates optimization suggestions for system prompts or tool descriptions to improve agent performance.

Parameters:

  • name (RecommendationName) –

    The name of the recommendation. Must be unique within your account.

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

    The description of the recommendation.

  • type (RecommendationType) –

    The type of recommendation to generate. Valid values are SYSTEM_PROMPT_RECOMMENDATION for system prompt optimization or TOOL_DESCRIPTION_RECOMMENDATION for tool description optimization.

  • recommendation_config (RecommendationConfig) –

    The configuration for the recommendation, including the input to optimize, agent traces to analyze, and evaluation settings.

  • kms_key_arn (Optional[KmsKeyArn], default: None ) –

    The ARN of the KMS key used to encrypt recommendation data. If provided, customer data is encrypted at rest with the specified key.

  • 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 recommendation.

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.

  • 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 start_recommendation(
    self,
    name: "capo_bedrock_agentcore.types.recommendation_name.RecommendationName",
    type: "capo_bedrock_agentcore.types.recommendation_type.RecommendationType",
    recommendation_config: "capo_bedrock_agentcore.types.recommendation_config.RecommendationConfig",
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    description: Optional[
        "capo_bedrock_agentcore.types.recommendation_description.RecommendationDescription"
    ] = None,
    kms_key_arn: Optional[
        "capo_bedrock_agentcore.types.kms_key_arn.KmsKeyArn"
    ] = 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.start_recommendation_response.StartRecommendationResponse":
    """<p>Starts a recommendation job that analyzes agent traces and generates optimization suggestions for system prompts or tool descriptions to improve agent performance.</p>

    Args:
        name: <p>The name of the recommendation. Must be unique within your account.</p>
        description: <p>The description of the recommendation.</p>
        type: <p>The type of recommendation to generate. Valid values are <code>SYSTEM_PROMPT_RECOMMENDATION</code> for system prompt optimization or <code>TOOL_DESCRIPTION_RECOMMENDATION</code> for tool description optimization.</p>
        recommendation_config: <p>The configuration for the recommendation, including the input to optimize, agent traces to analyze, and evaluation settings.</p>
        kms_key_arn: <p>The ARN of the KMS key used to encrypt recommendation data. If provided, customer data is encrypted at rest with the specified key.</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 recommendation.</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.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.start_recommendation_request.StartRecommendationRequest]",
    ) -> OperationResponse[
        "capo_bedrock_agentcore.types.start_recommendation_response.StartRecommendationResponse"
    ]:
        import capo_bedrock_agentcore._operations.amazon_bedrock_agent_core.start_recommendation

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

    def _redact_input(
        input_: "capo_bedrock_agentcore.types.start_recommendation_request.StartRecommendationRequest",
    ) -> dict[str, Any]:
        import capo_bedrock_agentcore.types.start_recommendation_request

        return capo_bedrock_agentcore.types.start_recommendation_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_bedrock_agentcore.types.start_recommendation_response.StartRecommendationResponse",
    ) -> dict[str, Any]:
        import capo_bedrock_agentcore.types.start_recommendation_response

        return capo_bedrock_agentcore.types.start_recommendation_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "StartRecommendation",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_bedrock_agentcore.types.start_recommendation_request.StartRecommendationRequest = {
        "name": name,
        "type": type,
        "recommendation_config": recommendation_config,
    }
    if description is not None:
        input_["description"] = description
    if kms_key_arn is not None:
        input_["kms_key_arn"] = kms_key_arn
    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