liveBook · Manning

LangChain agent

As explained in Build AI-Enhanced Web Apps

A software agent built with LangChain that iteratively decides which tools to invoke, processes their results, and produces a final response.

A LangChain agent combines a model with tools and repeatedly decides what to do next. It executes a tool, observes the result, revises its plan, and stops when it can produce a useful response. section 6.4.1

A typical agent workflow contains these moving parts:

  • Accept the user’s request and determine whether additional information is needed. section 6.4.1
  • Select and invoke one or more tools, such as search, flight comparison, booking, currency conversion, or weather services. section 6.4.1
  • Process each observation, continue iterating when necessary, and compile the gathered results into a final response. section 6.4.1

In a Next.js application, an API route can construct the agent on the server. An MCP client discovers remote tools, a Gemini model supplies reasoning, and the agent invokes those tools before returning structured output to the interface. The frontend can manage chat state with the Vercel AI SDK. section 12.5.1 section 12.5.2

Chuck Norris facts in a Next.js chat

A POST handler creates a MultiServerMCPClient connected over stdio to a Chuck Norris MCP server, discovers the get-chuck-joke tool, initializes Gemini, and creates a React agent. The agent decides whether to call the tool, then the route closes the MCP client and streams a UI-friendly result back to the chat interface. section 12.5.2

Figure 6.7 The iterative decision-making process of a LangChain agent. Starting with user input, the agent cycles through decision making, tool execution, and observation phases. The agent can utilize multiple tools (represented as tool 1, tool 2, or other agents) as needed. This process continues until the agent determines it can provide a final response to the user.

Trace the agent’s decision-making, tool execution, and observation loop from user input to final response. section 6.4.1

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains the reasoning-action-observation loop and demonstrates server-side construction, tool discovery, invocation, cleanup, and streaming.
Examples
Uses vacation planning and a Chuck Norris facts chat to demonstrate multi-tool iteration and MCP-backed tool invocation.
What you can do after
Build a Next.js API route that connects a model to MCP tools, invokes a LangChain agent, and streams results to a chat UI.
How it connects
Connects LangChain agents with MCP, Next.js API routes, Gemini, React agents, and the Vercel AI SDK.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.