AWS Bedrock Agent Runtime Sink
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Answers the question in each message from the documents of an Amazon Bedrock knowledge base, or finds the passages of the documents that match it, or passes it to a Bedrock agent.
Use it to build a question-and-answer service or a chatbot over your own documents, such as manuals, policies or FAQs, loaded into a Bedrock knowledge base. Set operation to retrieve to get only the passages that match the question, for example to show them as search results or to give them to a model of your own. Set it to invokeAgent to ask a Bedrock agent that you have set up in the Bedrock console. To load new documents into the knowledge base, use aws-bedrock-agent-sink; to call a model without a knowledge base, use aws-bedrock-text-sink.
Input: the body is the question, as text. The optional CamelAwsBedrockAgentRuntimeSessionId header continues an earlier conversation, with retrieveAndGenerate and invokeAgent: set it to the session ID of an earlier answer.
Output: when it is used inside a route, the body afterwards depends on operation. With retrieveAndGenerate, the default, and with invokeAgent, it is the answer, as text. The CamelAwsBedrockAgentRuntimeSessionId header holds the ID of the session, and the CamelAwsBedrockAgentRuntimeCitations header the passages of the documents the answer is based on, as objects of the AWS SDK for Java. With retrieve, the body is a List of the passages found, each an object of the AWS SDK for Java with the text of the passage (content.text), its score and the location of its document. The CamelAwsBedrockAgentRuntimeRetrievedResults header holds the same List.
Good to know: retrieveAndGenerate needs modelId and knowledgeBaseId, retrieve needs knowledgeBaseId, and invokeAgent needs agentId and agentAliasId; without them, retrieve and invokeAgent fail before they call Bedrock. The passages from retrieve are not JSON, and turned into JSON as they are, each is an empty object: take the parts you need in the next step, such as $\{body[0].content.text} in a Simple expression. With invokeAgent and no session ID, each message starts a new session. To reach AWS through an HTTP proxy, set proxyHost and proxyPort, and set proxyProtocol to HTTP for a proxy that takes plain HTTP, such as Squid. Headers that start with CamelAwsBedrock, except CamelAwsBedrockAgentRuntimeSessionId, are removed from the message first, so they cannot change what the Kamelet does.
Configuration Options
The following table summarizes the configuration options available for the aws-bedrock-agent-runtime-sink Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
AWS Region | Required The AWS region of the knowledge base, such as Enum values: * us-east-1 * us-west-1 | string | us-east-1 | ||
Access Key | The access key ID of an IAM user, which AWS gives when you create an access key for the user (in the AWS console: IAM, Users, Security credentials). Use it together with | string | |||
Agent Alias ID | The ID of the alias of the agent in | string | TSTALIASID | ||
Agent ID | The ID of the Bedrock agent to ask, a code of 10 letters and digits shown in the Bedrock console. Required when | string | KX7Q2M9WZB | ||
Knowledge Base ID | The ID of the knowledge base to search, a code of 10 letters and digits shown in the Bedrock console. Required when | string | AB12CD34EF | ||
Model ID | The ID of the Bedrock model that writes the answers from the parts of the documents that were found. It must be available in the region of the knowledge base. Required when Enum values: * anthropic.claude-instant-v1 * anthropic.claude-v2 * anthropic.claude-v2:1 * anthropic.claude-3-sonnet-20240229-v1:0 | string | |||
Number of Results | The most passages to give for each question. Only used when | integer | 10 | ||
Operation | What to do with the question. Enum values: * retrieveAndGenerate * retrieve * invokeAgent | string | retrieveAndGenerate | ||
Endpoint Overwrite | If true, the requests go to the address in | boolean | false | ||
Profile Credentials Name | The name of the profile to use from the AWS credentials file. Only used when | string | |||
Proxy Host | The host name or IP address of an HTTP proxy to send the calls to AWS through, such as the proxy of a company network. Used only together with | string | proxy.example.com | ||
Proxy Port | The port of the proxy in | integer | 3128 | ||
Proxy Protocol | How to talk to the proxy itself: Enum values: * HTTP * HTTPS | string | HTTP | ||
Search Type | How to search the knowledge base for the passages: Enum values: * HYBRID * SEMANTIC | string | |||
Secret Key | The secret access key that goes with | string | |||
Session Token | The session token of temporary credentials, which AWS gives together with their access key and secret key. Only used when | string | |||
Overwrite Endpoint URI | The address to send the requests to instead of the usual AWS address, such as | string | http://localhost:4566 | ||
Default Credentials Provider | If true, the credentials are found the way the AWS SDK finds them: from the | boolean | false | ||
Profile Credentials Provider | If true, the credentials are read from a profile of the AWS credentials file ( | boolean | false | ||
Session Credentials | If true, it logs in with temporary credentials, such as those of an assumed IAM role: | boolean | false |
Dependencies
At runtime, the aws-bedrock-agent-runtime-sink Kamelet relies upon the presence of the following dependencies:
-
camel:aws-bedrock
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:aws-bedrock-agent-runtime-sink" You can now run it directly through the following command
camel run route.yaml AWS Bedrock Agent Runtime Sink Kamelet Description
Authentication methods
In this Kamelet you can avoid using 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 can also use the Profile Credentials Provider, by setting the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of access key/secret key or default credentials provider could be used
For more information, see the AWS credentials documentation
Through an HTTP Proxy
Where AWS can be reached only through an HTTP proxy, as in many company networks, set proxyHost and proxyPort to the proxy. proxyProtocol is how the Kamelet talks to the proxy itself, not to AWS: it is HTTPS when it is not set, so set it to HTTP for a proxy that takes plain HTTP, such as Squid. The calls to AWS stay encrypted, as the proxy only passes them on. The Kamelet has no option for a proxy user or password.
The step that sends to the Kamelet, in a route:
- to:
uri: "kamelet:aws-bedrock-agent-runtime-sink"
parameters:
modelId: "anthropic.claude-v2"
knowledgeBaseId: "AB12CD34EF"
region: "eu-west-1"
useDefaultCredentialsProvider: true
proxyHost: "proxy.example.com"
proxyPort: 3128
proxyProtocol: "HTTP" Operations
operation chooses what the Kamelet does with the question in the body:
operation | What it does | Options it needs |
|---|---|---|
| Finds the passages that match the question in the knowledge base, and has the model write the answer from them. The body afterwards is the answer, as text. |
|
| Only finds the passages, without an answer. The body afterwards is a List of the passages, each with its text ( |
|
| Sends the question to a Bedrock agent, which answers it with its own instructions, knowledge bases and actions. The body afterwards is the answer, as text. |
|
The passages from retrieve are objects of the AWS SDK for Java, not JSON: turned into JSON as they are, each is an empty object. Take the parts you need in the next step. For example, to keep the text of the first passage:
- to:
uri: "kamelet:aws-bedrock-agent-runtime-sink"
parameters:
operation: "retrieve"
knowledgeBaseId: "AB12CD34EF"
numberOfResults: 3
searchType: "HYBRID"
region: "us-east-1"
useDefaultCredentialsProvider: true
- setBody:
simple: "$\{body[0].content.text}" To ask an agent, and continue the conversation with the session ID of the answer:
- to:
uri: "kamelet:aws-bedrock-agent-runtime-sink"
parameters:
operation: "invokeAgent"
agentId: "KX7Q2M9WZB"
agentAliasId: "TSTALIASID"
region: "us-east-1"
useDefaultCredentialsProvider: true Without the CamelAwsBedrockAgentRuntimeSessionId header, each message starts a new session, and the header holds its ID afterwards. Send that ID in the header with the next question to continue the same conversation.