Welcome to this guide on using Amazon Bedrock Agents to simplify library management! This step-by-step tutorial will show you how to set up and use these agents to automate tasks, enhance library operations, and build a smart knowledge base. Discover how AI can make your library more efficient and effective. Ready to transform your library? Letβs get started!

You can find all the magic PDFs and code goodies in my GitHub treasure chest π©β¨:
GitHub - RISING-CODER777/awsberock_agents
π Synopsis
In this guide, weβll cover.
- π Prerequisites
- ποΈIntroduction to Amazon Bedrock Agents
- π οΈ Setting Up Your Environment
- π Building a Knowledge Base
- π§ Creating Action Groups
- π§ͺ Testing and Troubleshooting
- β Unsubscribing to Avoid Costs
- π Conclusion
π Prerequisites
Before we dive into the fun, make sure you have the following:
- π An AWS Subscription. If you donβt have an AWS subscription, you can create a free account.
- π Access to Claude v2. and Titan Embeddings G1 β Text v1.2. from Amazon Bedrock.
- π Familiarity with AWS Lambda, S3, and IAM.
ποΈIntroduction
Amazon Bedrock Agents provides a framework for automating tasks and responding to queries based on library data. Key components include.
- Foundation Model: The AI model that processes and interprets user inputs, making sense of queries related to library inventory.
- Action Groups: Defined actions performed by AWS Lambda functions and described using OpenAPI schemas. They handle tasks like retrieving book details or updating inventory.
- Knowledge Bases: Store library data in vector format for efficient search and retrieval. They help the agent provide accurate and contextual responses.
![Store library data]()
Agent Workflow
![Agent Workflow]()
- Contextualize User Input: Validate and process user requests to understand their needs.
- Generate Orchestration Prompt: Create a detailed prompt using user input and metadata.
- Execute Actions: Based on the prompt, perform tasks such as,
- Retrieving information
- Updating records
- Calling APIs or searching databases
- Generate Output: Produce the final response, which may include further actions or queries.
π οΈ Setting Up Your Environment
Follow these steps to create and configure a Bedrock Agent tailored for library inventory.
Create a Bedrock Agent
- In the Amazon Bedrock dashboard, look for Builder tools in the left navigation pane.
![Builder tools]()
- Create Agent: Click on βCreate Agent,β give it a name (for example, βAgent-LibraryManagementβ), and choose the foundation model as Anthropic β Claude v2.
![Create Agent]()
![Select Model]()
- Provide Instructions: Add instructions like βYou are a helpful agent that manages book catalog inquiries, including book details, stock levels, prices, and availability.β
![Provide Instructions]()
- Click Create Agent.
- Letβs set aside action groups and knowledge bases for the time being.
Initial Testing
- Your agent may initially respond with βSorry, I donβt have enough informationβ as action groups and knowledge bases are not yet configured.
![Initial Testing]()
π Building a Knowledge Base
![Knowledge Base]()
Setting up a knowledge base is crucial for providing accurate responses. Hereβs how to configure it.
Upload Data
Create an S3 Bucket
- Go to the S3 section from the Services menu.
- Click βCreate bucketβ.
- Enter a unique bucket name (e.g., βlibrarycatalog-kbβ).
- Choose your preferred AWS Region and configure other settings as needed.
![AWS Region]()
- Click βCreate bucketβ.
Upload Files
- Go to your newly created bucket in the S3 dashboard.
- Click βUploadβ.
- Drag and drop your CSV and PDF files, or click βAdd filesβ to select them.
- Click βUploadβ to transfer your files to the S3 bucket.
![Upload]()
File Details
- CSV File: Should contain fields such as Book ID, Title, Author, Genre, ISBN, and Availability.
- PDF File: This can include detailed descriptions or additional information about the books.
Create a Knowledge Base
Access Knowledge Base Menu.
- In the AWS Console, go to the Amazon Bedrock section.
- Navigate to Builder tools and click on βKnowledge Baseβ.
![Amazon Bedrock section]()
Configure Your Knowledge Base
- Name Your Knowledge Base: Enter a name like βknowledge-base-library-catalogβ.
![Configure Your Base]()
- Data Source Name: Enter a name for your data source.
![Data Source Name]()
- Browse for S3 URI: Click βBrowseβ to locate and select the S3 URI for your bucket (e.g., s3://librarycatlog-kb).
![Browse]()
- Choose Embedding Model: Select Titan Embeddings G1 β Text v1.2.
![Embedding Model]()
- Vector Database: Choose Quick Create a vector store β Recommended.
![Vector Database]()
- Click βCreateβ to set up the knowledge base.
Sync Knowledge Base
AWS will convert the text from your files into vector embeddings for efficient retrieval. This process ensures that your knowledge base is ready for quick and accurate responses.
In the data source, click βSyncβ to start the process.
![Sync]()
Verify Vector Store
Check OpenSearch Dashboard
- In the AWS Console, navigate to OpenSearch Service.
- Go to the Dashboard: Verify that the collections and indexes related to your knowledge base have been created and are functioning correctly.
![OpenSearch Service]()
![Indexes]()
Set Up and Test an Agent
Set Up
- Navigate to Agent Builder.
- Go to Knowledge Bases and click βAddβ.
![Add]()
- Select the knowledge base you created (e.g., βknowledge-base-library-catlogβ).
- Enter the following instruction: βThis knowledge base contains a list of books available in the library. Each book has attributes such as BookID, Title, Author, Genre, Publication Year, ISBN, Available Copies, and Price.β
![BookID]()
- Click βPrepareβ.
Note. Amazon Bedrock does not allow knowledge-based creation with the root account. Create an IAM user with the right permissions and enable AWS Management Console access for managing knowledge bases and related resources.
Test
- After preparing the agent, click βTestβ.
- Enter queries to ensure the agent retrieves accurate information based on the knowledge base.
![Test]()
![Show tree]()
π§ Creating Action Groups
Action groups allow your agent to perform specific actions. Hereβs how to set them up,
Create a Lambda Function
- Go to the AWS Lambda section in the AWS Management Console.
- Click βCreate functionβ.
- Set the Function Name to βLibraryInventoryFunctionβ.
- Choose Python 3.12 as the Runtime.
- Select x86_64 for the Architecture.
![Basic information]()
- Click βCreate functionβ.
- Navigate to the Code section of your Lambda function.
- Copy and paste the following code into the editor:
This Lambda function handles two API paths: /GetBooksInventory and /RestockBook. For /GetBooksInventory, it returns a hardcoded list of book details. For /RestockBook, it provides a success message. The function formats responses into JSON and handles different API paths to return appropriate data.
Save and deploy your Lambda function code.
![Lambda function code]()
Configure Lambda Function Permissions
- Navigate to the Lambda functionβs Configurations section.
- Select Permissions.
- Under Resource-based policy statements, click Add permissions.
- In the Edit Policy Statement section
- Choose AWS Service: Select Other AWS services.
- Statement ID: Enter an identifier, e.g., st-001.
- Principal: Enter bedrock.amazonaws.com.
- Source ARN: Go to the Bedrock Agent dashboard, copy the Agent ARN, and paste it here.
- Action: Select lambda: InvokeFunction.
- Click Save to apply the changes.
![Save]()
Add Action Group to Agent
- Navigate to the Action Group in the Agent Details section.
![Agent Details section]()
- Click on Add.
- Choose the action group type as Defined with API Schemas.
- For Action Group Invocation, select Select an existing Lambda function.
- In Select Lambda Function, choose LibraryCatlogFunction from the list.
![Select Lambda Function]()
- For Select API Schema, choose Define with inline OpenAPI Schema Editor.
- Paste the following schema.
This schema defines the API paths for managing book inventory. The /GetBooksInventory endpoint retrieves book details, while the /RestockBook endpoint allows placing restock orders.
Click on Add.
π§ͺ Testing and Troubleshooting
Ensure your agent is functioning correctly and troubleshoot any issues.
Test Your Agent
- Run Prompts: Test the agent with various prompts to verify its responses.
- For example, ask to Get all book inventory.
![Run Prompts]()
- Restock the book with ID B003.
![Restock]()
- Restock 3 copies of the book with ID B001.
![Restock 3 copies]()
Troubleshoot Errors
- Check for accurate information: If errors like βunknown API pathβ occur, verify the details provided by the agent.
![Troubleshoot Errors]()
- Inspect CloudWatch Logs: Go to CloudWatch, then Log Groups and Log Streams.
![Inspect CloudWatch Logs]()
- Verify API Endpoint Configuration: Find the API path in the relevant log stream and ensure it matches the Lambda function code.
![Verify API Endpoint]()
- In this case, verify that the /GetBooksInventory endpoint is correctly configured.
![Correctly configured]()
Some additional troubleshooting tips
- Check Permissions and Authentication: Verify that proper permissions and authentication are in place.
- Validate Request Format: Ensure the request format matches the expected format for the API.
- Confirm Knowledge Base Setup: Verify that the knowledge base and API integration are correctly set up.
Create an Alias
- Alias Creation: In the agent details page, create an alias for versioning and testing specific versions of your agent.
![Alias Creation]()
- Test Alias: Test the alias just like you would with a working draft to ensure it behaves as expected.
β Unsubscribing to Avoid Costs
![Avoid Costs]()
Keep your costs in check by deleting unused resources and regularly reviewing your AWS account. To avoid extra charges, cancel any unneeded subscriptions in Claude v2 via AWS Marketplace.
Conclusion
You did it! π With Amazon Bedrock Agents, youβve taken library management to the next level. By setting up knowledge bases and action groups, youβre now ready to automate tasks and impress users with smart responses.
Keep experimenting and tweaking to perfect your setup. Dive into the world of Amazon Bedrock Agents and see how much more efficient and fun managing your library can be. Happy building! π
![Completed]()
If you enjoyed this blog, donβt forget to share it with your friends and colleagues.
Follow me on LinkedIn! Did you enjoy this guide? Feel free to clap and comment below!
Also any comment on anything missing or not right is very welcome. Long live the AWS Learning community π€!
Attributes and References
- Amazon Bedrock Agents: Create and Configure AWS Documentation
- Amazon Bedrock Agents: How They Work AWS Documentation
- Amazon Bedrock Knowledge Base: Create AWS Documentation
- Amazon Bedrock Knowledge Base: How It Works AWS Documentation