Building Agents with LangChain: A Practical Guide

Building Agents with LangChain: A Practical Guide

Building agents with LangChain in 2026 is simpler than it was a year ago. The 1.0 release, on 22 October 2025, trimmed the framework to its essential parts and made the create_agent factory the recommended way to build an agent. You give the factory a model, a set of tools and a system prompt, and it returns an agent that runs on the LangGraph runtime.

The central question is how to go from that first agent to one you can trust in production, and the short answer is to start with one agent and three tools, add memory and tests early, and only reach for a full graph when the work genuinely needs branching.

LangChain is the fastest way to build a standard agent, and LangGraph is the lower layer underneath it for work that needs explicit control. Most agents never need to leave the create_agent layer, and the ones that do can drop into LangGraph without changing frameworks.

Key takeaways

  • Building agents with LangChain starts with the create_agent factory, which compiles a model, tools and a system prompt into an agent.
  • LangChain 1.0, released on 22 October 2025, runs agents on the LangGraph runtime, giving them checkpoints, streaming and human-in-the-loop steps.
  • Keep the first agent small: one goal, three tools at most, and a system prompt that states the goal, the rules and the output format.
  • Add memory deliberately, scope tools to the minimum access they need, and test agents on fixed scenarios before shipping.
  • Reach for LangGraph directly only when the work needs explicit branching, approvals or crash recovery that create_agent cannot express.

Start with create_agent

The create_agent factory is the entry point for building agents with LangChain. You pass it a chat model, a list of tools and a system prompt, and it returns an agent you can run. The agent loop is the familiar one: the model reads the goal, decides whether to call a tool, reads the result, and repeats until it produces a final answer.

Because the agent runs on LangGraph, the loop is a real graph under the surface, and the state is checkpointed after each step.

That checkpointing is free, and it is the reason create_agent is more than a convenience wrapper. A run can be paused for a human approval and resumed later, it can survive a crash and continue from the last checkpoint, and it can be rewound and retried. LangChain 1.0 requires Python 3.10 or later, and the framework is MIT-licensed, with integrations for most model providers.

Best for: a first production agent with a clear goal and a handful of tools.

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI

agent = create_agent(
 model=ChatOpenAI(model="gpt-5"),
 tools=[search_docs, check_order_status],
 system_prompt="You are a support agent. Use the tools to find facts, then answer concisely.",
)

The example above is the whole shape of a first agent: a model, two tools and a system prompt. Everything else in this guide is about making that shape reliable. Resist the urge to add a second agent, a retriever and a memory store on the first day, because each addition is a new failure mode.

Write a system prompt that does real work

The system prompt is the most important file in an agent project, because it is where the agent’s behaviour is actually decided. A good prompt has four parts: the role, what the agent is and who it serves; the goal, what a successful run looks like; the rules, what the agent must never do, such as inventing a fact or taking an irreversible action without approval; and the output format, whether the answer should be a paragraph, a list, or a structured object.

Keep the prompt short and specific. Long prompts with vague instructions produce agents that improvise, and improvisation is the opposite of reliability. State the goal in one sentence, list the rules as plain statements, and give one example of a good answer where the format matters.

When the agent misbehaves, the prompt is the first place to look. For the prompt-management side of this work, see our guide to AI prompt version control.

Tools: give the agent hands, carefully

Tools are how an agent goes from talking to doing. A tool is a function the model may call, described by a name, a description and a schema for its arguments. LangChain turns a decorated Python function into a tool, and it supports the Model Context Protocol, so tools from MCP servers can be used directly.

The description matters more than the code, because the model decides when to call a tool from the description alone.

Scope every tool to the minimum access it needs. A tool that reads an order status should be able to read orders and nothing else, and a tool that sends a message should require a human approval before it runs. That discipline is what keeps an agent from becoming a security incident.

Our guide to AI agent tool calling explains how models move from talking to doing, and our guide to secure AI tool calling covers how to keep that power under control. Best for: tools that read before tools that write, and approval gates before any tool that changes state.

A laptop screen showing a three-stage circular diagram with a gear, a brain and a tick, beside a cup of coffee
The agent loop in one picture: think, act with a tool, check the result, and repeat until the goal is met.

Memory: what the agent should remember

An agent without memory starts every conversation from nothing, which is fine for a single question and useless for a returning user. Short-term memory keeps the conversation history within a run, so the agent can refer back to what was said. Long-term memory stores facts across runs, such as a user’s preferences or the outcome of an earlier task.

LangGraph’s checkpointing provides the durable store underneath.

Be deliberate about what you store. Memory that grows without limit becomes a cost and a privacy problem, and a memory full of stale facts makes the agent worse, not better. Store facts that change slowly, such as preferences and decisions, and keep the working history short.

