liveBook · Manning

Chapter 11: Building tool-based agents with LangGraph

What you will learn in chapter 11 of AI Agents and Applications

The introduction contrasts deterministic LangGraph workflows with agents that use an LLM to make context-sensitive tool decisions.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction contrasts deterministic LangGraph workflows with agents that use an LLM to make context-sensitive tool decisions.

Key terms: agentic workflows, agents, large language model (LLM), tools, application state

11.1 Starting simple: Building a single-tool travel info agent

Introduces a single-tool Cornwall travel agent and the chunked vector-store content that will support its answers.

Key terms: vector store retriever, Wikivoyage, chunks, vector store

11.1.1 Project setup

Sets up the chapter 11 Python project, its API key and debugger configuration, and a naming convention for successive agent scripts.

Key terms: ch11 project folder, virtual environment, requirements.txt, .env, OpenAI API key, launch.json, .vscode, main_x_y.py, feature, version

11.1.2 Loading environment variables

This subsection tells readers where to load the API key in the travel agent script after preparing the .env file.

Key terms: .env file, API key, main_01_01.py, import statements

11.1.3 Preparing the travel information vector store

This section prepares a searchable Wikivoyage knowledge base for the Cornwall travel agent and makes it reusable through a retriever.

Key terms: build_vectorstore(), Wikivoyage, overlapping chunks, OpenAI’s embedding models, Chroma vector store, semantic similarity, singleton pattern, get_travel_info_vectorstore(), vector store client, retriever

11.2 Enabling agents to call tools

Introduces tool calling as the next step for making the prepared vector store retriever available to the agent.

11.2.1 From function calling to tool calling

This section explains what tool calling adds to LLMs, why agents use it for flexible decisions, and how ReAct alternates reasoning with tool use.

Key terms: function calling, tool calling, tool, structured inputs, structured outputs, agents, fixed agentic workflows, tool parameters, ReAct, Reasoning

11.2.2 How tool calling works with LLMs

Explains what an LLM receives when a tool is registered and illustrates tool registration with a decorated travel-search function.

Key terms: tool calling, function signature, textual description, @tool, search_travel_info(), parameter schema, vector store, Wikivoyage

11.2.3 Registering tools with the LLM

This section explains how registering the travel search tool lets an LLM request its use, and how LangChain simplifies that registration.

Key terms: tool registration, parameter schema, structured tool call, tools argument, decorated Python function, .bind_tools(TOOLS), function signature, docstring, JSON schema

11.2.4 Agent state: Tracking the conversation

This subsection defines the agent’s state as a simple message history for the conversation.

Key terms: AgentState, LLM messages, tool responses

11.2.5 Executing tool calls

This section explains how a tool-execution node runs LLM-requested tools, returns their results to the conversation, and can be replaced by LangGraph’s built-in ToolNode.

Key terms: tool calls, ToolsExecutionNode, conversation state, ToolNode

11.2.6 The LLM node: Coordinating reasoning and action

The section explains how a tool-enabled LLM node uses conversation messages to decide whether to request tools, continue reasoning, or answer.

Key terms: LLM node, agent state, llm_with_tools, AIMessage, content, tool_calls

11.3 Assembling the agent graph

This section introduces the single-tool travel agent as a LangGraph directed graph made of LLM and tool-execution nodes connected by edges.

Key terms: LangGraph, directed graph, node, edges, LLM node, tool execution node

11.4 Understanding the agent graph structure

Explains how the travel agent graph moves between its LLM and tools nodes, decides when to end, and starts and finalizes execution.

Key terms: LLM node, tools node, ReAct pattern, conditional edge, tools_condition, tool_calls, END, entry point, llm_node, builder.compile()

11.5 Running the agent chatbot: The Read-Eval-Print Loop

This section shows how a simple Read-Eval-Print Loop connects a user to the travel information agent graph.

Key terms: Read-Eval-Print Loop (REPL), HumanMessage, agent graph, exit, quit

11.6 Executing a request

Introduces a hands-on walkthrough of running and debugging the travel information agent to observe its LangGraph flow between the LLM and a tool.

11.6.1 Step-by-step debugging

Walks through debugging a travel agent request to show how LLM tool calls are routed, executed, returned as messages, and turned into a final answer.

Key terms: breakpoints, state["messages"], response_message, tool calls, tools_condition, ToolsExecutionNode.__call__(), semantic search tool, ToolMessage, tool_calls, AIMessage

11.7 Expanding your agent: Adding a weather forecast tool

The section explains why a travel agent that searches curated content may also need current weather information.

Key terms: semantic search, curated travel content, dynamic, real-time information

11.7.1 Implementing a mock weather service

This section introduces a mock weather service that supplies simulated conditions and temperatures while the travel agent is being expanded.

Key terms: mock weather service, WeatherForecastService, weather condition, temperature

11.7.2 Creating the weather forecast tool

This section introduces a weather forecast tool that wraps a mock service so an agent can use simulated weather data.

Key terms: weather_forecast tool, mock weather forecast, town name

11.7.3 Updating the agent for multi-tool support

This subsection completes the multi-tool setup by making the LLM aware of both the travel and weather tools.

Key terms: tool calling, both available tools, travel queries, weather checks

11.8 Executing the multi-tool agent

This section explains that registering a weather tool lets the agent combine travel and weather information without changing its graph.

Key terms: weather forecast tool, graph structure, LLM, tool-calling protocol

11.8.1 Running the multi-tool agent (initial behavior)

This section uses a debugging run to show that the multi-tool agent may request weather for towns chosen from the LLM’s pretrained knowledge without first using semantic search.

Key terms: response_message.tool_calls, semantic search tool, pretraining

11.8.2 Improving LLM tool usage with system guidance

Clearer tool descriptions and a guiding system message steer a travel agent to search its knowledge base before checking weather and producing a grounded answer.

Key terms: tool descriptions, SystemMessage, semantic search tool, hallucinations, knowledge base, ToolMessage, vector store, weather forecast, synthesized, fact-based answer

11.9 Using prebuilt components for rapid development

Introduces LangGraph’s prebuilt agents as a way to reduce orchestration boilerplate without giving up transparency and observability.

Key terms: prebuilt agent components, ReAct agent, orchestration logic, boilerplate, transparency, observability

11.9.1 Refactoring to use the LangGraph ReAct agent

Refactors a custom tool-based agent into a prebuilt LangGraph ReAct agent that handles tool use and orchestration.

Key terms: LangGraph ReAct agent, ToolsExecutionNode, llm_node, tool binding, graph wiring, AgentState, remaining_steps, tool-calling rounds

11.9.2 Running the prebuilt agent

11.9.3 Observing and debugging with LangSmith

This section explains how LangSmith restores visibility into an agent built with high-level abstractions.

Key terms: LangSmith, tracing, tool calls, LLM reasoning, intermediate states

11.9.4 Enabling LangSmith tracing

This subsection shows how to access a LangSmith trace and explains why tracing makes even a prebuilt agent’s behavior inspectable.

Key terms: .env file, LangSmith, Tracing Projects, trace, LangSmith graphical trace, tool call, LLM step, flow of messages, observability

11.10 Summary

This summary contrasts LangGraph agent approaches and recaps how tool design, testing, and tracing support reliable tool-calling agents.

Where this is used later

Concepts explained in this chapter

← Chapter 10: Query generation, routing, and retrieval postprocessing Chapter 12: Multi-agent systems →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.