DEV Community

Cover image for First Impressions with Strands Agents SDK 🧬
Laura Salinas for AWS

Posted on

First Impressions with Strands Agents SDK 🧬

It's been exactly 3 months since I last wrote about agents and the industry has certainly made leaps since then. With the release of more support for agentic workflows across CSPs (cloud service provider), this felt like the right time to dive into one of the options still warm on the press, Strands Agents SDK.

I first heard about Strands as I logged back into work after a week vacation in Japan. Talk about bleeding edge, I'm away for 7 days and suddenly there's a brand new open source SDK that's making a splash.

If you somehow missed this announcement last month, I highly recommend giving the official launch blog a read to get familiar.

The TLDR πŸ‘‰πŸΌ Strands Agents is an open source SDK that takes a model-driven approach to building and running AI agents in just a few lines of code (and seriously in <10 lines I'm up and running).

Best part yet? This isn't just a 'stay in your prototype and experiment' type of solution. Teams at AWS have already been using Strands Agents in stealth mode before the public release. In fact, if you've gotten your hands on Q CLI for an agentic coding experience, then you're already reaping the benefits of an AWS team that built and shipped with Strands Agents in just 3 weeks 🀯

With that background, I wanted to play around with Strands Agents to see how quickly I could get started and what my first impressions are so far. Let's go 🀘🏼

Setup

Pretty straightforward, in the documentation you can find instructions on installation.

I create a new python file in my local repository and create a virtual environment to install packages related to this project.

  • Core functionality using pip3 install strands-agents
  • Built in tools using pip3 install strands-agents-tools

⚠️ Note: I'm using AWS as the model provider to run Strands which means I've already set up AWS credentials and enabled model access. The default model provider for Strands is Amazon Bedrock and the default model is Claude 3.7 Sonnet in the US Oregon (us-west-2) region. I don't cover AWS CLI setup here, but check out the docs if you haven't done that first.

Creating your first agent

With setup and model provider access complete I can get started building my first agent.

From the Strands documentation I start my python file with the skeleton code needed (again this is <10 lines to get to basic use)

from strands import Agent

# Create an agent with default settings
agent = Agent()

# Ask the agent a question
agent("Tell me about agentic AI")
Enter fullscreen mode Exit fullscreen mode

Running this with python3 strands-agent.py and I see Strands goes to work using Claude 3.7 Sonnet to pose the query "Tell me about Agentic AI". We see a quick response in my terminal.

Image description

Now that I know things are working we can get a bit more creative.

Building complexity in agents

Let's say I want to create an agent that helps new pet parents find a dog that best meets their lifestyle. Maintaining the same idea as the example code above, we create an agent, dog_breed_helper, and use the following system prompt.

You are a dog breed expert specializing in helping new pet parents decide what breed meets their lifestyles. Your expertise covers dog behavior, dog training, basic veterinary care, and dog breed standards.

    When giving recommendations:
    1. Provide both benefits and challenges of owning that breed
    2. Give examples when necessary
    3. Avoid jargon, but indicate when complex concepts are important

Your goal is to help pet parents make an informed decision about their choice in a dog.
Enter fullscreen mode Exit fullscreen mode

⚠️ There's certainly room for improvement in this system prompt, but the point here is to experiment and show you how easy it is to contextualize and ground an agent.

To test this agent I use a query like "Which dog should I adopt as a first time owner if I have an office job m-f 9-5, like to hike on weekends and don't know much about training?"

I execute the file, python3 dog_breed_agent.py and the results are below.

Image description

Next, I want to test one of the capabilities of Strands Agents that allows me to take my dog helper agent to the next level. This capability is to integrate tools to extend my agent's own knowledge.

If you're not yet familiar with the term- "Tools" are what transform a basic conversational agent into a truly useful assistant that can interact with the world. In this example, I'll explore using the built-in tools provided by the Strands SDK. Tools allow my agent to interact with external systems, access data and manipulate its environment.

To learn more you can check out which built-in tools Strands offers to get started quickly.

For my small experiment today I want to enhance my agent by having it search for information on the web. I can use the built in http_request tool to do this.

To enable this tool use in my python application I add from strands_tools import http_requestand then add the function call to my system prompt tools=[http_request]. I change my query to reflect both items I need help with.

My updated python file looks like so:

from strands import Agent
from strands_tools import http_request

# Create a basic agent with a specialized system prompt
dog_breed_helper = Agent(
    system_prompt="""You are a dog breed expert specializing
    in helping new pet parents decide what breed meets their lifestyles. Your expertise
    covers dog behavior, dog training, basic veterinary care, and dog breed standards.

    When giving recommendations:
    1. Provide both benefits and challenges of owning that breed. 
    2. Only provide 3 recommendations at a time.
    3. Give examples when necessary
    4. Avoid jargon, but indicate when complex concepts are important

    Your goal is to help pet parents make an informed decision about their choice in a dog.
    """,
    tools=[http_request]
)

query= """
Answer these questions:
1. Which dog should I adopt as a first time owner if I have an office job m-f 9-5, like to hike on weekends and don't know much about training?
2. Search wikipedia for the top 5 most popular dog breeds of 2024
"""
response = dog_breed_helper(query)
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ What I notice when I execute the file is Strands automatically knows which tool(s) to invoke based on the context of our conversation. When I say search the web it knows it needs to call the http_request tool to answer the question. This behavior is really impressive and opens up a lot of room to make these agents more than just simple text generators.

⚠️ Note: I did run into some throttling limits when experimenting with the http_request tool. If your queries are hanging longer than a few seconds you may see an error like the one I had which indicates AWS usage for the ConverseStream API is at capacity.
"An error occurred (ThrottlingException) when calling the ConverseStream operation (reached max retries: 4): Too many tokens, please wait before trying again."
You can have Strands switch to another model by passing the model ID string directly. I tried Sonnet 3.5 by adding model="anthropic.claude-3-5-sonnet-20240620-v1:0" to my agent definition.

When executing correctly, the response I receive from my agent is the following:

Answering the first question
Image description

Answering the second question
Image description

Learnings

  • Creating an agent was easy and straightforward with functioning python app in <10 lines and <10min
  • Adding complexity to agents using Strands can also be done easily whether through pre-built tools or adding custom tools
  • Errors from model providers (in my case Amazon Bedrock) are still a challenge, make sure to understand your service/model quotas as you experiment
  • Be open to switching to another version of a model if responses are lagging or being throttled

Let me know in the comments what your use cases for Strands Agents could be and leave a πŸ¦„ if you made it this far!

Additional Resources πŸ“š

Top comments (4)

Collapse
 
nevodavid profile image
Nevo David

Pretty cool stuff, I love seeing walkthroughs that actually show what goes wrong too. Makes me wanna give it a spin myself.

Collapse
 
lausalin profile image
Laura Salinas

Yes πŸ™Œ No point in gate keeping when things aren't working like expected. Let me know what you end up building!

Collapse
 
astrodevil profile image
Astrodevil

I came across Strands Agents last week via GitHub. This overview is a good starting point for me, going to give it a try now!

Collapse
 
lausalin profile image
Laura Salinas

Thanks for giving it a read! Let me know what you end up building 😊