%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE! %% See https://github.com/aws-beam/aws-codegen for more details. %% @doc Contains APIs related to model invocation and querying of knowledge %% bases. -module(aws_bedrock_agent_runtime). -export([delete_agent_memory/4, delete_agent_memory/5, get_agent_memory/5, get_agent_memory/7, get_agent_memory/8, invoke_agent/5, invoke_agent/6, invoke_flow/4, invoke_flow/5, retrieve/3, retrieve/4, retrieve_and_generate/2, retrieve_and_generate/3]). -include_lib("hackney/include/hackney_lib.hrl"). %% Example: %% function_invocation_input() :: #{ %% <<"actionGroup">> => [string()], %% <<"actionInvocationType">> => list(any()), %% <<"function">> => [string()], %% <<"parameters">> => list(function_parameter()()) %% } -type function_invocation_input() :: #{binary() => any()}. %% Example: %% file_part() :: #{ %% <<"files">> => list(output_file()()) %% } -type file_part() :: #{binary() => any()}. %% Example: %% knowledge_base_configuration() :: #{ %% <<"knowledgeBaseId">> => string(), %% <<"retrievalConfiguration">> => knowledge_base_retrieval_configuration() %% } -type knowledge_base_configuration() :: #{binary() => any()}. %% Example: %% rationale() :: #{ %% <<"text">> => string(), %% <<"traceId">> => string() %% } -type rationale() :: #{binary() => any()}. %% Example: %% api_request_body() :: #{ %% <<"content">> => map() %% } -type api_request_body() :: #{binary() => any()}. %% Example: %% guardrail_content_policy_assessment() :: #{ %% <<"filters">> => list(guardrail_content_filter()()) %% } -type guardrail_content_policy_assessment() :: #{binary() => any()}. %% Example: %% text_inference_config() :: #{ %% <<"maxTokens">> => integer(), %% <<"stopSequences">> => list([string()]()), %% <<"temperature">> => float(), %% <<"topP">> => float() %% } -type text_inference_config() :: #{binary() => any()}. %% Example: %% code_interpreter_invocation_output() :: #{ %% <<"executionError">> => [string()], %% <<"executionOutput">> => [string()], %% <<"executionTimeout">> => [boolean()], %% <<"files">> => list([string()]()) %% } -type code_interpreter_invocation_output() :: #{binary() => any()}. %% Example: %% external_source() :: #{ %% <<"byteContent">> => byte_content_doc(), %% <<"s3Location">> => s3_object_doc(), %% <<"sourceType">> => list(any()) %% } -type external_source() :: #{binary() => any()}. %% Example: %% inference_configuration() :: #{ %% <<"maximumLength">> => integer(), %% <<"stopSequences">> => list([string()]()), %% <<"temperature">> => float(), %% <<"topK">> => integer(), %% <<"topP">> => float() %% } -type inference_configuration() :: #{binary() => any()}. %% Example: %% bad_gateway_exception() :: #{ %% <<"message">> => string(), %% <<"resourceName">> => string() %% } -type bad_gateway_exception() :: #{binary() => any()}. %% Example: %% input_file() :: #{ %% <<"name">> => [string()], %% <<"source">> => file_source(), %% <<"useCase">> => list(any()) %% } -type input_file() :: #{binary() => any()}. %% Example: %% s3_object_doc() :: #{ %% <<"uri">> => string() %% } -type s3_object_doc() :: #{binary() => any()}. %% Example: %% function_parameter() :: #{ %% <<"name">> => [string()], %% <<"type">> => [string()], %% <<"value">> => [string()] %% } -type function_parameter() :: #{binary() => any()}. %% Example: %% dependency_failed_exception() :: #{ %% <<"message">> => string(), %% <<"resourceName">> => string() %% } -type dependency_failed_exception() :: #{binary() => any()}. %% Example: %% citation() :: #{ %% <<"generatedResponsePart">> => generated_response_part(), %% <<"retrievedReferences">> => list(retrieved_reference()()) %% } -type citation() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_response() :: #{ %% <<"citations">> => list(citation()()), %% <<"guardrailAction">> => list(any()), %% <<"output">> => retrieve_and_generate_output(), %% <<"sessionId">> => string() %% } -type retrieve_and_generate_response() :: #{binary() => any()}. %% Example: %% delete_agent_memory_response() :: #{} -type delete_agent_memory_response() :: #{}. %% Example: %% metadata() :: #{ %% <<"usage">> => usage() %% } -type metadata() :: #{binary() => any()}. %% Example: %% knowledge_base_query() :: #{ %% <<"text">> => [string()] %% } -type knowledge_base_query() :: #{binary() => any()}. %% Example: %% payload_part() :: #{ %% <<"attribution">> => attribution(), %% <<"bytes">> => binary() %% } -type payload_part() :: #{binary() => any()}. %% Example: %% failure_trace() :: #{ %% <<"failureReason">> => string(), %% <<"traceId">> => string() %% } -type failure_trace() :: #{binary() => any()}. %% Example: %% guardrail_managed_word() :: #{ %% <<"action">> => list(any()), %% <<"match">> => [string()], %% <<"type">> => list(any()) %% } -type guardrail_managed_word() :: #{binary() => any()}. %% Example: %% action_group_invocation_input() :: #{ %% <<"actionGroupName">> => string(), %% <<"apiPath">> => string(), %% <<"executionType">> => list(any()), %% <<"function">> => string(), %% <<"invocationId">> => [string()], %% <<"parameters">> => list(parameter()()), %% <<"requestBody">> => request_body(), %% <<"verb">> => string() %% } -type action_group_invocation_input() :: #{binary() => any()}. %% Example: %% retrieved_reference() :: #{ %% <<"content">> => retrieval_result_content(), %% <<"location">> => retrieval_result_location(), %% <<"metadata">> => map() %% } -type retrieved_reference() :: #{binary() => any()}. %% Example: %% retrieval_result_location() :: #{ %% <<"confluenceLocation">> => retrieval_result_confluence_location(), %% <<"s3Location">> => retrieval_result_s3_location(), %% <<"salesforceLocation">> => retrieval_result_salesforce_location(), %% <<"sharePointLocation">> => retrieval_result_share_point_location(), %% <<"type">> => list(any()), %% <<"webLocation">> => retrieval_result_web_location() %% } -type retrieval_result_location() :: #{binary() => any()}. %% Example: %% api_parameter() :: #{ %% <<"name">> => [string()], %% <<"type">> => [string()], %% <<"value">> => [string()] %% } -type api_parameter() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_session_configuration() :: #{ %% <<"kmsKeyArn">> => string() %% } -type retrieve_and_generate_session_configuration() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_request() :: #{ %% <<"input">> := retrieve_and_generate_input(), %% <<"retrieveAndGenerateConfiguration">> => retrieve_and_generate_configuration(), %% <<"sessionConfiguration">> => retrieve_and_generate_session_configuration(), %% <<"sessionId">> => string() %% } -type retrieve_and_generate_request() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_configuration() :: #{ %% <<"externalSourcesConfiguration">> => external_sources_retrieve_and_generate_configuration(), %% <<"knowledgeBaseConfiguration">> => knowledge_base_retrieve_and_generate_configuration(), %% <<"type">> => list(any()) %% } -type retrieve_and_generate_configuration() :: #{binary() => any()}. %% Example: %% retrieval_result_s3_location() :: #{ %% <<"uri">> => [string()] %% } -type retrieval_result_s3_location() :: #{binary() => any()}. %% Example: %% invoke_flow_response() :: #{ %% <<"responseStream">> => list() %% } -type invoke_flow_response() :: #{binary() => any()}. %% Example: %% usage() :: #{ %% <<"inputTokens">> => [integer()], %% <<"outputTokens">> => [integer()] %% } -type usage() :: #{binary() => any()}. %% Example: %% retrieval_result_content() :: #{ %% <<"text">> => [string()] %% } -type retrieval_result_content() :: #{binary() => any()}. %% Example: %% guardrail_custom_word() :: #{ %% <<"action">> => list(any()), %% <<"match">> => [string()] %% } -type guardrail_custom_word() :: #{binary() => any()}. %% Example: %% content_body() :: #{ %% <<"body">> => [string()] %% } -type content_body() :: #{binary() => any()}. %% Example: %% knowledge_base_retrieve_and_generate_configuration() :: #{ %% <<"generationConfiguration">> => generation_configuration(), %% <<"knowledgeBaseId">> => string(), %% <<"modelArn">> => string(), %% <<"orchestrationConfiguration">> => orchestration_configuration(), %% <<"retrievalConfiguration">> => knowledge_base_retrieval_configuration() %% } -type knowledge_base_retrieve_and_generate_configuration() :: #{binary() => any()}. %% Example: %% observation() :: #{ %% <<"actionGroupInvocationOutput">> => action_group_invocation_output(), %% <<"codeInterpreterInvocationOutput">> => code_interpreter_invocation_output(), %% <<"finalResponse">> => final_response(), %% <<"knowledgeBaseLookupOutput">> => knowledge_base_lookup_output(), %% <<"repromptResponse">> => reprompt_response(), %% <<"traceId">> => string(), %% <<"type">> => list(any()) %% } -type observation() :: #{binary() => any()}. %% Example: %% guardrail_word_policy_assessment() :: #{ %% <<"customWords">> => list(guardrail_custom_word()()), %% <<"managedWordLists">> => list(guardrail_managed_word()()) %% } -type guardrail_word_policy_assessment() :: #{binary() => any()}. %% Example: %% span() :: #{ %% <<"end">> => [integer()], %% <<"start">> => [integer()] %% } -type span() :: #{binary() => any()}. %% Example: %% pre_processing_parsed_response() :: #{ %% <<"isValid">> => [boolean()], %% <<"rationale">> => string() %% } -type pre_processing_parsed_response() :: #{binary() => any()}. %% Example: %% function_result() :: #{ %% <<"actionGroup">> => [string()], %% <<"confirmationState">> => list(any()), %% <<"function">> => [string()], %% <<"responseBody">> => map(), %% <<"responseState">> => list(any()) %% } -type function_result() :: #{binary() => any()}. %% Example: %% conflict_exception() :: #{ %% <<"message">> => string() %% } -type conflict_exception() :: #{binary() => any()}. %% Example: %% resource_not_found_exception() :: #{ %% <<"message">> => string() %% } -type resource_not_found_exception() :: #{binary() => any()}. %% Example: %% query_transformation_configuration() :: #{ %% <<"type">> => list(any()) %% } -type query_transformation_configuration() :: #{binary() => any()}. %% Example: %% post_processing_parsed_response() :: #{ %% <<"text">> => string() %% } -type post_processing_parsed_response() :: #{binary() => any()}. %% Example: %% guardrail_sensitive_information_policy_assessment() :: #{ %% <<"piiEntities">> => list(guardrail_pii_entity_filter()()), %% <<"regexes">> => list(guardrail_regex_filter()()) %% } -type guardrail_sensitive_information_policy_assessment() :: #{binary() => any()}. %% Example: %% knowledge_base_retrieval_configuration() :: #{ %% <<"vectorSearchConfiguration">> => knowledge_base_vector_search_configuration() %% } -type knowledge_base_retrieval_configuration() :: #{binary() => any()}. %% Example: %% guardrail_content_filter() :: #{ %% <<"action">> => list(any()), %% <<"confidence">> => list(any()), %% <<"type">> => list(any()) %% } -type guardrail_content_filter() :: #{binary() => any()}. %% Example: %% flow_completion_event() :: #{ %% <<"completionReason">> => list(any()) %% } -type flow_completion_event() :: #{binary() => any()}. %% Example: %% service_quota_exceeded_exception() :: #{ %% <<"message">> => string() %% } -type service_quota_exceeded_exception() :: #{binary() => any()}. %% Example: %% return_control_payload() :: #{ %% <<"invocationId">> => [string()], %% <<"invocationInputs">> => list(list()()) %% } -type return_control_payload() :: #{binary() => any()}. %% Example: %% text_response_part() :: #{ %% <<"span">> => span(), %% <<"text">> => [string()] %% } -type text_response_part() :: #{binary() => any()}. %% Example: %% invoke_agent_response() :: #{ %% <<"completion">> => list(), %% <<"contentType">> => string(), %% <<"memoryId">> => string(), %% <<"sessionId">> => string() %% } -type invoke_agent_response() :: #{binary() => any()}. %% Example: %% session_state() :: #{ %% <<"files">> => list(input_file()()), %% <<"invocationId">> => [string()], %% <<"knowledgeBaseConfigurations">> => list(knowledge_base_configuration()()), %% <<"promptSessionAttributes">> => map(), %% <<"returnControlInvocationResults">> => list(list()()), %% <<"sessionAttributes">> => map() %% } -type session_state() :: #{binary() => any()}. %% Example: %% pre_processing_model_invocation_output() :: #{ %% <<"parsedResponse">> => pre_processing_parsed_response(), %% <<"traceId">> => string() %% } -type pre_processing_model_invocation_output() :: #{binary() => any()}. %% Example: %% parameter() :: #{ %% <<"name">> => [string()], %% <<"type">> => [string()], %% <<"value">> => [string()] %% } -type parameter() :: #{binary() => any()}. %% Example: %% external_sources_retrieve_and_generate_configuration() :: #{ %% <<"generationConfiguration">> => external_sources_generation_configuration(), %% <<"modelArn">> => string(), %% <<"sources">> => list(external_source()()) %% } -type external_sources_retrieve_and_generate_configuration() :: #{binary() => any()}. %% Example: %% api_invocation_input() :: #{ %% <<"actionGroup">> => [string()], %% <<"actionInvocationType">> => list(any()), %% <<"apiPath">> => string(), %% <<"httpMethod">> => [string()], %% <<"parameters">> => list(api_parameter()()), %% <<"requestBody">> => api_request_body() %% } -type api_invocation_input() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_input() :: #{ %% <<"text">> => [string()] %% } -type retrieve_and_generate_input() :: #{binary() => any()}. %% Example: %% retrieval_result_confluence_location() :: #{ %% <<"url">> => [string()] %% } -type retrieval_result_confluence_location() :: #{binary() => any()}. %% Example: %% reprompt_response() :: #{ %% <<"source">> => list(any()), %% <<"text">> => [string()] %% } -type reprompt_response() :: #{binary() => any()}. %% Example: %% final_response() :: #{ %% <<"text">> => string() %% } -type final_response() :: #{binary() => any()}. %% Example: %% api_result() :: #{ %% <<"actionGroup">> => [string()], %% <<"apiPath">> => string(), %% <<"confirmationState">> => list(any()), %% <<"httpMethod">> => [string()], %% <<"httpStatusCode">> => [integer()], %% <<"responseBody">> => map(), %% <<"responseState">> => list(any()) %% } -type api_result() :: #{binary() => any()}. %% Example: %% byte_content_doc() :: #{ %% <<"contentType">> => string(), %% <<"data">> => binary(), %% <<"identifier">> => string() %% } -type byte_content_doc() :: #{binary() => any()}. %% Example: %% external_sources_generation_configuration() :: #{ %% <<"additionalModelRequestFields">> => map(), %% <<"guardrailConfiguration">> => guardrail_configuration(), %% <<"inferenceConfig">> => inference_config(), %% <<"promptTemplate">> => prompt_template() %% } -type external_sources_generation_configuration() :: #{binary() => any()}. %% Example: %% guardrail_trace() :: #{ %% <<"action">> => list(any()), %% <<"inputAssessments">> => list(guardrail_assessment()()), %% <<"outputAssessments">> => list(guardrail_assessment()()), %% <<"traceId">> => string() %% } -type guardrail_trace() :: #{binary() => any()}. %% Example: %% knowledge_base_vector_search_configuration() :: #{ %% <<"filter">> => list(), %% <<"numberOfResults">> => [integer()], %% <<"overrideSearchType">> => list(any()) %% } -type knowledge_base_vector_search_configuration() :: #{binary() => any()}. %% Example: %% filter_attribute() :: #{ %% <<"key">> => string(), %% <<"value">> => any() %% } -type filter_attribute() :: #{binary() => any()}. %% Example: %% retrieval_result_salesforce_location() :: #{ %% <<"url">> => [string()] %% } -type retrieval_result_salesforce_location() :: #{binary() => any()}. %% Example: %% output_file() :: #{ %% <<"bytes">> => binary(), %% <<"name">> => [string()], %% <<"type">> => string() %% } -type output_file() :: #{binary() => any()}. %% Example: %% internal_server_exception() :: #{ %% <<"message">> => string() %% } -type internal_server_exception() :: #{binary() => any()}. %% Example: %% guardrail_assessment() :: #{ %% <<"contentPolicy">> => guardrail_content_policy_assessment(), %% <<"sensitiveInformationPolicy">> => guardrail_sensitive_information_policy_assessment(), %% <<"topicPolicy">> => guardrail_topic_policy_assessment(), %% <<"wordPolicy">> => guardrail_word_policy_assessment() %% } -type guardrail_assessment() :: #{binary() => any()}. %% Example: %% model_invocation_input() :: #{ %% <<"inferenceConfiguration">> => inference_configuration(), %% <<"overrideLambda">> => string(), %% <<"parserMode">> => list(any()), %% <<"promptCreationMode">> => list(any()), %% <<"text">> => string(), %% <<"traceId">> => string(), %% <<"type">> => list(any()) %% } -type model_invocation_input() :: #{binary() => any()}. %% Example: %% attribution() :: #{ %% <<"citations">> => list(citation()()) %% } -type attribution() :: #{binary() => any()}. %% Example: %% trace_part() :: #{ %% <<"agentAliasId">> => string(), %% <<"agentId">> => string(), %% <<"agentVersion">> => string(), %% <<"sessionId">> => string(), %% <<"trace">> => list() %% } -type trace_part() :: #{binary() => any()}. %% Example: %% retrieval_result_share_point_location() :: #{ %% <<"url">> => [string()] %% } -type retrieval_result_share_point_location() :: #{binary() => any()}. %% Example: %% orchestration_configuration() :: #{ %% <<"queryTransformationConfiguration">> => query_transformation_configuration() %% } -type orchestration_configuration() :: #{binary() => any()}. %% Example: %% prompt_template() :: #{ %% <<"textPromptTemplate">> => string() %% } -type prompt_template() :: #{binary() => any()}. %% Example: %% access_denied_exception() :: #{ %% <<"message">> => string() %% } -type access_denied_exception() :: #{binary() => any()}. %% Example: %% inference_config() :: #{ %% <<"textInferenceConfig">> => text_inference_config() %% } -type inference_config() :: #{binary() => any()}. %% Example: %% guardrail_topic_policy_assessment() :: #{ %% <<"topics">> => list(guardrail_topic()()) %% } -type guardrail_topic_policy_assessment() :: #{binary() => any()}. %% Example: %% generation_configuration() :: #{ %% <<"additionalModelRequestFields">> => map(), %% <<"guardrailConfiguration">> => guardrail_configuration(), %% <<"inferenceConfig">> => inference_config(), %% <<"promptTemplate">> => prompt_template() %% } -type generation_configuration() :: #{binary() => any()}. %% Example: %% property_parameters() :: #{ %% <<"properties">> => list(parameter()()) %% } -type property_parameters() :: #{binary() => any()}. %% Example: %% flow_input() :: #{ %% <<"content">> => list(), %% <<"nodeName">> => string(), %% <<"nodeOutputName">> => string() %% } -type flow_input() :: #{binary() => any()}. %% Example: %% generated_response_part() :: #{ %% <<"textResponsePart">> => text_response_part() %% } -type generated_response_part() :: #{binary() => any()}. %% Example: %% memory_session_summary() :: #{ %% <<"memoryId">> => string(), %% <<"sessionExpiryTime">> => non_neg_integer(), %% <<"sessionId">> => string(), %% <<"sessionStartTime">> => non_neg_integer(), %% <<"summaryText">> => string() %% } -type memory_session_summary() :: #{binary() => any()}. %% Example: %% validation_exception() :: #{ %% <<"message">> => string() %% } -type validation_exception() :: #{binary() => any()}. %% Example: %% get_agent_memory_response() :: #{ %% <<"memoryContents">> => list(list()()), %% <<"nextToken">> => string() %% } -type get_agent_memory_response() :: #{binary() => any()}. %% Example: %% throttling_exception() :: #{ %% <<"message">> => string() %% } -type throttling_exception() :: #{binary() => any()}. %% Example: %% retrieve_and_generate_output() :: #{ %% <<"text">> => [string()] %% } -type retrieve_and_generate_output() :: #{binary() => any()}. %% Example: %% flow_output_event() :: #{ %% <<"content">> => list(), %% <<"nodeName">> => string(), %% <<"nodeType">> => list(any()) %% } -type flow_output_event() :: #{binary() => any()}. %% Example: %% action_group_invocation_output() :: #{ %% <<"text">> => string() %% } -type action_group_invocation_output() :: #{binary() => any()}. %% Example: %% raw_response() :: #{ %% <<"content">> => [string()] %% } -type raw_response() :: #{binary() => any()}. %% Example: %% guardrail_configuration() :: #{ %% <<"guardrailId">> => [string()], %% <<"guardrailVersion">> => [string()] %% } -type guardrail_configuration() :: #{binary() => any()}. %% Example: %% guardrail_regex_filter() :: #{ %% <<"action">> => list(any()), %% <<"match">> => [string()], %% <<"name">> => [string()], %% <<"regex">> => [string()] %% } -type guardrail_regex_filter() :: #{binary() => any()}. %% Example: %% retrieval_result_web_location() :: #{ %% <<"url">> => [string()] %% } -type retrieval_result_web_location() :: #{binary() => any()}. %% Example: %% delete_agent_memory_request() :: #{ %% <<"memoryId">> => string() %% } -type delete_agent_memory_request() :: #{binary() => any()}. %% Example: %% knowledge_base_lookup_output() :: #{ %% <<"retrievedReferences">> => list(retrieved_reference()()) %% } -type knowledge_base_lookup_output() :: #{binary() => any()}. %% Example: %% byte_content_file() :: #{ %% <<"data">> => binary(), %% <<"mediaType">> => string() %% } -type byte_content_file() :: #{binary() => any()}. %% Example: %% retrieve_request() :: #{ %% <<"nextToken">> => string(), %% <<"retrievalConfiguration">> => knowledge_base_retrieval_configuration(), %% <<"retrievalQuery">> := knowledge_base_query() %% } -type retrieve_request() :: #{binary() => any()}. %% Example: %% invoke_agent_request() :: #{ %% <<"enableTrace">> => [boolean()], %% <<"endSession">> => [boolean()], %% <<"inputText">> => string(), %% <<"memoryId">> => string(), %% <<"sessionState">> => session_state() %% } -type invoke_agent_request() :: #{binary() => any()}. %% Example: %% invocation_input() :: #{ %% <<"actionGroupInvocationInput">> => action_group_invocation_input(), %% <<"codeInterpreterInvocationInput">> => code_interpreter_invocation_input(), %% <<"invocationType">> => list(any()), %% <<"knowledgeBaseLookupInput">> => knowledge_base_lookup_input(), %% <<"traceId">> => string() %% } -type invocation_input() :: #{binary() => any()}. %% Example: %% request_body() :: #{ %% <<"content">> => map() %% } -type request_body() :: #{binary() => any()}. %% Example: %% get_agent_memory_request() :: #{ %% <<"maxItems">> => integer(), %% <<"memoryId">> := string(), %% <<"memoryType">> := list(any()), %% <<"nextToken">> => string() %% } -type get_agent_memory_request() :: #{binary() => any()}. %% Example: %% s3_object_file() :: #{ %% <<"uri">> => string() %% } -type s3_object_file() :: #{binary() => any()}. %% Example: %% post_processing_model_invocation_output() :: #{ %% <<"parsedResponse">> => post_processing_parsed_response(), %% <<"traceId">> => string() %% } -type post_processing_model_invocation_output() :: #{binary() => any()}. %% Example: %% guardrail_pii_entity_filter() :: #{ %% <<"action">> => list(any()), %% <<"match">> => [string()], %% <<"type">> => list(any()) %% } -type guardrail_pii_entity_filter() :: #{binary() => any()}. %% Example: %% orchestration_model_invocation_output() :: #{ %% <<"metadata">> => metadata(), %% <<"rawResponse">> => raw_response(), %% <<"traceId">> => string() %% } -type orchestration_model_invocation_output() :: #{binary() => any()}. %% Example: %% invoke_flow_request() :: #{ %% <<"inputs">> := list(flow_input()()) %% } -type invoke_flow_request() :: #{binary() => any()}. %% Example: %% file_source() :: #{ %% <<"byteContent">> => byte_content_file(), %% <<"s3Location">> => s3_object_file(), %% <<"sourceType">> => list(any()) %% } -type file_source() :: #{binary() => any()}. %% Example: %% retrieve_response() :: #{ %% <<"nextToken">> => string(), %% <<"retrievalResults">> => list(knowledge_base_retrieval_result()()) %% } -type retrieve_response() :: #{binary() => any()}. %% Example: %% knowledge_base_lookup_input() :: #{ %% <<"knowledgeBaseId">> => string(), %% <<"text">> => string() %% } -type knowledge_base_lookup_input() :: #{binary() => any()}. %% Example: %% code_interpreter_invocation_input() :: #{ %% <<"code">> => [string()], %% <<"files">> => list([string()]()) %% } -type code_interpreter_invocation_input() :: #{binary() => any()}. %% Example: %% knowledge_base_retrieval_result() :: #{ %% <<"content">> => retrieval_result_content(), %% <<"location">> => retrieval_result_location(), %% <<"metadata">> => map(), %% <<"score">> => [float()] %% } -type knowledge_base_retrieval_result() :: #{binary() => any()}. %% Example: %% guardrail_topic() :: #{ %% <<"action">> => list(any()), %% <<"name">> => [string()], %% <<"type">> => list(any()) %% } -type guardrail_topic() :: #{binary() => any()}. -type delete_agent_memory_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). -type get_agent_memory_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). -type invoke_agent_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). -type invoke_flow_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). -type retrieve_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). -type retrieve_and_generate_errors() :: throttling_exception() | validation_exception() | access_denied_exception() | internal_server_exception() | service_quota_exceeded_exception() | resource_not_found_exception() | conflict_exception() | dependency_failed_exception() | bad_gateway_exception(). %%==================================================================== %% API %%==================================================================== %% @doc Deletes memory from the specified memory identifier. -spec delete_agent_memory(aws_client:aws_client(), binary() | list(), binary() | list(), delete_agent_memory_request()) -> {ok, delete_agent_memory_response(), tuple()} | {error, any()} | {error, delete_agent_memory_errors(), tuple()}. delete_agent_memory(Client, AgentAliasId, AgentId, Input) -> delete_agent_memory(Client, AgentAliasId, AgentId, Input, []). -spec delete_agent_memory(aws_client:aws_client(), binary() | list(), binary() | list(), delete_agent_memory_request(), proplists:proplist()) -> {ok, delete_agent_memory_response(), tuple()} | {error, any()} | {error, delete_agent_memory_errors(), tuple()}. delete_agent_memory(Client, AgentAliasId, AgentId, Input0, Options0) -> Method = delete, Path = ["/agents/", aws_util:encode_uri(AgentId), "/agentAliases/", aws_util:encode_uri(AgentAliasId), "/memories"], SuccessStatusCode = 202, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, QueryMapping = [ {<<"memoryId">>, <<"memoryId">>} ], {Query_, Input} = aws_request:build_headers(QueryMapping, Input2), request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Gets the sessions stored in the memory of the agent. -spec get_agent_memory(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), binary() | list()) -> {ok, get_agent_memory_response(), tuple()} | {error, any()} | {error, get_agent_memory_errors(), tuple()}. get_agent_memory(Client, AgentAliasId, AgentId, MemoryId, MemoryType) when is_map(Client) -> get_agent_memory(Client, AgentAliasId, AgentId, MemoryId, MemoryType, #{}, #{}). -spec get_agent_memory(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), binary() | list(), map(), map()) -> {ok, get_agent_memory_response(), tuple()} | {error, any()} | {error, get_agent_memory_errors(), tuple()}. get_agent_memory(Client, AgentAliasId, AgentId, MemoryId, MemoryType, QueryMap, HeadersMap) when is_map(Client), is_map(QueryMap), is_map(HeadersMap) -> get_agent_memory(Client, AgentAliasId, AgentId, MemoryId, MemoryType, QueryMap, HeadersMap, []). -spec get_agent_memory(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), binary() | list(), map(), map(), proplists:proplist()) -> {ok, get_agent_memory_response(), tuple()} | {error, any()} | {error, get_agent_memory_errors(), tuple()}. get_agent_memory(Client, AgentAliasId, AgentId, MemoryId, MemoryType, QueryMap, HeadersMap, Options0) when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) -> Path = ["/agents/", aws_util:encode_uri(AgentId), "/agentAliases/", aws_util:encode_uri(AgentAliasId), "/memories"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary} | Options2], Headers = [], Query0_ = [ {<<"maxItems">>, maps:get(<<"maxItems">>, QueryMap, undefined)}, {<<"memoryId">>, MemoryId}, {<<"memoryType">>, MemoryType}, {<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)} ], Query_ = [H || {_, V} = H <- Query0_, V =/= undefined], request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode). %% @doc %% The CLI doesn't support streaming operations in Amazon Bedrock, %% including `InvokeAgent'. %% %% Sends a prompt for the agent to process and respond to. Note the following %% fields for the request: %% %% To continue the same conversation with an agent, use the same %% `sessionId' value in the request. %% %% To activate trace enablement, turn `enableTrace' to `true'. Trace %% enablement helps you follow the agent's reasoning process that led it %% to the information it processed, the actions it took, and the final result %% it yielded. For more information, see Trace enablement: %% https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html#trace-events. %% %% End a conversation by setting `endSession' to `true'. %% %% In the `sessionState' object, you can include attributes for the %% session or prompt or, if you configured an action group to return control, %% results from invocation of the action group. %% %% The response is returned in the `bytes' field of the `chunk' %% object. %% %% The `attribution' object contains citations for parts of the response. %% %% If you set `enableTrace' to `true' in the request, you can trace %% the agent's steps and reasoning process that led it to the response. %% %% If the action predicted was configured to return control, the response %% returns parameters for the action, elicited from the user, in the %% `returnControl' field. %% %% Errors are also surfaced in the response. -spec invoke_agent(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), invoke_agent_request()) -> {ok, invoke_agent_response(), tuple()} | {error, any()} | {error, invoke_agent_errors(), tuple()}. invoke_agent(Client, AgentAliasId, AgentId, SessionId, Input) -> invoke_agent(Client, AgentAliasId, AgentId, SessionId, Input, []). -spec invoke_agent(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), invoke_agent_request(), proplists:proplist()) -> {ok, invoke_agent_response(), tuple()} | {error, any()} | {error, invoke_agent_errors(), tuple()}. invoke_agent(Client, AgentAliasId, AgentId, SessionId, Input0, Options0) -> Method = post, Path = ["/agents/", aws_util:encode_uri(AgentId), "/agentAliases/", aws_util:encode_uri(AgentAliasId), "/sessions/", aws_util:encode_uri(SessionId), "/text"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, case request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode) of {ok, Body0, {_, ResponseHeaders, _} = Response} -> ResponseHeadersParams = [ {<<"x-amzn-bedrock-agent-content-type">>, <<"contentType">>}, {<<"x-amz-bedrock-agent-memory-id">>, <<"memoryId">>}, {<<"x-amz-bedrock-agent-session-id">>, <<"sessionId">>} ], FoldFun = fun({Name_, Key_}, Acc_) -> case lists:keyfind(Name_, 1, ResponseHeaders) of false -> Acc_; {_, Value_} -> Acc_#{Key_ => Value_} end end, Body = lists:foldl(FoldFun, Body0, ResponseHeadersParams), {ok, Body, Response}; Result -> Result end. %% @doc Invokes an alias of a flow to run the inputs that you specify and %% return the output of each node as a stream. %% %% If there's an error, the error is returned. For more information, see %% Test a flow in Amazon Bedrock: %% https://docs.aws.amazon.com/bedrock/latest/userguide/flows-test.html in %% the Amazon Bedrock User Guide. %% %% The CLI doesn't support streaming operations in Amazon Bedrock, %% including `InvokeFlow'. -spec invoke_flow(aws_client:aws_client(), binary() | list(), binary() | list(), invoke_flow_request()) -> {ok, invoke_flow_response(), tuple()} | {error, any()} | {error, invoke_flow_errors(), tuple()}. invoke_flow(Client, FlowAliasIdentifier, FlowIdentifier, Input) -> invoke_flow(Client, FlowAliasIdentifier, FlowIdentifier, Input, []). -spec invoke_flow(aws_client:aws_client(), binary() | list(), binary() | list(), invoke_flow_request(), proplists:proplist()) -> {ok, invoke_flow_response(), tuple()} | {error, any()} | {error, invoke_flow_errors(), tuple()}. invoke_flow(Client, FlowAliasIdentifier, FlowIdentifier, Input0, Options0) -> Method = post, Path = ["/flows/", aws_util:encode_uri(FlowIdentifier), "/aliases/", aws_util:encode_uri(FlowAliasIdentifier), ""], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Queries a knowledge base and retrieves information from it. -spec retrieve(aws_client:aws_client(), binary() | list(), retrieve_request()) -> {ok, retrieve_response(), tuple()} | {error, any()} | {error, retrieve_errors(), tuple()}. retrieve(Client, KnowledgeBaseId, Input) -> retrieve(Client, KnowledgeBaseId, Input, []). -spec retrieve(aws_client:aws_client(), binary() | list(), retrieve_request(), proplists:proplist()) -> {ok, retrieve_response(), tuple()} | {error, any()} | {error, retrieve_errors(), tuple()}. retrieve(Client, KnowledgeBaseId, Input0, Options0) -> Method = post, Path = ["/knowledgebases/", aws_util:encode_uri(KnowledgeBaseId), "/retrieve"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Queries a knowledge base and generates responses based on the %% retrieved results and using the specified foundation model or inference %% profile: %% https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html. %% %% The response only cites sources that are relevant to the query. -spec retrieve_and_generate(aws_client:aws_client(), retrieve_and_generate_request()) -> {ok, retrieve_and_generate_response(), tuple()} | {error, any()} | {error, retrieve_and_generate_errors(), tuple()}. retrieve_and_generate(Client, Input) -> retrieve_and_generate(Client, Input, []). -spec retrieve_and_generate(aws_client:aws_client(), retrieve_and_generate_request(), proplists:proplist()) -> {ok, retrieve_and_generate_response(), tuple()} | {error, any()} | {error, retrieve_and_generate_errors(), tuple()}. retrieve_and_generate(Client, Input0, Options0) -> Method = post, Path = ["/retrieveAndGenerate"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %%==================================================================== %% Internal functions %%==================================================================== -spec proplists_take(any(), proplists:proplist(), any()) -> {any(), proplists:proplist()}. proplists_take(Key, Proplist, Default) -> Value = proplists:get_value(Key, Proplist, Default), {Value, proplists:delete(Key, Proplist)}. -spec request(aws_client:aws_client(), atom(), iolist(), list(), list(), map() | undefined, list(), pos_integer() | undefined) -> {ok, {integer(), list()}} | {ok, Result, {integer(), list(), hackney:client()}} | {error, Error, {integer(), list(), hackney:client()}} | {error, term()} when Result :: map(), Error :: map(). request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) -> RequestFun = fun() -> do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) end, aws_request:request(RequestFun, Options). do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) -> Client1 = Client#{service => <<"bedrock">>}, Host = build_host(<<"bedrock-agent-runtime">>, Client1), URL0 = build_url(Host, Path, Client1), URL = aws_request:add_query(URL0, Query), AdditionalHeaders1 = [ {<<"Host">>, Host} , {<<"Content-Type">>, <<"application/x-amz-json-1.1">>} ], Payload = case proplists:get_value(send_body_as_binary, Options) of true -> maps:get(<<"Body">>, Input, <<"">>); false -> encode_payload(Input) end, AdditionalHeaders = case proplists:get_value(append_sha256_content_hash, Options, false) of true -> add_checksum_hash_header(AdditionalHeaders1, Payload); false -> AdditionalHeaders1 end, Headers1 = aws_request:add_headers(AdditionalHeaders, Headers0), MethodBin = aws_request:method_to_binary(Method), SignedHeaders = aws_request:sign_request(Client1, MethodBin, URL, Headers1, Payload), Response = hackney:request(Method, URL, SignedHeaders, Payload, Options), DecodeBody = not proplists:get_value(receive_body_as_binary, Options), handle_response(Response, SuccessStatusCode, DecodeBody). add_checksum_hash_header(Headers, Body) -> [ {<<"X-Amz-CheckSum-SHA256">>, base64:encode(crypto:hash(sha256, Body))} | Headers ]. handle_response({ok, StatusCode, ResponseHeaders}, SuccessStatusCode, _DecodeBody) when StatusCode =:= 200; StatusCode =:= 202; StatusCode =:= 204; StatusCode =:= 206; StatusCode =:= SuccessStatusCode -> {ok, {StatusCode, ResponseHeaders}}; handle_response({ok, StatusCode, ResponseHeaders}, _, _DecodeBody) -> {error, {StatusCode, ResponseHeaders}}; handle_response({ok, StatusCode, ResponseHeaders, Client}, SuccessStatusCode, DecodeBody) when StatusCode =:= 200; StatusCode =:= 202; StatusCode =:= 204; StatusCode =:= 206; StatusCode =:= SuccessStatusCode -> case hackney:body(Client) of {ok, <<>>} when StatusCode =:= 200; StatusCode =:= SuccessStatusCode -> {ok, #{}, {StatusCode, ResponseHeaders, Client}}; {ok, Body} -> Result = case DecodeBody of true -> try jsx:decode(Body) catch Error:Reason:Stack -> erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack) end; false -> #{<<"Body">> => Body} end, {ok, Result, {StatusCode, ResponseHeaders, Client}} end; handle_response({ok, StatusCode, _ResponseHeaders, _Client}, _, _DecodeBody) when StatusCode =:= 503 -> %% Retriable error if retries are enabled {error, service_unavailable}; handle_response({ok, StatusCode, ResponseHeaders, Client}, _, _DecodeBody) -> {ok, Body} = hackney:body(Client), try DecodedError = jsx:decode(Body), {error, DecodedError, {StatusCode, ResponseHeaders, Client}} catch Error:Reason:Stack -> erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack) end; handle_response({error, Reason}, _, _DecodeBody) -> {error, Reason}. build_host(_EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) -> Endpoint; build_host(_EndpointPrefix, #{region := <<"local">>}) -> <<"localhost">>; build_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) -> aws_util:binary_join([EndpointPrefix, Region, Endpoint], <<".">>). build_url(Host, Path0, Client) -> Proto = aws_client:proto(Client), Path = erlang:iolist_to_binary(Path0), Port = aws_client:port(Client), aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, Path], <<"">>). -spec encode_payload(undefined | map()) -> binary(). encode_payload(undefined) -> <<>>; encode_payload(Input) -> jsx:encode(Input).