The purpose of this repository is to assist in development of Amazon Bedrock Agentcore support in Koog framework. The project is not intended for production usage. This project was created using the Ktor Project Generator.
- A computer with arm64 architecture (e.g. Apple M1)
- Java 21 or higher
- Docker
- Gradle 8.14
- AWS credentials to try Agent Memory on Bedrock Agentcore Memory and to deploy the application to Agentcore Runtime
- Created Agentcore Memory: short-term and long-term memory with a "Semantic memory" built-in extraction strategy
- Set your Agentcore Memory settings in
application.yaml: memoryId and memoryStrategyId (make sure to copy these ids after a successful creation) - Set your AWS credentials:
export AWS_ACCESS_KEY_ID=your_aws_key_idandexport AWS_SECRET_ACCESS_KEY=your_aws_secret_key - Switch to the following executor in the KoogAgentService
// promptExecutor = simpleBedrockExecutor(System.getenv("AWS_ACCESS_KEY_ID"), System.getenv("AWS_SECRET_ACCESS_KEY")),//for local testing- Switch to
EnvironmentCredentialsProvider()in KoogAgentService - Run:
./gradlew run
Application starts on http://localhost:8080.
Send a POST request to interact with the agent:
Endpoint: POST http://localhost:8080/invocations
Content-Type: application/json
Request 1:
{
"prompt": "My favorite band is Radiohead"
}Sample response 1:
{
"response": "That's awesome! Radiohead is an incredibly talented band with a unique sound and a huge following.<...>"
}Note: it might be better to repeat the request just to make sure it is extracted from short-term memory to long-term memory.
Request 2:
{
"prompt": "What is the user's favorite band?"
}Sample response 2:
{
"response": "Based on the information you provided, the user's favorite band is Radiohead.<...>"
}- Set your AWS credentials:
export AWS_ACCESS_KEY_ID=your_aws_key_idandexport AWS_SECRET_ACCESS_KEY=your_aws_secret_key - Build the application
- Customize the file
dockerize.shwith your AWS account ID - Run the commands from
dockerize.shone by one - In the AWS console in Agentcore Runtime, click "Host agent" and choose "Import docker image from Amazon ECR" with the image that you have just uploaded.
- In the AWS console in Agentcore Runtime, invoke the agent in "Agent sandbox"
Here's a list of features included in this project:
| Name | Description |
|---|---|
| Routing | Provides a structured routing DSL |
| Server-Sent Events (SSE) | Support for server push events |
| Koog | Integrate LLMs and build AI Agents with Koog framework |
| Content Negotiation | Provides automatic content conversion according to Content-Type and Accept headers |
| kotlinx.serialization | Handles JSON serialization using kotlinx.serialization library |
To build or run the project, use one of the following tasks:
| Task | Description |
|---|---|
./gradlew test |
Run the tests |
./gradlew build |
Build everything |
./gradlew buildFatJar |
Build an executable JAR of the server with all dependencies included |
./gradlew buildImage |
Build the docker image to use with the fat JAR |
./gradlew publishImageToLocalRegistry |
Publish the docker image locally |
./gradlew run |
Run the server |
./gradlew runDocker |
Run using the local docker image |
If the server starts successfully, you'll see the following output:
2024-12-04 14:32:45.584 [main] INFO Application - Application started in 0.303 seconds.
2024-12-04 14:32:45.682 [main] INFO Application - Responding at http://0.0.0.0:8080