import requests, sys, json
from dotenv import load_dotenv
from langchain.agents import create_agent
from langchain.tools import tool

load_dotenv()

@tool('get_weather', description='Return weather information for a given city', return_direct=False)
def get_weather(city: str):
	response = requests.get(f'https://api.weather.gov/alerts/active/area/{city}')
	#print(f'Response is @@@@@@@@@@@@@@@@@@@@ {response}')
	#sys.exit()
	return response.json()


agent = create_agent(
    model="claude-sonnet-4-5-20250929",
    tools=[get_weather],
    system_prompt="You are a helpful assistant"
)

# Run the agent
result = agent.invoke({
	"messages": [
		{"role": "user", "content": "what is the weather in NY?"}
		]
})

if result:
	#Get the "messages" element of the dictionary which holds the agents response 
	agent_response = result["messages"][-1]
	#... then get the "content" part of the resource returned
	response = agent_response.content
	print(response)
	
else:
	print("An error occurred")

print(type(response))