DEV Community

Mindy Jen
Mindy Jen

Posted on

Get Your Hands Dirty - AgentCore - Set Up

Overview: What are Strands Agents?

Strands Agents is a Python framework designed to simplify the creation of AI agents with built-in tool integration, conversation memory, and multi-model flexibility. It abstracts the complex "request-response-tool" loop, allowing developers to focus on agent behavior rather than wiring API calls. The framework natively supports models in Amazon Bedrock (like Nova Pro) and includes pre-built tools such as calculators and web search.

Step 1: Setting Up Your Environment

To get started, you need to install the core packages and configure your AWS environment. The framework uses boto3 to automatically detect your region and set the appropriate Model ID for models like Nova Pro.

# Install required packages
# %pip install -q strands-agents strands-agents-tools rich

import boto3
from strands import Agent
from strands.models import BedrockModel

# Automatically detect region and set Nova Pro Model ID
region = boto3.session.Session().region_name
NOVA_PRO_MODEL_ID = "us.amazon.nova-pro-v1:0" 
if region.startswith("eu"):
    NOVA_PRO_MODEL_ID = "eu.amazon.nova-pro-v1:0"

print(f"Using Model: {NOVA_PRO_MODEL_ID}")
Enter fullscreen mode Exit fullscreen mode

Step 2: Creating an Agent with Built-in Tools

You can instantiate an agent by defining its model, a system prompt, and a list of tools. In this example, we integrate a built-in calculator tool from the strands_tools package.

from strands_tools import calculator

# Create an agent with a built-in calculator
agent = Agent(
    model=BedrockModel(model_id=NOVA_PRO_MODEL_ID),
    system_prompt="You are a helpful assistant that provides concise responses.",
    tools=[calculator],
)

# The agent automatically decides to use the calculator tool to answer
agent("What is the area of a circle with radius 8.26cm?")
Enter fullscreen mode Exit fullscreen mode

Step 3: Building and Integrating Custom Tools

Strands Agents allows you to turn any Python function into a tool using the @tool decorator. This allows the agent to interact with custom logic or external APIs seamlessly.

from strands import tool

# Define a custom tool with a docstring (used by the LLM to understand the tool)
@tool
def weather(city: str) -> str:
    """Get weather information for a city"""
    return f"Weather for {city}: Sunny, 35°C" # Dummy result for demo

# Update agent to use both custom and built-in tools
agent = Agent(
    model=BedrockModel(model_id=NOVA_PRO_MODEL_ID),
    system_prompt="You are a helpful assistant.",
    tools=[weather, calculator],
)

agent("How is the weather in HK? Return temperature in Fahrenheit.")
Enter fullscreen mode Exit fullscreen mode

Step 4: Understanding the Agent Loop and Memory

The framework manages a "Sliding Window" conversation memory, allowing agents to remember previous interactions within a session. You can also inspect the "Agent Loop"—the internal cycle of reasoning, tool execution, and response generation—using tools like the rich library.

# Test built-in conversation memory
agent("What did we talk about just now?") 

# Examine the internal loop metrics
print(f"Number of reasoning cycles: {agent.event_loop_metrics.cycle_count}")
Enter fullscreen mode Exit fullscreen mode

Key Takeaway: Strands Agents provides an autonomous cycle of reasoning: it receives input, decides if tools are needed, executes them, and iterates until a final response is generated. This makes it an ideal foundation for complex, multi-step AI applications.

Top comments (0)