Give the user a way to see and delete what is stored. For the architecture behind this, see our guide to AI agent memory architecture.

Retrieval: grounding the agent in your data

Most useful agents need to answer from your data, not just from what the model was trained on. That is retrieval: the agent searches a knowledge base, reads the relevant documents, and grounds its answer in what it found. In LangChain, a retriever is just another tool, which keeps the design clean.

The agent decides when to search, the retriever returns the most relevant passages, and the model writes an answer that cites them.

Retrieval quality decides the agent’s quality, so it deserves more attention than the agent loop itself. A retriever that returns the wrong documents will produce a confident wrong answer, and no amount of prompt engineering fixes that. Test retrieval separately from the agent, with a fixed set of questions and known answers, before you judge the agent as a whole.

When to drop into LangGraph

There comes a point where create_agent cannot express what the work needs: the agent must branch on a tool result, wait for a human approval in the middle of a run, run two steps in parallel, or resume exactly after a crash. At that point, build the workflow as a LangGraph graph directly. Nodes become your steps, edges become your routing decisions, and the shared state becomes the record of the run.

Because create_agent already runs on LangGraph, the move is a change of layer, not a change of framework, and your tools and prompts transfer unchanged.

Do not make the move early. A graph is more code, more tests and more to debug, and a team that builds a graph before it needs one pays that cost on every change. The right time is when you can point to a specific requirement that the simple agent cannot meet.

Best for: workflows with branching, parallel steps, approvals or recovery requirements that a single loop cannot express.

Approach How you build it Control When to use it
create_agent Model, tools and a system prompt Low: the loop is fixed A first agent with a clear goal
LangGraph directly Nodes, edges and shared state High: every path is explicit Branching, approvals and recovery
LangGraph subgraphs Reusable graphs inside a graph High: composable control Multi-step workflows with shared parts

The table shows the two layers of one stack. Most agents live in the first row, and only the ones with branching or recovery needs move to the second.

Testing and shipping the agent

Agents need tests, and the tests look different from ordinary software tests. A fixed set of scenarios, each with an input and an expected outcome, is the starting point. Run the scenarios after every change, and record the pass rate, the cost per run and the number of tool calls.

When the agent fails, read the trace before changing the code: the failure is usually a tool description, a prompt rule or a retrieval miss, not the model.

Ship in stages. Start with a small group of users, or with the agent drafting answers that a human approves before they are sent. Watch the traces for a week, fix the most common failure, and only then widen the rollout.

Set limits from day one: a maximum number of steps per run, a maximum cost per run, and an alert when either is exceeded. Our guide to AI agent testing covers how to evaluate agents that take actions.

Building agents with LangChain checklist

  • One agent, one goal, and no more than three tools in the first version.
  • A system prompt that states the role, the goal, the rules and the output format.
  • Every tool has a clear description, minimum access, and an approval gate before irreversible actions.
  • Retrieval is tested separately, with fixed questions and known answers, before the agent is judged.
  • A fixed set of test scenarios runs after every change, with pass rate, cost and tool calls recorded.
  • Step and cost limits are set, with alerts, and the first rollout is small or human-approved.

Frequently asked questions

What is the easiest way to build an agent with LangChain?

Use the create_agent factory. Pass it a chat model, a list of tools and a system prompt, and it returns an agent that runs on the LangGraph runtime. That is enough for most first agents, and you can add memory, retrieval and human approvals as the agent proves itself.

Do I need LangGraph to build an agent with LangChain?

Not directly. Since LangChain 1.0, create_agent runs on LangGraph underneath, so you get its durability and checkpointing without writing graph code. You only need to use LangGraph directly when the work needs explicit branching, parallel steps or custom state handling.

What happened to AgentExecutor in LangChain 1.0?

AgentExecutor was replaced by create_agent as the recommended way to build agents. It remains available in maintenance mode through December 2026, and legacy chains moved to the langchain-classic package. New code should use create_agent.

How many tools should an agent have?

Start with three at most. Each tool is a choice the model must make, and too many tools make the agent slower and more error-prone. Add a tool only when a real task needs it, and write a clear description for each one, because the model chooses from the description.

How do I stop a LangChain agent from looping forever?

Set a maximum number of steps per run, which the LangGraph runtime enforces, and add a cost limit as a second guard. Also write the system prompt so the agent knows when to stop: state what a finished answer looks like.

Is LangChain free to use?

Yes, LangChain and LangGraph are free open-source frameworks under the MIT licence. You pay for the language-model calls and for any hosted services you choose, such as LangSmith for tracing and evaluation or LangGraph Platform for deployment. The frameworks themselves cost nothing.

Latest articles

Scroll to Top