Building My First AI Agent with Strands Agents: Part 1 link
๐ฏ Objective
Give your agent the ability to fetch live data from the internet using the http_request tool. In this lab the agent calls the US National Weather Service API to answer a weather question.
๐ Background
Most useful agents need to reach out to external services. The http_request tool lets an agent make GET/POST/PUT/DELETE requests to any URL. The agent decides which URL to call, parses the response, and presents it in natural language.
๐ Key Concepts
| Concept | Description |
|---|---|
http_request |
Built-in Strands tool for making HTTP calls |
| System Prompt | Guides the agent on which APIs to use and how to interpret responses |
| API chaining | The agent may make multiple HTTP calls (e.g. get coordinates โ get forecast) |
โ๏ธ Prerequisites
- AWS credentials configured
- Internet connectivity (the agent calls
api.weather.gov) - Dependencies installed (
uv sync)
Lab 02 : Agentic ai with http_request tool
# This lab is to teach you about http_request tool
from strands import Agent
from strands.models.bedrock import BedrockModel
from strands_tools import file_read, file_write, http_request
# Configure the Bedrock model
bedrock_model = BedrockModel(
# Set your preferred model ID here (e.g., "global.amazon.nova-2-lite-v1:0")
model_id="<YOUR_MODEL_ID>",
region_name="eu-west-2",
temperature=0.3,
)
system_prompt = """
Weather Information
- You can also make HTTP requests to the National Weather Service API.
- Process and display weather forecast data for locations in the United States.
"""
# - When retrieving weather information, first get coordinates using https://api.weather.gov/points/{latitude},{longitude}, or
# https://api.weather.gov/points/{zipcode}, then use the returned forecast URL. You can make additional http requests as well.
# Create the agent with tools
local_agent = Agent(
system_prompt=system_prompt, # Define a system Prompt
model=bedrock_model,
tools=[http_request], # Add your custom tools here
)
local_agent("what is the weather in new york?")
โถ๏ธ How to Run
uv run labs/02-http-tools/agent.py
๐งช Exercises
-
Try a different city โ Change
"new york"to another US city and see if the agent resolves the correct API endpoint. -
Combine tools โ Add
file_writeso the agent saves the weather report to a file. - Non-US weather โ The NWS API only covers the US. Modify the system prompt to use a global weather API like OpenWeatherMap instead.
- Error handling โ Disconnect from the internet and observe how the agent reacts.
ALL LAB EXCERSIZE GitHub Notes
Top comments (1)
Part 3 logging and debugging
Next lab