A beginner-friendly agent that shows you how to build AI agents using LangGraph and TypeScript. This agent fetches real-time weather data and provides helpful recommendations.
Ask questions like:
- "What's the weather in London?"
- "Give me a 5-day forecast for New York"
- "Should I bring an umbrella in Paris?"
The agent will:
- ✅ Understand your question
- ✅ Fetch real weather data from WeatherAPI
- ✅ Give you friendly answers with recommendations
You need two free API keys:
1. WeatherAPI (for weather data)
- Sign up: https://www.weatherapi.com/signup.aspx
- Copy your API key from the dashboard
2. OpenAI (for the AI brain)
- Sign up: https://platform.openai.com/
- Create an API key in your account settings
# Navigate to the weather-agent directory
cd agents/weather-agent
# Install dependencies
yarn install
# Create your environment file
cp .env.example .envNow edit the .env file and add your API keys. The file looks like this:
# ============================================
# REQUIRED: API Keys
# ============================================
# WeatherAPI Key
WEATHER_API_KEY=your_weather_api_key_here
# OpenAI API Key
OPENAI_API_KEY=your_openai_api_key_here
# ============================================
# OPTIONAL: Model Configuration (already set to good defaults)
# ============================================
MODEL_NAME=gpt-4o-mini
TEMPERATURE=0Just replace the two API keys with your actual keys. The other settings have good defaults already!
# Run the agent in your terminal
yarn startYou'll see the agent answer weather questions!
Want to deploy this agent on your own server? Check out the Self-Hosting Guide for:
- 🐳 Quick Start - Deploy with Docker in 3 commands (no databases needed!)
- 💾 Persistent History - Add Redis + PostgreSQL for conversation storage
- 🔒 Production Setup - Security, scaling, and monitoring best practices
Quick deploy:
cp .env.example .env # Add your API keys
docker compose up -d # Start the agent
# Open Studio: https://smith.langchain.com/studio → Connect to http://localhost:8000See SELF-HOSTING.md for complete documentation.
Want to chat with your agent in a nice web interface? Use LangSmith Studio:
# Start the development server
yarn devThen open your browser to:
- LangSmith Studio: https://smith.langchain.com/studio?baseUrl=http://localhost:2024
In the Studio, you can:
- Chat with the agent in real-time
- See how it thinks and makes decisions
- Watch it call the weather API
- Debug any issues
This file contains the entire agent in 7 simple steps:
// Step 1: Define the state (conversation memory)
// Step 2: Create weather tools (API connections)
// Step 3: Create the agent node (AI brain)
// Step 4: Create the tools node (executes API calls)
// Step 5: Create routing (decides what to do next)
// Step 6: Build the graph (connect everything)
// Step 7: Compile (make it ready to run)Think of the agent as a flowchart:
- User asks a question → Agent thinks about it
- Agent needs weather data? → Call Tools to get it
- Got the data? → Go back to Agent to answer
- Answer ready? → End
This flowchart is called a "graph" in LangGraph!
The agent has two tools:
Tool 1: get_current_weather
- Gets current weather for a location
- Returns: temperature, conditions, humidity, wind
Tool 2: get_forecast
- Gets weather forecast (1-14 days)
- Returns: daily high/low temps, rain chance, conditions
- User: "What's the weather in Paris?"
- Agent (thinking): "I need to call get_current_weather for Paris"
- Tools Node: Calls WeatherAPI
- Agent: "Got the data! Let me write a nice response with recommendations"
- User: Gets friendly answer like:
"It's 15°C and sunny in Paris! Perfect weather for sightseeing. Don't forget your sunglasses!"
weather-agent/
├── src/
│ └── graph.ts # Main agent code (the whole agent in one file!)
├── .env # Your API keys (you create this)
├── .env.example # Template for .env
├── package.json # Dependencies
└── README.md # This file
Simple, right? One main file to understand!
Edit your .env file to change settings:
# Required
WEATHER_API_KEY=your_key
OPENAI_API_KEY=your_key
# Optional: Choose different AI models
MODEL_NAME=gpt-4o-mini # Fast and cheap (default)
# MODEL_NAME=gpt-4o # Smarter but costs more
# MODEL_NAME=gpt-3.5-turbo # Cheaper alternative
# Optional: Creativity level (0 = consistent, 1 = creative)
TEMPERATURE=0
# Optional: For LangSmith tracing
LANGSMITH_API_KEY=your_key
LANGSMITH_PROJECT=weather-agent
LANGSMITH_TRACING=trueYes! Just change MODEL_NAME in your .env file:
gpt-4o-mini- Default, fast, cheap ($0.15 per 1M tokens)gpt-4o- Smarter ($2.50 per 1M tokens)gpt-3.5-turbo- Budget option ($0.50 per 1M tokens)
With the free tiers:
- WeatherAPI: 1 million calls/month for free
- OpenAI: You pay per request (around $0.0001 per weather question with gpt-4o-mini)
A typical weather question costs less than 1 cent!
Yes! Open src/graph.ts and edit the system prompt to change how the agent talks.
WeatherAPI.com - a free weather data service. The free tier gives you:
- Current weather for any location
- 3-day forecasts
- 1 million API calls per month
Almost anything:
- City names: "London", "New York", "Tokyo"
- Zip codes: "10001", "SW1"
- Coordinates: "48.8567,2.3508"
- Even: "auto:ip" (your current location)
"WEATHER_API_KEY is required" error
- Make sure your
.envfile exists in theweather-agentdirectory - Check that you copied the API key correctly (no spaces or quotes)
Agent gives weird responses
- Try lowering the
TEMPERATUREin.env(set it to 0) - Make sure you're using a model like
gpt-4o-minithat is good with tool calling
"Cannot find module" errors
- Run
yarn installagain - Make sure you're in the
weather-agentdirectory
- Official Docs: https://langchain-ai.github.io/langgraph/
- Tutorials: https://docs.langchain.com/oss/javascript/langgraph/quickstart
- Thinking in LangGraph: https://docs.langchain.com/oss/javascript/langgraph/thinking-in-langgraph
- Add More Tools: Create tools for other APIs (news, local events, etc.)
- Change Personality: Edit the system prompt to make it funny, serious, or professional
- Add Memory: Make it remember previous conversations
- Deploy It: Put it online so anyone can use it
Use this weather agent as a template! The pattern is:
- Define your state (what to remember)
- Create tools (what the agent can do)
- Build the graph (how it flows)
- Compile and run!
- Questions? Open an issue on GitHub
- Found a bug? Submit a pull request
- Want to learn more? Check the LangGraph documentation
This is a learning project! Contributions that make it easier to understand are especially welcome:
- Better comments
- More examples
- Clearer explanations
- Bug fixes
This project is licensed under the MIT License - see the LICENSE file for details.
Happy learning! 🚀
Built with ❤️ using LangGraph and WeatherAPI