11 Building Tool-based Agents with LangGraph

 

This chapter covers

  • Building LLM-powered agents using LangGraph
  • Registering and using tools for dynamic agent execution
  • Debugging agent execution and tool calls
  • Simplifying agents with pre-built LangGraph components
  • Observing agent execution with LangSmith

In chapter 5, you explored the distinction between agentic workflows and agents. You learned that agentic workflows are fundamentally deterministic: their logic is based on flows with conditional paths that depend on the current application state. These workflows can be elegantly modeled using node-based graphs in LangGraph, and you saw a complete, hands-on example of such a system.

Agents, however, operate differently. Rather than following a predetermined flow, agents rely on dynamic, context-sensitive decision-making. With the help of a language model (LLM), an agent chooses which tools to use—and in what order—based on the evolving context of the task at hand. These decisions aren’t pre-scripted; instead, they unfold step by step, as the agent continually evaluates the outputs of previous actions and adapts accordingly.

In this chapter, you’ll put these ideas into practice by building a multi-tool travel information agent. We’ll begin simply, implementing an agent that provides destination information using a single tool. From there, we’ll extend it into a true multi-tool agent, able to answer questions about both travel destinations and their current weather conditions.

11.1 Starting Simple: Building a Single-Tool Travel Info Agent

11.1.1 Project Setup

11.1.2 Loading Environment Variables

11.1.3 Preparing the Travel Information Vector Store

11.2 Enabling Agents to Call Tools

11.2.1 From Function Calling to Tool Calling

11.2.2 How Tool Calling Works with LLMs

11.2.3 Registering Tools with the LLM

11.2.4 Agent State: Tracking the Conversation

11.2.5 Executing Tool Calls

11.2.6 The LLM Node: Coordinating Reasoning and Action

11.3 Assembling the Agent Graph

11.3.1 Understanding the Agent Graph Structure

11.4 Running the Agent Chatbot: The REPL Loop

11.5 Executing a Request

11.5.1 Step-by-Step Debugging

11.6 Expanding Your Agent: Adding a Weather Forecast Tool

11.6.1 Implementing a Mock Weather Service

11.6.2 Creating the Weather Forecast Tool

11.6.3 Updating the Agent for Multi-Tool Support

11.7 Executing the Multi-Tool Agent

11.7.1 Running the Multi-Tool Agent (Initial Behavior)

11.7.2 Improving LLM Tool Usage with System Guidance

11.8 Using Pre-Built Components for Rapid Development

11.8.1 Refactoring to Use the LangGraph React Agent

11.8.2 Running the Pre-Built Agent

11.8.3 Observing and Debugging with LangSmith

11.9 Summary