📘 Introduction

Welcome to this hands-on LangChain + LangGraph tutorial! In this guide, we’ll build an AI agent with tool-calling capabilities using LangChain, LangGraph, and OpenAI models.

Instead of just answering questions, our agent will be able to invoke a Python function when needed. We’ll demonstrate this with a simple tool that greets users — the perfect starting point to understand how tool integration works.

💡 What are LangChain and LangGraph?

  • LangChain is a Python framework for building applications powered by LLMs. It gives you tools to define prompts, memory, tools, and workflows — making it possible to build more than just chatbots.
  • LangGraph extends LangChain by allowing graph-based workflows. You can define nodes (steps) and edges(transitions) to control how agents reason, plan, and act.

Together with OpenAI models, this stack allows you to:

🤖 Build context-aware agents
🛠️ Equip them with tools (e.g., APIs, calculators, or custom Python functions)
🔗 Control workflows with graph structures
⚡ Scale from simple prototypes to powerful assistants

💡
In this tutorial, we’ll focus on tool calling — a core capability of modern AI agents.

✅ Prerequisites

Before starting, make sure you have the following:

🐍☑️ Python installed
📦☑️ Pip installed
🌐☑️ A virtual environment (venv) created and activated
🔑☑️ An OpenAI API key generated (get one from OpenAI)
🔐☑️ OpenAI API key set as environment variable OPENAI_API_KEY

📦1️⃣ Install Libraries

Install the following Python packages using pip:

pip install langchain-openai langgraph

📥2️⃣ Import Libraries

Start by importing the required Python modules:

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool

🛠️3️⃣ Define a Tool

We’ll create a simple Python greeting function and register it as a tool so that the agent can call it when needed.

@tool
def greet_user(name: str) -> str:
    """Greet the user with a personalized welcome message.

    Args:
        name: The name of the user.
    """
    return f"Hello, {name}! Welcome to the Deep Learning Nerds Academy"

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In