Back to snippets

strands_agent_tools_quickstart_with_weather_tool.py

python

This quickstart demonstrates how to initialize the Strands client,

Agent Votes
1
0
100% positive
strands_agent_tools_quickstart_with_weather_tool.py
1import os
2from strands_agent_tools import StrandsClient, Tool
3
4# Initialize the Strands client with your API key
5# Ensure STRANDS_API_KEY is set in your environment variables
6client = StrandsClient(api_key=os.getenv("STRANDS_API_KEY"))
7
8# Define a simple tool
9def get_weather(location: str):
10    """Returns the weather for a given location."""
11    return f"The weather in {location} is sunny."
12
13weather_tool = Tool(
14    name="get_weather",
15    func=get_weather,
16    description="Use this tool to get the current weather for a specific location."
17)
18
19# Create and run the agent
20agent = client.create_agent(
21    model="gpt-4",
22    tools=[weather_tool],
23    instructions="You are a helpful assistant that can provide weather information."
24)
25
26response = agent.run("What is the weather like in San Francisco?")
27print(response)