Amazon Bedrock is a powerful service that allows developers to build, deploy, and manage AI agents with ease. These agents can be designed to perform a variety of tasks, from natural language processing to integrating with external APIs for real-time data retrieval. In this article, we will build an AI agent capable of performing real-time tasks, such as retrieving the current time in UTC format and calculating the sum of two numbers dynamically (Simulate the Agentic Behaviour to understand AWS Bedrock Action groups).
What is an AI Agent?
An AI agent is a system that perceives its environment, processes information, and takes actions to achieve specific goals. It operates autonomously or semi-autonomously, making decisions based on predefined rules, learned behaviours, or real-time data.
Examples of AI Agents
- *Chatbots *(e.g., ChatGPT, Google Gemini) — Understand and respond to user queries.
- Autonomous Vehicles (e.g., Tesla Autopilot) — Perceive surroundings and navigate.
- Trading Bots — Analyze market trends and execute trades.
- AI Assistants (e.g., Alexa, Siri) — Perform tasks based on voice commands.
- AI-powered Recommendation Systems — Suggest products, movies, or content based on user behaviour.
Before we begin, ensure you have the following:
- AWS Account: You need an active AWS account to access Amazon Bedrock.
- IAM Permissions: Ensure your IAM user has the necessary permissions to create and manage Bedrock agents.
- Basic Knowledge of APIs: Familiarity with REST APIs and how they work will be helpful.
- AWS CLI (Optional): While we will focus on the AWS Management Console, having the AWS CLI installed can be beneficial for advanced configurations.
Accessing Amazon Bedrock in the AWS Console
- Log in to the AWS Management Console: Navigate to AWS Console and log in with your credentials.
- Navigate to Amazon Bedrock:
- In the AWS Management Console, use the search bar at the top and type “Amazon Bedrock”.
- Click on the “Amazon Bedrock” service to open the Bedrock dashboard.
Creating a New Agent in Amazon Bedrock
1. Open the Agents Section:
- In the Amazon Bedrock dashboard, locate the “Agents” section in the left-hand navigation pane.
- Click on “Agents” to open the agents management page.
2. Testing Claude Ai Model (Foundational Model — AWS Bedrock)
AI models are trained on static datasets and do not have live internet access to fetch or learn new information in real time. Their knowledge is limited to what they were trained on, and they require fine-tuning or external APIs to access real-time data or creating an Ai Agent to achieve this real-time task.
3. Create a New Agent:
Click the “Create agent” button to start the process of creating a new AI agent.
- You will be prompted to provide a name for your agent. Enter a descriptive name, such as “demo-agent”.
- Optionally, you can add a description to provide more context about the agent’s purpose.
4. Configure the Agent:
After creation of Agent, Assign a predefined IAM role to your AWS Bedrock Agent for secure access, or create a new role with the necessary permissions.
Execution Role: The default selected option, “Create and use a new service role” will automatically generate a new role for the AWS Bedrock agent, granting the necessary execution permissions and policies — eliminating the need for manual setup.
- Base Model Selection: Select a base model from AWS Bedrock’s foundation models, such as Anthropic Claude, Amazon Titan, Meta Llama, or Stability AI, based on your specific use case.
- Instruction for Agent: Provide clear and structured instructions to ensure your AWS Bedrock Agent operates efficiently, including task definitions, context, and expected output formats. Optimize its performance by specifying guidelines for accuracy, error handling, and response quality, enabling the agent to function like a pro with minimal manual intervention.
Select “Save and Exit” to store the AWS Bedrock Agent’s basic configurations. This action will automatically generate the necessary IAM roles and policies, ensuring the agent has the required permissions to access AWS Bedrock services seamlessly.
Select “Edit in Agent Builder” to review and enhance your AWS Bedrock Agent by configuring additional settings such as Lambda functions, Action Groups, Action Group Invocation, and Action Group Functions. This allows you to fine-tune the agent’s capabilities and ensure seamless execution of tasks.
Action Groups: Allow your agent to execute specific tasks by integrating with external AWS services or APIs. These groups define what actions the agent can take.
Adding Action Group: Allow your agent to execute specific tasks by integrating with external AWS services or APIs. These groups define what actions the agent can take.
Action Group Invocation: You can create a Lambda function for an AWS Bedrock Action Group to seamlessly invoke custom actions with just a few easy clicks. This enables your Bedrock Agent to execute tailored workflows, integrate with external services, and enhance automation without complex configurations. ❤️
Action group function 1: To enable time capability in real-time, you need to create an AWS Lambda Function for “get_time” Action Group to be invoked by this demo-agent against an incoming request using Lambda function trigger.
Action group function 2: Adding a capability to add two numbers, you need to create a Action Group Function to be invoked by a demo-agent against a user incoming request. Let’s create an Action Group Function so that it will automatically generate an AWS Lambda Function for “add_two_numbers” Action Group. (However. Normal Model can perform this maths operation, but this is only for clarifying how agentic Ai works behind the scenes bu creating action groups)
Action group function 2 (Parameters): To enable the “add_two_numbers” action, the agent needs two numeric parameters. Let’s configure the parameters so that this function can get the required parameters from user request coming to this demo-agent.
Once done, Wait for a while so that demo-agent can configure the basic things and create Step Code Generation for Lambda, IAM Roles, Permissions and necessary policies for AWS Bedrock Agent to work efficiently …
After Creation, We can view our all-in-one created Lambda with action groups we defined above with parameter and invocation mechanism.
To enhance your auto-created AWS Lambda function for the “get_time” Action Group and ensure it returns the current time in UTC format.
def get_time():
return datetime.datetime.utcnow().strftime("%H:%M:%S")
To enhance your auto-created AWS Lambda function and enable it to return the sum of two numbers, update the function as follows:
def add_two_numbers(number_1, number_2):
return number_1 + number_2
Prepare: After deploying your AWS Bedrock Agent, the preparation phase ensures the agent is ready for testing and validation. This step involves initializing resources, verifying configurations, and checking connectivity with integrated services like Lambda functions, Action Groups, and IAM policies. Conduct test runs to confirm the agent processes requests accurately and performs as expected before full deployment. 🚀
Awesome! 🚀 Your AWS Bedrock Agent is now successfully returning the current UTC time and computing the sum of two numbers via the incoming request to demo-agent
- Show Trace: After deploying your AWS Bedrock Agent, the trace feature helps in debugging and validating its execution flow. It enables you to monitor the agent’s responses, track invoked actions (like fetching time or summing numbers), and inspect logs for any errors or unexpected behaviour.
- Use this step to ensure the agent is correctly handling requests, invoking Lambda functions, and returning accurate results.
Show Trace: Let’s analyze how our AWS Bedrock Agent processes inputs and makes decisions. This step involves tracking the agent’s execution flow, including:
- Input Analysis: How the agent interprets user queries (e.g., detecting whether the request is for time or sum calculation).
- Decision Making: How it determines the appropriate Action Group and selects the correct Lambda function.
- Function Invocation: Monitoring how the agent interacts with AWS Lambda to retrieve results.
- Response Generation: Ensuring the agent structures responses correctly and returns accurate data.
Top comments (0)