LangChain in Practice: Mastering the Four Core Modules of the Agent Ecosystem

Master LangChain's four core modules and build your first AI Agent from the ground up.
This article breaks down the LangChain ecosystem into its four pillars — LangChain (core components), LangGraph (stateful orchestration), Deep Agents (autonomous planning), and LangSmith (production ops) — and walks through building a working Agent. Key concepts include tool calling, prompt templates, and short-term memory management, with an emphasis on architectural thinking over API memorization.
Why LangChain Is Still the Most Mature Agent Framework
In the age of large AI models, the way we approach learning development frameworks is fundamentally different from how we once learned Spring Boot or Java. In the past, you needed to memorize countless APIs. Today, almost any code that calls an LLM can be written by the model itself. What's truly worth investing your energy in, therefore, is not the API interfaces that may change at any moment — it's a deep understanding of the overall framework ecosystem and its underlying architectural thinking.
The reason LangChain is widely regarded as the most mature AI Agent client framework comes down to its philosophy of "embracing everything." It preserves the traditional chain-based (Chain) approach, supports mature workflow orchestration, and also accommodates the latest autonomous planning agents. It maintains the convenience of a framework while preserving a remarkable degree of developer freedom — and that distinction matters enormously. Most frameworks, once they encapsulate a feature, end up constraining how it's used, making them suitable only for specific problems. LangChain, by contrast, gives you extensive freedom no matter what you're building.
Background: The Birth and Rise of LangChain LangChain was created by Harrison Chase in October 2022, just before OpenAI launched ChatGPT. It filled a critical gap: how could developers systematically integrate large language models (LLMs) with external data sources, tools, and complex logic? Before LangChain, developers had to write enormous amounts of "glue code" to handle prompt management, model invocation, result parsing, and other repetitive tasks. LangChain abstracted these patterns into reusable components, quickly becoming one of the fastest-growing open-source projects on GitHub, and in 2023 it closed a $250 million Series B round at a $1 billion valuation.

