Voiced by Amazon Polly |
Overview of Strands Agents
Strands Agents is an open-source SDK from AWS that simplifies the development of AI agents through a model-driven approach. It allows you to define a task-specific prompt and tools the agent can use, and relies on foundation models like Claude, LLaMA, or models available in Amazon Bedrock.
With Strands, developers can create intelligent agents that plan, reason, and reflect while completing tasks using minimal code. It is already used internally by several AWS services such as Amazon Q Developer and AWS Glue.
Drive Business Growth with AWS's Machine Learning Solutions
- Scalable
- Cost-effective
- User-friendly
Prerequisites
Before setting up your Strands Agent, ensure the following:
- AWS CLI installed and configured
- Active AWS account with Amazon Bedrock access
- Python 3.10+
- A virtual environment manager (e.g. venv)
Create Project Environment
Set up a Python virtual environment and install required packages over the terminal:
1 2 3 4 5 |
<em>python3 -m venv venv</em> <em>source venv/bin/activate</em> <em>pip install strands-agents strands-agents-tools </em> |
4) Configure AWS Access
Make sure AWS credentials are configured properly using:
1 |
<em>aws configure </em> |
Build and Run a Basic Strands Agent
In agent.py, define your agent:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<em>import os</em> <em>import logging</em> <em># CRITICAL: Set AWS environment variables BEFORE importing strands</em> <em>os.environ['AWS_PROFILE'] = 'profile_name'</em> <em>os.environ['AWS_REGION'] = 'us-east-1' </em> <em> </em> <em>from strands import Agent</em> <em>from strands_tools import calculator, current_time, use_aws</em> <em># Create the agent with tools and specify the model</em> <em>agent = Agent(</em> <em> tools=[calculator, current_time,use_aws],</em> <em> model="anthropic.claude-3-5-sonnet-20240620-v1:0" # Specify your model</em> <em>)</em> <em> </em> <em> </em> <em># Define a message to test the agent</em> <em>message = """</em> <em>I have 3 requests:</em> |
-
1<em> What is 7 * 8?</em>
-
1<em> What is the time right now in india?</em>
-
1<em> list count of s3 buckets in my aws account?</em>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<em>"""</em> <em># Run the agent and handle any errors</em> <em>if __name__ == "__main__":</em> <em> try:</em> <em> print("Running the agent...")</em> <em> response = agent(message)</em> <em> print("\nAgent Response:")</em> <em> print(response)</em> <em> except Exception as e:</em> <em> print(f"Error: {e}")</em> <em> import traceback</em> <em> traceback.print_exc()</em> |
Run your agent on the terminal:
1 |
<em>Python agent.py</em> |
Output:
Handle Common Errors
AccessDeniedException for Model ID
- Make sure you’re using a region where your AWS account has access to the Bedrock model.
- Double-check IAM permissions for Bedrock.
Region Configuration
- Ensure AWS_REGION is exported correctly before importing the strands module.
Conditional Write Error
- If you encounter an error like “pre-condition failed”, verify if you’re trying to overwrite an existing object in S3 via a conditional call — this doesn’t apply directly to Strands, but could arise if tools use S3.
Clean Up Resources
Once testing is done:
- Deactivate Bedrock Model access enabled
- Deactivate and remove your virtual environmentml
AWS Media Services Excellence: Unleash Potential with Cloud Consulting
- Embrace Innovation!
- Transform your Media Capabilities
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.

WRITTEN BY Kamlesh N
Comments