Building Your First LangChain Agent with LangGraph in 2026
Build a LangChain agent step by step with LangGraph, tools, memory and tracing, avoid four common mistakes, and see how a bootcamp support desk used one.
This article is published in English.
Sources: Building AI Agents with LangChain: A Beginner’s Guide for 2026
Plenty of developers have followed a LangChain tutorial and ended up with a chatbot that makes up tool names and loops until the token budget runs dry. The distance between a finished install and a working shipped agent is wide, and most tutorials skip the parts that cause trouble. Here's what an agent does under the hood, how to build one with the current stack, which mistakes to avoid and what a realistic deployment looks like in education technology.
The short version: a LangChain agent pairs an LLM's reasoning with external tools to finish multi-step jobs. Recent LangChain releases lean on LangGraph for stateful, looping agents rather than the old AgentExecutor alone. Tools, retrieval and memory carry most of the weight in anything production-grade.
What makes something an agent
A chatbot takes input and returns output in one pass. An agent takes a goal, picks tools, runs them, looks at what came back and decides the next move, repeating until the goal is met or a stop condition fires. That loop is the whole difference.
It matters a lot for learning products. Picture a student typing: "Quiz me on Chapter 5, check my last three quiz scores, and make it harder if I keep scoring above 80%." A static chatbot can't handle that. An agent can split the request into pieces, call a quiz API, query a grades database, apply the conditional logic and return a personalized quiz set. Learning platforms and LMS startups are building this sort of architecture now.
Three layers make up the design:
- The LLM backbone, such as GPT-4o, Claude, Gemini or an open-weight model.
- The tool layer: plain Python functions, external APIs, or LangChain's built-in tools like Tavily Search, Wikipedia and custom SQL queries.
- The memory layer, anything from a short-term conversation buffer to long-term vector stores or entity memory.
Tie them together with a LangGraph state machine and you have something you can take to production.
Building one, step by step
Follow the steps in order. Skipping one is the usual reason beginner agents fall over once real users show up.
- Install the stack. Run
pip install langchain langchain-openai langgraph langchain-community tavily-pythonon Python 3.11 or newer. PutOPENAI_API_KEYandTAVILY_API_KEYin environment variables and never hardcode them. - Write the goal down in one sentence before touching code. For example: the agent answers questions about a student's course progress by querying the LMS API and summarizing the result. Vague goals produce broken agents, and sharpening the goal early saves hours of debugging.
- Set up the model.
ChatOpenAI(model="gpt-4o", temperature=0)gives you steadier reasoning, and a temperature of zero matters for tool-calling because it reduces the chance of invented calls. For cost-sensitive deployments,gpt-4o-minican handle a large share of the work for a fraction of the price. - Define tools with the
@tooldecorator. Each one is a Python function with a clear docstring, because the model reads that docstring to decide when to call it. A poor docstring means the tool never gets called, or gets called at the wrong moment. - Build the LangGraph state and nodes. Declare a
TypedDictstate schema, create one node for the model's reasoning and one for running tools, and connect them throughStateGraphwith conditional edges. Those edges create the reasoning loop. - Add memory.
MemorySaverfrom LangGraph covers short-term state. For long-term memory, which personalized learning agents depend on, connect a vector store such as Pinecone or Chroma. - Compile, test and watch. Compile with
graph.compile(checkpointer=memory), invoke it with a test query and use LangSmith, LangChain's tracing platform, to inspect every step: which tool ran, what input it got and what the model decided afterward. - Harden it. Add retries, token budget limits (
max_iterations), input validation and arecursion_limitso a lost agent can't loop forever. Log every tool call to your monitoring stack.
Where agents fit in education tech
LMS platforms such as Moodle, Canvas or a homegrown system can use agents as course assistants. They query grades, recommend the next module, flag struggling students to an instructor and build quiz questions from uploaded PDFs through RAG. One mid-sized LMS provider reported cutting instructor admin time by 40% after an agent began answering student progress questions.
AI tutors work best as agents rather than single model calls. The tutor checks what the student already knows (memory), pulls the relevant course material (RAG), adjusts how it explains things (a preference-profile tool) and schedules a follow-up quiz (a calendar tool). LangChain's tool chaining keeps that under roughly 500 lines of Python.
University and research portals are another fit. Graduate students use agents to search institutional repositories, summarize papers, cross-check citations and draft literature review sections. The agent does the retrieval grunt work and the student does the thinking, which is a reasonable, citation-safe workflow when configured properly.
Skill-based learning platforms, think coding bootcamps and professional certifications, use agents to run live code evaluation, compare learner output against a rubric, give targeted feedback and update skill graphs. A good one doesn't just grade. It reasons about why the learner made a particular mistake and produces a small, targeted lesson.
Choosing a framework
Comparing LangChain, LlamaIndex, CrewAI and AutoGen deserves its own article, but a rule of thumb helps. LangChain with LangGraph is the stronger pick for general-purpose agents that need tools, memory and reasoning loops. LlamaIndex is tuned for retrieval pipelines and document question answering. Plenty of production systems combine them, with LlamaIndex handling ingestion and retrieval while LangChain orchestrates the agent on top.
The flow of a single request goes like this: define the goal and system prompt, set up the model and bind the tools, create the graph state and nodes, then let the agent ask itself which tool it needs. It runs that tool with generated input, observes the output and decides whether the task is complete or the loop should continue. When it's done, it returns the answer.
Some lessons stand out from that flow.
- Temperature counts for more than model choice. Setting it to zero on the agent's model tends to cut hallucinated tool calls noticeably compared with higher values, whichever frontier model you use. Treat any specific percentage you read online as a rough estimate and test with your own tools.
- Docstrings are the agent's instruction manual. A one-line vague description is the most frequent cause of tool misuse in beginner builds.
- LangGraph replaced AgentExecutor for good reason. AgentExecutor is fine for simple single-pass agents, but anything with branching, human-in-the-loop steps or parallel tool calls needs the node-based state machine.
- RAG plus an agent is where education products get real value. Without retrieval, an agent can only reason from training data. With it, the agent can answer questions about your actual course content, student data or institutional knowledge.
- Tracing isn't optional. Don't ship an agent without LangSmith or an equivalent, because debugging a looping agent without traces is guesswork and with them root-cause analysis takes minutes.
Case study: a bootcamp support desk
The setup was a mid-sized online coding bootcamp with about 1,200 active students taking Python, data science and web development courses. Support fielded more than 800 student questions a week, and around 60% were repeats about deadlines, project feedback and finding things in the curriculum.
Before the agent, three full-time staff handled everything through a shared inbox. Average response time was 6.2 hours, student satisfaction (CSAT) sat at 62%, and each instructor lost about 11 hours a week to admin queries.
The team, two developers over six weeks, built a LangGraph agent with four tools. One searched course material through RAG over the LMS knowledge base. One looked up student progress through the LMS API. One calculated deadlines from the course calendar. The last one escalated complicated queries to a human with full context attached.
Ninety days after launch, the reported results were:
- The agent handled 74% of incoming queries.
- Average response time dropped to 8 seconds.
- CSAT rose to 81%.
- Human support tickets fell by 52%.
- Each instructor saved about 7 hours a week.
- Development cost was recovered in roughly 4.5 months.
The standout lesson concerned the escalation tool, which turned out to be the most important item in the kit. Students trusted the agent more once it was clear that it knew its limits and would hand off cleanly. The design of that handoff did more for satisfaction than any improvement in reasoning.
These figures come from the team's own reporting, so use them as an illustration of the shape of the gain rather than a benchmark you should expect to match.
Four common mistakes
Using AgentExecutor for complex agents
It doesn't support conditional branching, parallel tool execution or state that persists across conversation turns, and in 2026 those are standard requirements. Migrate to LangGraph. The learning curve is steeper at first, but you get full control of the reasoning loop, and LangChain's own documentation now points to LangGraph as the default for anything non-trivial.
Having no recursion limit
Without a recursion_limit, a confused agent can loop indefinitely and burn tokens and money. The risk climbs with tool-heavy agents, where a single failed call can trigger repeated retries. Set recursion_limit=25 or lower in the LangGraph compile config, and write explicit stop conditions into your node logic instead of leaving the decision to the model.
Skipping LangSmith tracing early
When an agent gives a wrong answer there are a dozen places the chain could have gone wrong, and without traces you're reading the final output and guessing. Enable LangSmith on day one, since it's free for development use. Export LANGCHAIN_TRACING_V2=true and LANGCHAIN_API_KEY before you write the first line of agent code, and you'll be glad during your first debugging session.
Writing tools with vague docstrings
Tool selection is driven entirely by the model reading your docstring. Something like "gets user data" gives it nothing to work with, so it'll call the tool at random or not at all. Spell out the tool's purpose, the inputs it takes and the situations where it applies. A good one reads: retrieves a student's last five quiz scores from the LMS database for a given student_id, to be used when the user asks about past performance or quiz history.
Quick answers
What does LangChain do for beginners? It's a Python framework that connects language models to tools, data sources and memory. You hand the model a set of tools and it decides which to call to reach a goal. Begin with the quickstart docs and a simple tool-calling agent before attempting multi-step workflows.
Is LangChain better than LlamaIndex for agents? For general-purpose agents with tools, memory and reasoning loops, LangChain with LangGraph is the better fit. LlamaIndex is better tuned for retrieval and document QA, and many teams use both.
How long does a first agent take? A simple single-tool agent takes a developer with basic Python about two to four hours. A production-grade agent with several tools, memory, error handling and LangSmith observability usually takes one to three weeks, depending on how awkward the APIs are.
What is RAG, and do you need it? Retrieval-augmented generation lets the agent answer questions about your own data, like course content, student records or PDFs, by retrieving relevant chunks before it writes a response. You need it whenever the agent must know something that wasn't in the model's training data, which for learning products is nearly always.
Does LangGraph replace LangChain? No, it extends it. LangChain supplies the primitives (models, tools, memory) and LangGraph adds stateful graph orchestration for loops, branching and multi-agent coordination. It's the recommended route for any non-trivial agent in the LangChain ecosystem.
Start small
You no longer need to be an ML researcher or a big-tech engineer to build agents. Someone with basic Python can ship a working one in a weekend with LangGraph, LangSmith and a clear process. Adaptive tutors, LMS assistants and progress coaches are all within reach, and the tooling is mature enough for production.
The teams that do well aren't the ones with the biggest models. They understand agent architecture well enough to design sensible tool sets, dependable memory and graceful failure. Begin with one tool, one goal and one agent, then iterate.