The Four Core Modules of the LangChain Ecosystem
The modern LangChain ecosystem consists of four major modules. Getting clear on how they divide responsibilities is the essential first step.
LangChain: The Foundation and Core Component Library
LangChain itself plays two roles. First, it serves as the foundational component library for the entire ecosystem, providing the essential capabilities for interacting with LLMs — how to invoke models, how to hold conversations, how to use tools. This foundation supports not only LangChain itself but also higher-level modules like LangGraph and Deep Agents. Second, it offers a chain-based approach for building complex applications, though this pattern is used relatively less frequently today.
LangGraph: A Stateful Workflow Orchestration Engine
LangGraph is a stateful workflow orchestration engine built on top of the core component library. It combines those foundational components to build applications capable of handling complex business logic. Many people have historically treated LangChain and LangGraph as two separate frameworks to be learned independently, but in reality they are deeply intertwined — you cannot truly master LangGraph without LangChain as its foundation.
Deep Dive: The Graph Theory Behind LangGraph LangGraph draws its design inspiration from directed graph theory, modeling workflows as a combination of Nodes and Edges. Each node represents a processing step (such as calling an LLM, executing a tool, or updating state), while edges define the transition conditions between nodes — including Conditional Edges for implementing branching logic. Unlike traditional DAGs (Directed Acyclic Graphs), LangGraph supports Cycles, which is critical for agent tasks that require repeated iteration — for example, having a model keep trying until it reaches a satisfactory result. Its core innovation is the introduction of Persistent State: every node can read from and write to a shared state during execution, which is the technical foundation for multi-step complex reasoning.
Concept Clarified: The Essential Difference Between Agent and Chain A Chain represents a deterministic, linear or conditionally branching execution flow — the developer decides the order of every step at code-writing time, much like a traditional chain of function calls. An Agent introduces autonomy: the LLM acts as the "brain," dynamically deciding at runtime which tool to call next and whether to continue iterating until the task is complete. This paradigm is called ReAct (Reasoning + Acting), proposed by Google DeepMind in 2022 and the theoretical foundation of modern agent architectures. The core loop is: Think → Act → Observe → Think Again. This enables agents to tackle open-ended, multi-step tasks that Chains simply cannot handle.
Deep Agents: An Advanced Suite for Autonomous Planning
Deep Agents is a module introduced after LangChain's 1.X major version, designed for modern, high-level autonomous agent scenarios. Its most fundamental difference from LangChain/LangGraph lies in how tasks are planned: LangChain/LangGraph requires the developer to plan the entire business flow in advance, whereas Deep Agents lets the LLM plan the task itself. This is exactly the core characteristic of modern agents like Manus, Claude Code, and Codex — all the basic capabilities (browsing the web, reading files, etc.) are provided, but how the task is handled is left entirely to the model's judgment.
Industry Context: The Technical Wave of Autonomous Agents Deep Agents corresponds to the industry's latest exploration of "fully autonomous agents." Representative products include Manus (developed by the Chinese team at Monica), which attracted widespread attention in 2024, as well as Anthropic's Claude Code and OpenAI's Codex/Operator. The technical architecture of these systems typically includes three elements: long-context planning (leveraging LLMs' extended context for multi-step task decomposition), computer use capabilities (such as Anthropic's browser/desktop control API released in October 2024), and persistent sandbox environments (providing agents with stable code execution and file read/write environments). Unlike LangGraph's predefined flows, the workflows of these systems are entirely dynamically emergent — their reliability and controllability remain core research challenges in both academia and engineering.
LangSmith: The Production Operations Platform
LangSmith provides LLM applications with engineering capabilities including trace logging, debugging, evaluation, and operations monitoring. If you're just building a simple demo you may not need it — but for a serious production product, you need to know where problems occur, examine logs to diagnose failures, evaluate model performance, and monitor live behavior. These are all essential capabilities for shipping a real product.
Industry Concept: LLMOps and LangSmith's Position LangSmith represents LLMOps (Large Language Model Operations), an emerging engineering discipline analogous to DevOps and MLOps in traditional software engineering. Debugging LLM applications differs fundamentally from traditional software: model outputs are probabilistic, meaning the same input can yield different outputs; errors are often not code bugs but prompt design issues; performance bottlenecks may lie in network latency, token consumption, or some step in the tool-calling chain. LangSmith uses distributed tracing technology to visually present the complete trace of every LLM call — including input prompts, model parameters, outputs, latency, and token consumption. This lets developers pinpoint "ghost problems" in LLM applications the same way they'd debug a traditional API, making it indispensable infrastructure for production-grade AI applications.

Version Evolution: Key Changes from 0.3 to 1.3
This article focuses on the latest 1.3 version. From 0.3 to 1.3, the most significant changes are at the API level, while the core architectural thinking has changed little. This explains why developers familiar with 0.3 find the migration to 1.3 remarkably smooth.
Rapidly changing APIs were one of LangChain's most criticized pain points — a version bump could force a complete code rewrite, causing significant frustration. The good news is that the team has committed to no major API breaking changes starting from the official 1.0 release, signaling that the framework has reached mature stability. This makes investing deeply in learning the current APIs far more worthwhile.
That said, here's a pragmatic suggestion: it's okay if you're not fully fluent in every API — you can always have an AI generate the code for you. But you must internalize the architectural thinking yourself. Without that, you won't even know how to describe your requirements to an AI, and whatever you build will be more luck than skill.
Hands-On: Building Your First Agent from Hello World
Rather than an extended theoretical preamble, let's just build something and run it. The entire process revolves around a few core components.
A Unified Way to Access LLMs
LangChain provides a unified way to access all mainstream LLMs through init_chat_model, with the key parameter being model_provider. LangChain has built-in support for major providers including OpenAI, DeepSeek, Google Gemini, and Anthropic.
Since accessing OpenAI directly from mainland China can be difficult, this tutorial uses Alibaba Cloud's Bailian platform with the Tongyi Qianwen model, redirecting to Alibaba Cloud's OpenAI-compatible endpoint via base_url. This also showcases one of LangChain's great strengths — switching between different LLMs is extremely simple, requiring only a few parameter changes. If you have network access to OpenAI, simply remove the base_url and swap in your API key for a seamless switch.
It's worth noting that the Tongyi Qianwen series is currently supported through the community-maintained langchain-community package (e.g., the ChatTongyi component) and has not yet been officially incorporated into LangChain core. Community packages may occasionally have version compatibility issues, but they work fine at present. A more stable approach is to use the ChatOpenAI component directly, pointing its base_url at Alibaba Cloud — this is equally compatible.

Tools: Extending the Boundaries of What LLMs Can Do
LLMs can only work with their training data. For real-time information like "what's today's date?" they're helpless. Tools are the key to filling these gaps. Take a get_current_date function as an example: simply add a description and a tool decorator to an ordinary Python function, and the LLM can recognize and call it.
Technical Internals: How Function Calling Works Tool-calling capability (also known as Function Calling) was first introduced by OpenAI in June 2023 with the GPT-4 update. At its core, it's a capability specifically reinforced during model training to produce "structured output tool-call instructions." When a developer passes the tool's name, description, and parameter Schema (in JSON Schema format) to the model alongside the prompt, the model doesn't answer directly — instead, it outputs a structured JSON payload declaring "I need to call function XX with parameters XX." The application parses this JSON, actually executes the function, and returns the result to the model. This mechanism transforms the model's "imagined execution" into real external operations, and is the critical bridge connecting LLMs to the real world. Anthropic, Google, Alibaba, Baidu, and other major model providers all now support compatible Function Calling formats.
At the low level, the interaction involves several message types: the user's question is a HumanMessage, and the model's reply is an AIMessage. When the model determines it needs to call a tool, the AIMessage's content is empty but contains a tool_calls section specifying which function to invoke. The tool's execution result is packaged as a ToolMessage and returned to the model, which synthesizes everything to produce the final answer.
Agent: Encapsulating Complex Interaction Flows
With a model and tools in place, you can create an Agent. An agent created with create_agent internally contains both the model and its tools, with all intermediate invocation logic fully encapsulated. When you ask "what's today's date?", the agent will automatically plan, call the appropriate tool, process the result, and return the correct answer — you don't need to think about any of the steps in between.
Three Essential Supporting Components
Beyond the core Agent building blocks, LangChain provides several highly practical utilities.
Prompt Templates (ChatPromptTemplate)
Prompts are the only entry point for interacting with an LLM. ChatPromptTemplate uses curly-brace variables to templatize system instructions and user messages. For example, setting up "Translate the content from English into {language}" and passing in Chinese, German, or French as the parameter generates different complete prompts. This means an application only needs to accept a few fixed business parameters from the outside world — a pattern that closely resembles traditional application development.

Short-Term Memory (Checkpoint)
Short-term memory enables the LLM to understand conversational context. If you first ask "what's today's date?" and then ask "what about tomorrow?", the model with short-term memory can infer you're asking about tomorrow's date rather than, say, tomorrow's weather. In LangChain, you simply pass an InMemorySaver checkpointer when building the agent, and all the work of consolidating the conversation history is handled automatically — no manual message list management required.
Architectural Extension: Short-Term vs. Long-Term Memory Memory systems in AI applications are typically divided into two layers: short-term memory (In-Context Memory) and long-term memory (External Memory). Short-term memory is LangChain's Checkpoint mechanism — it stores conversation history directly in the model's context window by appending the history message list to every request's prompt. This approach is fast and simple to implement, but is limited by the model's context length (e.g., GPT-4o's 128K token context window), and early content gets truncated when conversations grow too long. Long-term memory relies on external storage, typically using vector databases (such as Pinecone or Chroma) for semantic retrieval — historical information is stored as vectors and relevant excerpts are retrieved via similarity search and injected into the context when needed. LangChain provides abstract support for both approaches through its Memory module, allowing developers to choose flexibly based on application scale and memory retention requirements.
Conclusion: Grasp the Thinking, Not Just the APIs
Through this introductory hands-on walkthrough, we've experienced the core value of LangChain as an AI Agent application framework: it provides all the foundational components for interfacing with LLMs (Model, Tools, Prompt, Checkpoint), and the essence of building agents going forward is assembling these building blocks into complete applications.
More importantly, understand the multiple architectural approaches LangChain offers — chain-based structure, stateful workflow orchestration, and autonomous planning. Only by grasping the differences between these approaches will you know, during top-level architectural design, which one to reach for when pursuing a given goal. This is also the fundamental answer to the dilemma of "never being able to keep up with new versions": the deeper you go into the underlying architectural thinking, the easier it becomes to follow along as new versions arrive.
Key Takeaways
Related articles

The Truth Behind Codex 'Build a Website in 5 Minutes': AI Isn't Creating Sites—It's Helping You Copy Them
Exposing the truth behind viral Codex 5-minute website videos: creators aren't building original sites with AI—they're copying shared prompts or scraping others' work. Learn AI coding tools' real limits.

Getting Started with AI Agent Development: A Complete Guide from Concept to Practice
A comprehensive guide to AI Agent architecture and development, covering automated marketing, intelligent customer service, and investment analysis scenarios with single and multi-agent collaboration.

The Truth Behind Codex 'Build a Website in 5 Minutes': AI Isn't Creating Sites — It's Helping You Copy Them
Exposing the truth behind viral Codex 5-minute website videos: creators aren't building original sites with AI — they're copying shared prompts or scraping others' work.