AWS Bedrock Agent Runtime
Since Camel 4.5
Only producer is supported
The AWS2 Bedrock component supports invoking a supported LLM model from AWS Bedrock service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Bedrock. More information is available at Amazon Bedrock.
URI Format
aws-bedrock-agent-runtime://label[?options]
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Bedrock Agent Runtime component supports 28 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Component configuration. | BedrockAgentRuntimeConfiguration | ||
Required Define the Knowledge Base Id we are going to use. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Required Define the model Id we are going to use. Enum values:
| String | ||
Required The operation to perform. Enum values:
| BedrockAgentRuntimeOperations | ||
Set the need for overriding the endpoint. This option needs to be used in combination with the uriEndpointOverride option. | false | boolean | |
If we want to use a POJO request as body or not. | false | boolean | |
If using a profile credentials provider, this parameter will set the profile name. | false | String | |
The region in which Bedrock Agent Runtime client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example, ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). Enum values:
| String | ||
Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | ||
Set whether the Bedrock Agent Runtime client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean | |
Set whether the Bedrock Agent Runtime client should expect to load credentials through a profile credentials provider. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired To use an existing configured AWS Bedrock Agent Runtime async client (required for invokeFlow which streams events back). | BedrockAgentRuntimeAsyncClient | ||
Autowired To use an existing configured AWS Bedrock Agent Runtime client. | BedrockAgentRuntimeClient | ||
Enables tracing for the invokeFlow operation. When enabled, the producer collects FlowTraceEvent entries and publishes them in the CamelAwsBedrockAgentRuntimeFlowTraces header. | false | boolean | |
The unique identifier of the Bedrock flow alias to invoke (used by the invokeFlow operation). Can be overridden per exchange via the CamelAwsBedrockAgentRuntimeFlowAliasIdentifier header. | String | ||
The unique identifier of the Bedrock flow to invoke (used by the invokeFlow operation). Can be overridden per exchange via the CamelAwsBedrockAgentRuntimeFlowIdentifier header. | String | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
To define a proxy host when instantiating the Bedrock Agent Runtime client. | String | ||
To define a proxy port when instantiating the Bedrock Agent Runtime client. | Integer | ||
To define a proxy protocol when instantiating the Bedrock Agent Runtime client. Enum values:
| HTTPS | Protocol | |
Amazon AWS Access Key. | String | ||
Amazon AWS Secret Key. | String | ||
Amazon AWS Session Token used when the user needs to assume an IAM role. | String | ||
If we want to trust all certificates in case of overriding the endpoint. | false | boolean | |
Set whether the Bedrock Agent Runtime client should expect to use Session Credentials. This is useful in a situation in which the user needs to assume an IAM role for doing operations in Bedrock. | false | boolean |
Endpoint Options
The AWS Bedrock Agent Runtime endpoint is configured using URI syntax:
aws-bedrock-agent-runtime:label
With the following path and query parameters:
Query Parameters (24 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Required Define the Knowledge Base Id we are going to use. | String | ||
Required Define the model Id we are going to use. Enum values:
| String | ||
Required The operation to perform. Enum values:
| BedrockAgentRuntimeOperations | ||
Set the need for overriding the endpoint. This option needs to be used in combination with the uriEndpointOverride option. | false | boolean | |
If we want to use a POJO request as body or not. | false | boolean | |
If using a profile credentials provider, this parameter will set the profile name. | false | String | |
The region in which Bedrock Agent Runtime client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example, ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). Enum values:
| String | ||
Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | ||
Set whether the Bedrock Agent Runtime client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean | |
Set whether the Bedrock Agent Runtime client should expect to load credentials through a profile credentials provider. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use an existing configured AWS Bedrock Agent Runtime async client (required for invokeFlow which streams events back). | BedrockAgentRuntimeAsyncClient | ||
Autowired To use an existing configured AWS Bedrock Agent Runtime client. | BedrockAgentRuntimeClient | ||
Enables tracing for the invokeFlow operation. When enabled, the producer collects FlowTraceEvent entries and publishes them in the CamelAwsBedrockAgentRuntimeFlowTraces header. | false | boolean | |
The unique identifier of the Bedrock flow alias to invoke (used by the invokeFlow operation). Can be overridden per exchange via the CamelAwsBedrockAgentRuntimeFlowAliasIdentifier header. | String | ||
The unique identifier of the Bedrock flow to invoke (used by the invokeFlow operation). Can be overridden per exchange via the CamelAwsBedrockAgentRuntimeFlowIdentifier header. | String | ||
To define a proxy host when instantiating the Bedrock Agent Runtime client. | String | ||
To define a proxy port when instantiating the Bedrock Agent Runtime client. | Integer | ||
To define a proxy protocol when instantiating the Bedrock Agent Runtime client. Enum values:
| HTTPS | Protocol | |
Amazon AWS Access Key. | String | ||
Amazon AWS Secret Key. | String | ||
Amazon AWS Session Token used when the user needs to assume an IAM role. | String | ||
If we want to trust all certificates in case of overriding the endpoint. | false | boolean | |
Set whether the Bedrock Agent Runtime client should expect to use Session Credentials. This is useful in a situation in which the user needs to assume an IAM role for doing operations in Bedrock. | false | boolean |
Message Headers
The AWS Bedrock Agent Runtime component supports 15 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsBedrockAgentRuntimeOperation (producer) Constant: | The operation we want to perform. | String | |
CamelAwsBedrockAgentRuntimeCitations (producer) Constant: | When retrieving and generating a response, this header will contain the citations. | String | |
CamelAwsBedrockAgentRuntimeSessionId (producer) Constant: | When retrieving and generating a response, this header will contain he unique identifier of the session. Reuse the same value to continue the same session with the knowledge base. | String | |
CamelAwsBedrockAgentRuntimeFlowIdentifier (producer) Constant: | The unique identifier of the flow to invoke. Overrides the flowIdentifier configured on the endpoint. | String | |
CamelAwsBedrockAgentRuntimeFlowAliasIdentifier (producer) Constant: | The unique identifier of the flow alias to invoke. Overrides the flowAliasIdentifier configured on the endpoint. | String | |
CamelAwsBedrockAgentRuntimeFlowEnableTrace (producer) Constant: | Enables tracing for the flow invocation. When set, overrides the enableTrace option on the endpoint. | Boolean | |
CamelAwsBedrockAgentRuntimeFlowExecutionId (producer) Constant: | The unique identifier of an in-progress flow execution to continue. Used for multi-turn flow conversations. | String | |
CamelAwsBedrockAgentRuntimeFlowOutputs (producer) Constant: | When invoking a flow, this header will contain the list of FlowOutputEvent emitted by the flow. | List | |
CamelAwsBedrockAgentRuntimeFlowTraces (producer) Constant: | When invoking a flow with tracing enabled, this header will contain the list of FlowTraceEvent emitted during execution. | List | |
CamelAwsBedrockAgentRuntimeFlowCompletionReason (producer) Constant: | When invoking a flow, this header will contain the reason the flow completed (set when a FlowCompletionEvent is received). | String | |
CamelAwsBedrockAgentRuntimeRetrievedResults (producer) Constant: | When performing a retrieve operation, this header will contain the list of KnowledgeBaseRetrievalResult chunks returned by the knowledge base. | List | |
CamelAwsBedrockAgentRuntimeNumberOfResults (producer) Constant: | Overrides the maximum number of results returned by the retrieve operation. Must be a positive Integer; when not set the AWS service default is used. | Integer | |
CamelAwsBedrockAgentRuntimeSearchType (producer) Constant: | Overrides the search type used by the retrieve operation. Accepts the AWS SearchType enum (HYBRID, SEMANTIC) or its String representation. | String | |
CamelAwsBedrockAgentRuntimeNextToken (producer) Constant: | Pagination token used by the retrieve operation. Set on the in-message to request the next page; set on the out-message when the response carries one. | String | |
CamelAwsBedrockAgentRuntimeRetrieveGuardrailAction (producer) Constant: | When performing a retrieve operation, this header will contain the guardrail action (if any) applied by the knowledge base. | String |
Required Bedrock component options
You have to provide the bedrockRuntimeClient in the Registry or your accessKey and secretKey to access the Amazon Bedrock service.
Usage
Supported operations
The component supports the following operations on the operation URI option:
-
retrieveAndGenerate— Query a Bedrock Knowledge Base and generate a grounded response from the selected model. -
retrieve— Run a semantic search against a Bedrock Knowledge Base and return the matched chunks without LLM generation. -
invokeFlow— Invoke a Bedrock Flow by id/alias and stream the resulting events back as Camel message headers.
Retrieving from a Bedrock Knowledge Base
The retrieve operation performs a semantic search against a Bedrock Knowledge Base and returns the matching chunks without invoking an LLM. Use this when you want to plug retrieval into your own generation step, inspect retrieval quality, or build pagination on top of the knowledge base.
Mandatory options:
-
knowledgeBaseId— the id of the Bedrock Knowledge Base to query.
The body of the in-message must be a String containing the search query. When pojoRequest=true, the body must be a RetrieveRequest (any retrieval-config knobs in that POJO are honored verbatim).
The retrieval configuration can be tuned per exchange via the following headers:
-
CamelAwsBedrockAgentRuntimeNumberOfResults(Integer) — maximum number of chunks to return. -
CamelAwsBedrockAgentRuntimeSearchType(String) — overrides the search type (HYBRIDorSEMANTIC). -
CamelAwsBedrockAgentRuntimeNextToken(String) — pagination token returned by a previous call.
The producer surfaces the matched chunks as the out-message body (a List<KnowledgeBaseRetrievalResult>) and on the following headers:
-
CamelAwsBedrockAgentRuntimeRetrievedResults— the sameList<KnowledgeBaseRetrievalResult>available on the body. -
CamelAwsBedrockAgentRuntimeNextToken— present when the response carries a pagination token. -
CamelAwsBedrockAgentRuntimeRetrieveGuardrailAction— present when the knowledge base applies a guardrail action.
Invoking a Bedrock Flow
The invokeFlow operation streams flow events using the AWS SDK async client; the producer transparently allocates a BedrockAgentRuntimeAsyncClient when the endpoint is configured with operation=invokeFlow.
Mandatory options:
-
flowIdentifier— the unique id of the flow to invoke (overridable via theCamelAwsBedrockAgentRuntimeFlowIdentifierheader). -
flowAliasIdentifier— the unique id of the flow alias to invoke (overridable via theCamelAwsBedrockAgentRuntimeFlowAliasIdentifierheader).
Optional options:
-
enableTrace— whentrue, the producer collects the emittedFlowTraceEvent`s into the `CamelAwsBedrockAgentRuntimeFlowTracesheader (overridable viaCamelAwsBedrockAgentRuntimeFlowEnableTrace).
The body of the in-message can be:
-
a
String— wrapped in a singleFlowInputtargeting nodeFlowInputNode, outputdocument; -
a
FlowInputinstance — used as the sole input to the flow; -
a
List<FlowInput>— passed verbatim to the request (use this form to chain multiple flow inputs).
When pojoRequest=true, the body must be an InvokeFlowRequest and is sent unchanged.
The producer collects emitted events into headers:
-
CamelAwsBedrockAgentRuntimeFlowOutputs— the list of `FlowOutputEvent`s emitted by the flow. -
CamelAwsBedrockAgentRuntimeFlowTraces— the list of `FlowTraceEvent`s (only when tracing is enabled). -
CamelAwsBedrockAgentRuntimeFlowCompletionReason— the completion reason reported by the flow (when present).
The out-message body is the document of the last FlowOutputEvent (decoded as String when the document is a string, otherwise the raw Document). When the flow emits no outputs, the body is left untouched.
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws-bedrock</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.
Spring Boot Auto-Configuration
When using aws-bedrock-agent-runtime with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-aws-bedrock-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> The component supports 87 options, which are listed below.