DEV Community

Jamal
Jamal

Posted on

Lab 02 โ€” HTTP Tools Integration; Strands Agentic AI

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

  1. AWS credentials configured
  2. Internet connectivity (the agent calls api.weather.gov)
  3. 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?")

Enter fullscreen mode Exit fullscreen mode

โ–ถ๏ธ How to Run

uv run labs/02-http-tools/agent.py
Enter fullscreen mode Exit fullscreen mode

๐Ÿงช Exercises

  1. Try a different city โ€” Change "new york" to another US city and see if the agent resolves the correct API endpoint.
  2. Combine tools โ€” Add file_write so the agent saves the weather report to a file.
  3. Non-US weather โ€” The NWS API only covers the US. Modify the system prompt to use a global weather API like OpenWeatherMap instead.
  4. Error handling โ€” Disconnect from the internet and observe how the agent reacts.

ALL LAB EXCERSIZE GitHub Notes

๐Ÿ“š Further Reading

Top comments (1)

Collapse
 
d3vjamal profile image
Jamal

Part 3 logging and debugging
Next lab