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 the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The configuration that the endpoints of the component start from. Each endpoint uses a copy of it, in which its own URI options replace the values. | BedrockAgentRuntimeConfiguration | ||
The ID of the knowledge base that retrieve and retrieveAndGenerate query. The other operations do not use it, and neither do these with pojoRequest. | 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 | |
The ID or ARN of the model that retrieveAndGenerate generates the answer with, for example anthropic.claude-3-5-sonnet-20241022-v2:0. The other operations do not use it, and neither does retrieveAndGenerate with pojoRequest. Enum values:
| String | ||
Required The operation that the producer performs. The CamelAwsBedrockAgentRuntimeOperation header replaces this option. Enum values:
| BedrockAgentRuntimeOperations | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request object of the AWS SDK for the operation, which the producer sends as it is: a RetrieveAndGenerateRequest, RetrieveRequest, InvokeFlowRequest, InvokeAgentRequest or InvokeInlineAgentRequest. The options and headers that build the request are then not used, and a body of another type fails the exchange. | false | boolean | |
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | false | String | |
The AWS region of Amazon Bedrock, as a region ID such as us-east-1, which is the value of Region.US_EAST_1.id(). If not set, the AWS SDK takes the region from its default region provider chain, for example the AWS_REGION environment variable. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | 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 a custom software.amazon.awssdk.services.bedrockagentruntime.BedrockAgentRuntimeAsyncClient for invokeFlow, invokeAgent and invokeInlineAgent, which receive their response as an event stream. When it is not set, the endpoint builds one from the credentials, region, proxy and endpoint override options: at start when the operation option is one of these, or else on first use. The Camel endpoint does not close a client that is set or autowired. | BedrockAgentRuntimeAsyncClient | ||
Autowired To use a custom software.amazon.awssdk.services.bedrockagentruntime.BedrockAgentRuntimeClient for retrieve and retrieveAndGenerate. When this option is set or autowired, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used for this client. The Camel endpoint does not close a client that is set or autowired. | BedrockAgentRuntimeClient | ||
The ID of the alias of the agent that invokeAgent invokes. The CamelAwsBedrockAgentRuntimeAgentAliasId header replaces this option. | String | ||
The ID of the agent that invokeAgent invokes. The CamelAwsBedrockAgentRuntimeAgentId header replaces this option. | String | ||
Whether invokeFlow, invokeAgent and invokeInlineAgent ask for the trace events of the invocation, which the producer gives in the CamelAwsBedrockAgentRuntimeFlowTraces or CamelAwsBedrockAgentRuntimeAgentTraces header. The CamelAwsBedrockAgentRuntimeFlowEnableTrace header replaces it for invokeFlow, and the CamelAwsBedrockAgentRuntimeAgentEnableTrace header for the agent operations. | false | boolean | |
The ID of the foundation model that the inline agent of invokeInlineAgent uses, for example anthropic.claude-3-5-sonnet-20241022-v2:0. The CamelAwsBedrockAgentRuntimeAgentFoundationModel header replaces this option. | String | ||
The instructions that tell the inline agent of invokeInlineAgent what to do and how to interact with users. The CamelAwsBedrockAgentRuntimeAgentInstruction header replaces this option. | String | ||
The ID of the session of invokeAgent and invokeInlineAgent: reuse the same value to continue the conversation. The CamelAwsBedrockAgentRuntimeSessionId header replaces this option. If neither is set, the producer uses a random ID for each message, and gives it in that header. | String | ||
How invokeAgent and invokeInlineAgent give the answer: complete gives the whole text as a String, and chunks gives a List of the text of each chunk. In both modes the producer waits until the agent has finished. The CamelAwsBedrockAgentRuntimeAgentStreamOutputMode header replaces this option. Enum values:
| complete | String | |
The ID of the alias of the flow that invokeFlow invokes. The CamelAwsBedrockAgentRuntimeFlowAliasIdentifier header replaces this option. | String | ||
The ID of the flow that invokeFlow invokes. The CamelAwsBedrockAgentRuntimeFlowIdentifier header replaces this option. | 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 | |
The host name of the proxy that the HTTP clients of Bedrock Agent Runtime connect through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP clients of Bedrock Agent Runtime connect through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP clients of Bedrock Agent Runtime use to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. It is required, unless bedrockAgentRuntimeClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. It is required, unless bedrockAgentRuntimeClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. When it is not set, the accessKey and secretKey options are used without a session token. | String | ||
Whether the HTTP clients of Bedrock Agent Runtime trust every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | 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
| Name | Description | Default | Type |
|---|---|---|---|
The ID of the knowledge base that retrieve and retrieveAndGenerate query. The other operations do not use it, and neither do these with pojoRequest. | String | ||
The ID or ARN of the model that retrieveAndGenerate generates the answer with, for example anthropic.claude-3-5-sonnet-20241022-v2:0. The other operations do not use it, and neither does retrieveAndGenerate with pojoRequest. Enum values:
| String | ||
Required The operation that the producer performs. The CamelAwsBedrockAgentRuntimeOperation header replaces this option. Enum values:
| BedrockAgentRuntimeOperations | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request object of the AWS SDK for the operation, which the producer sends as it is: a RetrieveAndGenerateRequest, RetrieveRequest, InvokeFlowRequest, InvokeAgentRequest or InvokeInlineAgentRequest. The options and headers that build the request are then not used, and a body of another type fails the exchange. | false | boolean | |
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | false | String | |
The AWS region of Amazon Bedrock, as a region ID such as us-east-1, which is the value of Region.US_EAST_1.id(). If not set, the AWS SDK takes the region from its default region provider chain, for example the AWS_REGION environment variable. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | 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 a custom software.amazon.awssdk.services.bedrockagentruntime.BedrockAgentRuntimeAsyncClient for invokeFlow, invokeAgent and invokeInlineAgent, which receive their response as an event stream. When it is not set, the endpoint builds one from the credentials, region, proxy and endpoint override options: at start when the operation option is one of these, or else on first use. The Camel endpoint does not close a client that is set or autowired. | BedrockAgentRuntimeAsyncClient | ||
Autowired To use a custom software.amazon.awssdk.services.bedrockagentruntime.BedrockAgentRuntimeClient for retrieve and retrieveAndGenerate. When this option is set or autowired, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used for this client. The Camel endpoint does not close a client that is set or autowired. | BedrockAgentRuntimeClient | ||
The ID of the alias of the agent that invokeAgent invokes. The CamelAwsBedrockAgentRuntimeAgentAliasId header replaces this option. | String | ||
The ID of the agent that invokeAgent invokes. The CamelAwsBedrockAgentRuntimeAgentId header replaces this option. | String | ||
Whether invokeFlow, invokeAgent and invokeInlineAgent ask for the trace events of the invocation, which the producer gives in the CamelAwsBedrockAgentRuntimeFlowTraces or CamelAwsBedrockAgentRuntimeAgentTraces header. The CamelAwsBedrockAgentRuntimeFlowEnableTrace header replaces it for invokeFlow, and the CamelAwsBedrockAgentRuntimeAgentEnableTrace header for the agent operations. | false | boolean | |
The ID of the foundation model that the inline agent of invokeInlineAgent uses, for example anthropic.claude-3-5-sonnet-20241022-v2:0. The CamelAwsBedrockAgentRuntimeAgentFoundationModel header replaces this option. | String | ||
The instructions that tell the inline agent of invokeInlineAgent what to do and how to interact with users. The CamelAwsBedrockAgentRuntimeAgentInstruction header replaces this option. | String | ||
The ID of the session of invokeAgent and invokeInlineAgent: reuse the same value to continue the conversation. The CamelAwsBedrockAgentRuntimeSessionId header replaces this option. If neither is set, the producer uses a random ID for each message, and gives it in that header. | String | ||
How invokeAgent and invokeInlineAgent give the answer: complete gives the whole text as a String, and chunks gives a List of the text of each chunk. In both modes the producer waits until the agent has finished. The CamelAwsBedrockAgentRuntimeAgentStreamOutputMode header replaces this option. Enum values:
| complete | String | |
The ID of the alias of the flow that invokeFlow invokes. The CamelAwsBedrockAgentRuntimeFlowAliasIdentifier header replaces this option. | String | ||
The ID of the flow that invokeFlow invokes. The CamelAwsBedrockAgentRuntimeFlowIdentifier header replaces this option. | String | ||
The host name of the proxy that the HTTP clients of Bedrock Agent Runtime connect through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP clients of Bedrock Agent Runtime connect through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP clients of Bedrock Agent Runtime use to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. It is required, unless bedrockAgentRuntimeClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. It is required, unless bedrockAgentRuntimeClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. When it is not set, the accessKey and secretKey options are used without a session token. | String | ||
Whether the HTTP clients of Bedrock Agent Runtime trust every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Bedrock Agent Runtime component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsBedrockAgentRuntimeOperation (producer) Constant: | The operation that the producer performs. It replaces the operation option. | String | |
CamelAwsBedrockAgentRuntimeCitations (producer) Constant: | The citations of the answer, which link its parts to the sources that they come from. Set by retrieveAndGenerate, invokeAgent and invokeInlineAgent when the answer has citations. | List | |
CamelAwsBedrockAgentRuntimeSessionId (producer) Constant: | The ID of the session. retrieveAndGenerate, invokeAgent and invokeInlineAgent read it to continue a session, and set it to the session of the response; for the agent operations it replaces the sessionId option. | String | |
CamelAwsBedrockAgentRuntimeAgentId (producer) Constant: | The ID of the agent for invokeAgent. It replaces the agentId option. | String | |
CamelAwsBedrockAgentRuntimeAgentAliasId (producer) Constant: | The ID of the alias of the agent for invokeAgent. It replaces the agentAliasId option. | String | |
CamelAwsBedrockAgentRuntimeAgentEnableTrace (producer) Constant: | Whether invokeAgent and invokeInlineAgent ask for the trace events of the invocation. It replaces the enableTrace option for them. | Boolean | |
CamelAwsBedrockAgentRuntimeAgentEndSession (producer) Constant: | Whether invokeAgent and invokeInlineAgent end the session after this invocation. | Boolean | |
CamelAwsBedrockAgentRuntimeAgentMemoryId (producer) Constant: | The ID of the memory of the agent for invokeAgent, which keeps a summary of the earlier sessions. invokeInlineAgent does not read it. | String | |
CamelAwsBedrockAgentRuntimeAgentStreamOutputMode (producer) Constant: | The output mode of invokeAgent and invokeInlineAgent: complete or chunks. It replaces the streamOutputMode option. | String | |
CamelAwsBedrockAgentRuntimeAgentFoundationModel (producer) Constant: | The ID of the foundation model of the inline agent for invokeInlineAgent. It replaces the foundationModel option. | String | |
CamelAwsBedrockAgentRuntimeAgentInstruction (producer) Constant: | The instructions of the inline agent for invokeInlineAgent. It replaces the instruction option. | String | |
CamelAwsBedrockAgentRuntimeAgentTraces (producer) Constant: | The trace events of the invocation: TracePart elements for invokeAgent, and InlineAgentTracePart elements for invokeInlineAgent. Set when the trace is enabled and the agent sends trace events. | List | |
CamelAwsBedrockAgentRuntimeAgentReturnControl (producer) Constant: | The actions that the agent returns to the caller to carry out, instead of calling an action group itself: ReturnControlPayload elements for invokeAgent, and InlineAgentReturnControlPayload elements for invokeInlineAgent. Set when the agent returns control. | List | |
CamelAwsBedrockAgentRuntimeAgentFiles (producer) Constant: | The files that the agent generated: FilePart elements for invokeAgent, and InlineAgentFilePart elements for invokeInlineAgent. Set when the agent sends files. | List | |
CamelAwsBedrockAgentRuntimeFlowIdentifier (producer) Constant: | The ID of the flow for invokeFlow. It replaces the flowIdentifier option. | String | |
CamelAwsBedrockAgentRuntimeFlowAliasIdentifier (producer) Constant: | The ID of the alias of the flow for invokeFlow. It replaces the flowAliasIdentifier option. | String | |
CamelAwsBedrockAgentRuntimeFlowEnableTrace (producer) Constant: | Whether invokeFlow asks for the trace events of the flow. It replaces the enableTrace option for invokeFlow. | Boolean | |
CamelAwsBedrockAgentRuntimeFlowExecutionId (producer) Constant: | The ID of a flow execution that invokeFlow continues, for a flow that waits for more input, as in a multi-turn conversation. | String | |
CamelAwsBedrockAgentRuntimeFlowOutputs (producer) Constant: | The output events of the flow, set by invokeFlow, as an empty List when the flow has no output. The body is the document of the last one. | List | |
CamelAwsBedrockAgentRuntimeFlowTraces (producer) Constant: | The trace events of the flow. Set by invokeFlow when the trace is enabled and the flow sends trace events. | List | |
CamelAwsBedrockAgentRuntimeFlowCompletionReason (producer) Constant: | The reason why the flow completed: SUCCESS, or INPUT_REQUIRED when it waits for more input. Set by invokeFlow when the flow sends a completion event. | String | |
CamelAwsBedrockAgentRuntimeRetrievedResults (producer) Constant: | The results that retrieve found in the knowledge base, the same List as the body. | List | |
CamelAwsBedrockAgentRuntimeNumberOfResults (producer) Constant: | The maximum number of results that retrieve returns. If not set, Amazon Bedrock uses its default. | Integer | |
CamelAwsBedrockAgentRuntimeSearchType (producer) Constant: | The search type of retrieve: HYBRID, which combines the vector search with a text search, or SEMANTIC, which uses the vector search only. If not set, Amazon Bedrock chooses one. | String | |
CamelAwsBedrockAgentRuntimeNextToken (producer) Constant: | The token of the next page of the results of retrieve. Set it to get that page; retrieve sets it when there are more results, and removes it when there are none. | String | |
CamelAwsBedrockAgentRuntimeRetrieveGuardrailAction (producer) Constant: | Whether the guardrail of the knowledge base intervened in retrieve: INTERVENED or NONE. Set by retrieve when the response has it, and removed otherwise. | String |
Message Body
The message body at each side of the AWS Bedrock Agent Runtime component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| The question, the query or the input of the agent as text for retrieveAndGenerate, retrieve, invokeAgent and invokeInlineAgent: bytes, a stream or a file are read as text, a Map or a Jackson JsonNode is sent as JSON text, another POJO as its toString(), so take the text out of it first, and no body fails. invokeFlow takes a String, which becomes the document of the input node FlowInputNode, or a FlowInput or a List of FlowInput of the AWS SDK: another body is read as text, as for the other operations. With pojoRequest=true the request of the AWS SDK for the operation, such as a RetrieveAndGenerateRequest: another body fails.
|
Producer output |
| The answer as text for retrieveAndGenerate, with the citations and the session id in headers, and a List of KnowledgeBaseRetrievalResult for retrieve. invokeAgent and invokeInlineAgent give the answer as text, or a List of the chunks with streamOutputMode=chunks or the CamelAwsBedrockAgentRuntimeAgentStreamOutputMode header; the text is empty when the agent returns control. invokeFlow gives the document of the last output of the flow as text, or as a Document of the AWS SDK for another type, and keeps the body when the flow has no output.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required Bedrock component options
You have to provide the bedrockAgentRuntimeClient 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. -
invokeAgent— Invoke a deployed Bedrock Agent by id/alias and stream the response back. -
invokeInlineAgent— Invoke an agent defined inline at invocation time (foundation model plus instruction).
The CamelAwsBedrockAgentRuntimeOperation header overrides the operation option per exchange. With neither set, the exchange fails with an IllegalArgumentException.
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 is the search query as a String. A Map or a Jackson JsonNode body is sent as JSON text, and another body is converted to a String. 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. When the CamelAwsBedrockAgentRuntimeOperation header picks invokeFlow, invokeAgent or invokeInlineAgent on an endpoint of another operation, the async client is created when the first exchange needs it.
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); -
a
Mapor a JacksonJsonNode— marshalled to JSON text and used as above; -
another body, such as a
byte[], anInputStreamor a file, is converted to aStringand used as above.
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.
Invoking a Bedrock Agent
The invokeAgent operation invokes a deployed Bedrock Agent. Like invokeFlow it uses the AWS SDK async client, and the producer transparently allocates a BedrockAgentRuntimeAsyncClient when the endpoint is configured with operation=invokeAgent.
Mandatory options:
-
agentId— the unique id of the agent to invoke (overridable via theCamelAwsBedrockAgentRuntimeAgentIdheader). -
agentAliasId— the unique id of the agent alias (overridable via theCamelAwsBedrockAgentRuntimeAgentAliasIdheader).
The in-message body is the input text sent to the agent. A Map or a Jackson JsonNode body is sent as JSON text, and another body is converted to a String. When pojoRequest=true, the body must be an InvokeAgentRequest and is sent unchanged.
The agent APIs are session based. Set sessionId on the endpoint, or the CamelAwsBedrockAgentRuntimeSessionId header, to continue an existing conversation; when neither is supplied a random session id is generated for the invocation. The session id used is always echoed back on the CamelAwsBedrockAgentRuntimeSessionId header of the out-message so a route can reuse it on the next call.
-
Java
-
YAML
from("direct:agent")
.to("aws-bedrock-agent-runtime://label?operation=invokeAgent&agentId=RAWAGENTID&agentAliasId=RAWALIASID"); - route:
from:
uri: direct:agent
steps:
- to:
uri: aws-bedrock-agent-runtime:label
parameters:
operation: invokeAgent
agentId: RAWAGENTID
agentAliasId: RAWALIASID Invoking an inline Bedrock Agent
The invokeInlineAgent operation defines the agent at invocation time instead of referencing a deployed one.
Mandatory options:
-
foundationModel— the model backing the agent (overridable via theCamelAwsBedrockAgentRuntimeAgentFoundationModelheader). -
instruction— the instruction given to the agent (overridable via theCamelAwsBedrockAgentRuntimeAgentInstructionheader).
For the richer inline options (action groups, knowledge bases, collaborators, guardrails), set pojoRequest=true and send an InvokeInlineAgentRequest body, which is passed to AWS unchanged.
Agent response and streaming output
Both agent operations stream their response. The producer collects the emitted events into headers:
-
CamelAwsBedrockAgentRuntimeAgentTraces— the trace events (only when tracing is enabled viaenableTraceor theCamelAwsBedrockAgentRuntimeAgentEnableTraceheader). -
CamelAwsBedrockAgentRuntimeAgentReturnControl— the return-control payloads, emitted when the agent asks the caller to fulfil an action. -
CamelAwsBedrockAgentRuntimeAgentFiles— the files emitted by the agent. -
CamelAwsBedrockAgentRuntimeCitations— the citations attributed to the response chunks.
The out-message body depends on streamOutputMode:
-
complete(the default) — the response chunks are accumulated and the body is the full text as aString. -
chunks— the body is theList<String>of individual chunks.
The mode can be overridden per exchange with the CamelAwsBedrockAgentRuntimeAgentStreamOutputMode header.
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.