Skip to content

asultani91/agentic-weather-assistant-bedrock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β˜€οΈ Agentic AI Weather Assistant: Building Blocks with Amazon Bedrock

A beginner-friendly (Level 100) hands-on workshop demonstrating how to build Agentic AI from scratch using pure Python and AWS SDKβ€”no complex frameworks required. In just one hour, learn what makes AI "agentic" by creating an intelligent weather assistant that thinks, plans, acts, and responds autonomously.

Workshop Type: Hands-on, code-from-scratch approach Duration: ~1 hour Target Audience: Beginners to AI and AWS Prerequisites: Basic Python knowledge, AWS account Region: US West (Oregon) β€” us-west-2


🎯 What I Built

An AI agent using pure Python and AWS SDK that:

Capability Implementation
🧠 Thinks Interfaces with Claude 4.5 Sonnet through Amazon Bedrock API
πŸ”§ Acts Makes HTTP requests to National Weather Service API using Python's subprocess
πŸ“Š Processes Handles JSON data with native Python data structures
πŸ’¬ Responds Communicates via command-line and Streamlit web interfaces

🌟 Key Features

Intelligent Location Handling

The agent accepts multiple location formats:

  • City names: "Seattle", "New York City"
  • ZIP codes: "90210", "10001"
  • Coordinates: "47.6062,-122.3321"
  • Descriptions: "National park near Homestead in Florida"
  • Reasoning queries: "Largest city in California"

Two-Step API Orchestration

  1. Points API β†’ Converts location to NWS forecast office coordinates
  2. Forecast API β†’ Retrieves detailed weather data for that grid

Dual Interface

  • Command-Line Interface (weather_agent_cli.py) β€” Quick terminal-based queries
  • Web Application (weather_agent_web.py) β€” Interactive Streamlit UI with real-time progress tracking

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Input  β”‚ β†’ Location (city, ZIP, coordinates, descriptions)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 🧠 Claude 4.5 Sonnetβ”‚ β†’ AI analyzes location and plans API calls
β”‚  (Amazon Bedrock)   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ“ Points API URL Generated        β”‚
β”‚ https://api.weather.gov/points/... β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 🌐 Execute Points   β”‚ β†’ curl command to NWS
β”‚    API Call         β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ“‹ Points Response  β”‚ β†’ Extract forecast URL from JSON
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 🌀️ Execute Forecastβ”‚ β†’ curl to gridpoints/SEW/124,67/forecast
β”‚    API Call         β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ“Š Raw JSON Data    β”‚ β†’ Temperature, wind, conditions
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 🧠 Claude Processes β”‚ β†’ Convert raw data to summary
β”‚  (Amazon Bedrock)   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ’¬ Human-Readable   β”‚ β†’ "Today: Partly cloudy, 72Β°F"
β”‚    Response         β”‚    "Wind: West 5-10 mph"
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”‘ What Makes This "Agentic"?

Characteristic Implementation
πŸ€– Autonomy β€’ Interprets location descriptions
β€’ Generates correct API URLs
β€’ Decides relevant weather info
β€’ Handles errors independently
⚑ Reactivity β€’ Adapts to city names, ZIP codes, coordinates
β€’ Processes varying API structures
β€’ Handles network issues
β€’ Works with incomplete data
🎯 Proactivity β€’ Plans complete API strategies
β€’ Takes initiative to call APIs
β€’ Analyzes weather insights
β€’ Presents user-friendly results

πŸ’» Code Structure

Core Functions

1. Amazon Bedrock Connection

def call_claude_sonnet(prompt):
    """Connect to Claude 4.5 Sonnet - the agent's 'brain'"""
    bedrock = boto3.client(
        service_name='bedrock-runtime',
        region_name='us-west-2'
    )
    
    response = bedrock.converse(
        modelId='us.anthropic.claude-sonnet-4-5-20250929-v1:0',
        messages=[{
            "role": "user",
            "content": [{"text": prompt}]
        }],
        inferenceConfig={
            "maxTokens": 2000,
            "temperature": 0.7
        }
    )
    
    return True, response['output']['message']['content'][0]['text']

2. API Execution

def execute_curl_command(url):
    """Agent's 'hands' - executes HTTP requests"""
    result = subprocess.run(
        ['curl', '-s', url],
        capture_output=True,
        text=True,
        timeout=30
    )
    return True, result.stdout

3. AI Planning

def generate_weather_api_calls(location):
    """Agent's 'planning brain' - figures out right API calls"""
    prompt = f"""
    You are an expert at working with the National Weather Service API.
    
    Generate the NWS Points API URL for "{location}".
    
    Instructions:
    1. Determine approximate lat/lon coordinates
    2. Generate: https://api.weather.gov/points/{{lat}},{{lon}}
    
    Return ONLY the complete Points API URL.
    """
    
    success, response = call_claude_sonnet(prompt)
    api_url = response.strip()
    return True, [api_url]

4. Data Processing

def process_weather_response(raw_json, location):
    """Agent's 'analysis brain' - makes sense of complex data"""
    prompt = f"""
    Convert this raw NWS forecast data for "{location}" into a 
    clear, helpful weather summary.
    
    Raw Data: {raw_json}
    
    Include: location intro, current conditions, 2-3 day outlook,
    notable patterns/alerts. Format for easy reading.
    """
    
    return call_claude_sonnet(prompt)

πŸš€ Getting Started

Prerequisites

  • Python 3.7+
  • AWS account with Bedrock access
  • AWS CLI configured

Setup

  1. Clone or download the project files

  2. Create virtual environment:

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install boto3 streamlit requests Pillow
  1. Configure AWS credentials:
aws configure
# Enter your AWS Access Key ID
# Enter your AWS Secret Access Key
# Default region: us-west-2
  1. Enable Claude 4.5 Sonnet in Bedrock:
    • Open Amazon Bedrock console
    • Navigate to Model access
    • Enable Claude 4.5 Sonnet
    • Wait for "Access granted" status

Running the Agent

Command-Line Interface:

python weather_agent_cli.py

Web Application:

streamlit run weather_agent_web.py

Access at: http://localhost:8501


πŸ§ͺ Test Cases

Try these example queries:

  • "Seattle" (major city)
  • "90210" (ZIP code)
  • "New York City" (multi-word city)
  • "National park near Homestead in Florida" (descriptive)
  • "Largest City in California" (requires reasoning)

πŸ› οΈ Technologies Used

AWS Services

  • Amazon Bedrock β€” Foundation model hosting (Claude 4.5 Sonnet)
  • AWS IAM β€” Authentication and permissions
  • boto3 β€” AWS SDK for Python

AI Models

  • Claude 4.5 Sonnet (us.anthropic.claude-sonnet-4-5-20250929-v1:0)
    • Complex reasoning and planning
    • Processing structured data
    • Human-like responses

APIs & Data Sources

  • National Weather Service API β€” Free, real-time US weather data
    • Points API: Location to forecast office mapping
    • Forecast API: Detailed weather forecasts

Development Tools

  • Python 3.7+ β€” Core programming language
  • Streamlit β€” Web interface framework
  • subprocess β€” HTTP requests via curl
  • json β€” Data processing

πŸ“Έ Screenshots

The project includes screenshots of:

Web Application Interface

  1. Main Landing Page

    • Dark-themed UI with location input field
    • "Get Weather Forecast" button
    • "Clear Results" button
    • Example suggestions section
  2. Weather Analysis Process

    • 6-step process visualization with checkmarks
    • Generated Points API URL display
    • Expandable raw API responses
    • Process status sidebar
    • "What Makes This Agentic?" explanation
  3. Final Weather Forecast Display

    • Location and timestamp
    • Current conditions
    • 3-day detailed outlook with temperatures and precipitation chances

All screenshots are stored in the /images folder.


🌍 Real-World Applications

The agentic patterns learned in this project apply to:

Weather & Environmental

  • Forecast assistants with alerts
  • Climate monitoring and predictions
  • Disaster response coordination

Travel & Transportation

  • Trip planning with weather integration
  • Route optimization
  • Event management

Business & Finance

  • Market analysis with data gathering
  • Customer support with knowledge bases
  • Risk assessment

Software Development

  • Code assistants
  • DevOps automation
  • Documentation generation

πŸŽ“ Learning Outcomes

By completing this workshop, I gained expertise in:

βœ… Amazon Bedrock Integration β€” Connecting to Claude 4.5 Sonnet and handling API responses βœ… API Integration Patterns β€” AI-driven URL generation and sequential API calls βœ… Prompt Engineering β€” Structured prompts for specific tasks and output formatting βœ… Agentic Workflow Design β€” Think β†’ Plan β†’ Act β†’ Process β†’ Respond pattern βœ… JSON Data Processing β€” Extracting and transforming complex API responses βœ… Error Handling β€” Building resilient systems with proper exception management βœ… UI Development β€” Creating both CLI and web interfaces with Streamlit


πŸš€ Next Steps

Immediate Extensions

  • Add more APIs (international weather, air quality, traffic)
  • Improve error handling with retry logic
  • Add memory to store previous queries
  • Enhance UI with weather maps and charts

Intermediate Projects

  • Multi-agent systems (weather + travel + events)
  • Tool integration (calculators, databases, notifications)
  • Conversation flow with context maintenance

Advanced Concepts

  • Production deployment (Lambda, ECS, EKS)
  • Security & compliance (auth, encryption, audits)
  • Performance optimization (caching, parallelization)

πŸ’‘ Key Takeaway

The Agentic AI Workflow:

Input β†’ AI Planning β†’ Action β†’ AI Processing β†’ Response

This pattern is reusable across countless domainsβ€”from customer support to research automation to business intelligence. Anyone can build intelligent systems that reason, plan, and take meaningful actions in the real world.


πŸ‘€ Workshop Contributor

Ramakrishna Natarajan Sr. Partner Solutions Architect, AWS


πŸ‘€ Author

Ahmad Sultani πŸ”— LinkedIn | 🐦 X (Twitter) ☁️ AWS Solutions Architect Associate (SAA-C03) β€” In Progress πŸ€– Specialization: Generative AI & Agentic Systems πŸ“Ί β€” AWS Tutorials & Tech Updates


πŸ“„ License

MIT.


Welcome to the world of agentic AI! πŸš€

About

Build an intelligent weather assistant from scratch using pure Python, Amazon Bedrock (Claude 4.5 Sonnet), and National Weather Service API - demonstrates core agentic AI principles (autonomy, reactivity, proactivity) with CLI and Streamlit web interfaces

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages