惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
博客园_首页
H
Help Net Security
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
The Cloudflare Blog
腾讯CDC
Jina AI
Jina AI
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
爱范儿
爱范儿
N
Netflix TechBlog - Medium
F
Fortinet All Blogs

Towards AI

Building AI Agents in Rust — part 4 | Towards AI Building AI Agents in Rust — part 5 | Towards AI The Verified Identity Agent Bridge | Towards AI You Can’t Prompt Your Away Your LLM Problems | Towards AI The Free Agent Trap | Towards AI Your Agentic Loop Will Drift. Here Is the KL Divergence Equation That Measures How Far It Has Wandered From Its Original Instruction. | Towards AI Beyond Chat: Processing Images, PDFs, and Documents with the OpenAI Adapter in Oracle Integration Cloud | Towards AI Building AI Agents in Rust — part 3 | Towards AI Self-Hosting Airflow at Home: Automating Stock Price Data Collection | Towards AI The 76-Hour Frontier: How the Takedown of Claude Fable 5 Birthed the Military-Industrial-AI Complex | Towards AI I Trained a Markdown File to Boost GPT-5.5 by 23 Points — It Shouldn't Work | Towards AI We Replaced ChatGPT With a Local AI Server. Six Months of Honest Data. | Towards AI What Really Makes Cars Pollute? A Data Science Deep Dive into CO₂ Emissions | Towards AI Training GPT-2 From Scratch on a GTX1050 | Towards AI Principal Component Analysis (PCA): Theory, Mathematics, and Applications Build a Zero-Cost Web Automation Pipeline With OpenRouter, OpenClaw, and MediaUse I Gave Qwen3.7-Plus a Screenshot and It Found the Exact Pixel to Click for $0.40 Beyond the Prompt: Why Autonomous AI Agents Are Replacing the Chatbot Moonshot Cracked Claude Code’s Playbook with an MIT Terminal Agent and a $0.60 Model Connections, Roles, and Warehouses: Getting CoCo Desktop Production-Ready from Day One My First $5,000 Month Writing About AI Engineering on Medium Google Shrank Gemma 4 by 72% and Unsloth Fixed the 4-Bit Bug Nobody Else Caught on One 4090, and 4-Bit Shouldn’t Be This Good TOON: Beyond JSON for LLMs Claude Code Casual, Pro, Elite: The Three Working Personas of Claude Code Mastery MiniMax M3 Decodes 1M Tokens 15x Faster — and It Shouldn’t Be This Cheap Using Amazon SQS for AI Agent Orchestration I Ran a 1.5B-Active Model on My Laptop That Embarrassed a 26B by 46 Points How to Build a Self-Improving Company with AI Part 3 — Implementation/Engine-Level: Choosing the Runtime That Gives You These for Free Part 2 — Serve-Level Speed: System Design That Stabilizes P95/P99
LangChain Explained: Understanding Models, Prompts, Chain...
Editorial Team · 2026-06-08 · via Towards AI

Author(s): Atul Kumar

Originally published on Towards AI.

LangChain Explained: Understanding Models, Prompts, Chains, Memory, Indexes, and Agents

Large Language Models (LLMs) such as GPT, Gemini, and Claude have made it easier than ever to build intelligent applications. However, developing production-ready AI systems often requires much more than simply calling an API.

This is where LangChain comes in

In this article, we’ll explore the core components of LangChain and understand why they are important.

Introduction to Langchain :

LangChain is an open-source framework that simplifies the development of applications powered by Large Language Models. It provides a collection of components that help developers connect LLMs with external data, memory, tools, and workflows.

Benefits of LangChain:

1. Model Agnostic

LangChain provides a unified interface for different LLM providers such as OpenAI, Gemini, and Claude. This makes it easier to switch models without rewriting large portions of code.

2. Reusable Prompt Templates

Instead of hardcoding prompts, developers can create dynamic and reusable prompt templates, improving maintainability and scalability.

3. Simplified AI Workflows

Chains allow multiple operations to be connected, making complex workflows easier to build and manage.

4. Context-Aware Applications

Memory enables applications to remember previous interactions, creating more natural and personalized user experiences.

5. Efficient Knowledge Retrieval

Indexes and vector databases allow applications to retrieve relevant information from large datasets, improving response accuracy.

6. Autonomous Decision Making

Agents can dynamically decide which tools or actions to use, enabling the development of intelligent AI systems.

7. Faster Development

LangChain provides ready-to-use components, reducing development time and allowing developers to focus on application logic rather than infrastructure.

What Can We Build Using LangChain?

1. AI Chatbots

Build conversational assistants capable of answering questions and maintaining context throughout a conversation.

2. Customer Support Systems

Create intelligent support agents that can access company knowledge bases and provide accurate responses.

3. Retrieval-Augmented Generation (RAG) Applications

Build systems that retrieve information from documents and use LLMs to generate context-aware answers.

4. Document Question-Answering Systems

Allow users to upload PDFs, research papers, or reports and ask questions about their contents.

5. AI Agents

Develop autonomous agents that can use tools, APIs, databases, and search engines to complete tasks.

6. Personal AI Assistants

Create assistants that manage schedules, answer questions, summarize information, and perform actions on behalf of users.

7. Content Generation Tools

Generate blogs, social media posts, emails, reports, and marketing content automatically.

8. Recommendation Systems

Use embeddings and semantic search to recommend products, articles, courses, or videos.

9. Research Assistants

Build AI systems that search, summarize, and analyze information from multiple sources.

10. Multi-Agent Systems

Create multiple specialized agents that collaborate to solve complex problems and automate workflows.

Components Of LangChain:-

LangChain Components

1. Models

Models are the core interfaces through which we interact with AI models. It is one of the core building blocks of a LangChain application.

Problem:
Different AI providers, such as Anthropic, OpenAI, and Google Gemini, use different SDKs and API formats. If you write code directly for one provider, switching to another often requires changing significant parts of your code.

Solution:
LangChain’s Model abstraction provides a common interface for interacting with different LLMs. Instead of writing provider-specific code, we write against LangChain’s standardized API.

Models In LangChain

2. Prompts

A Prompt is the fundamental text input or instruction provided to a Large Language Model (LLM).

Problem:

LLMs perform best when prompts are well — structured properly. But hardcoding prompts every time can lead to:

  • Repeated code
  • Inconsistent outputs
  • Difficult maintenance

Solution:

The Prompt component in LangChain provides reusable and dynamic templates that insert user inputs into predefined instructions before sending them to the model.

Prompting Techniques:

  1. Dynamic Prompting: Prompt changes based on user input or variable.
Example of Dynamic Prompting

Use Case: Personalised responses, Chatbots, AI Applications.

2. Role-Based Prompting: Assign a role or persona to the model.

Example of Role based Prompting

Use Case: Expert Advice, Tutoring, Coding Assistance.

3. Few-Shot Prompting: It provides an example so the model learns the desired pattern and generates the desired output for a new input.

Example of Few-Shot Prompting

Use Case: Classification, Extraction, Formatting Tasks.

3. Chains

A Chain in LangChain connects individual components like prompts, LLMs, and output parsers into a seamless, automated workflow.

Let Say,

NLP Pipeline

We can represent the flow using pipelines; if not, we have to manually take the output of one and push it as input to another

Problem:

Many GenAI applications require multiple steps, not just a single Large Language Model (LLM) call. Without chains, we would have had to manually connect all the steps.

Solution:

Chains connect multiple LangChain components into a single workflow, in which the output of one component becomes the input to the next.

Types of Chains:

  1. Sequential Chain: Steps executed one after another.
  2. Parallel Chain: Multiple tasks run simultaneously.
  3. RAG Chain: Most common in Industry( Chat with PDF, Company Knowledge base)
Types Of Chains

4. Memory

Problem:

By Default, “LLM API calls are stateless” means they do not remember previous conversations.

Solution:

Memory stores conversation history or important information and automatically provides it to the LLM when needed.

How Memory Works?

Working of Memory

Types of Memory:

  1. Conversation Buffer Memory: Stores the entire conversation. Simple, but becomes large over time. Best for short conversations and prototyping.
Conversation Buffer Memory

2. Conversation Buffer Window Memory: Limit memory to only the last K messages. Best for maintaining the recent conversational context while keeping the token usage predictable and preventing the context window from overflowing.

3. Summarize Based Memory: Periodically summarize older chat segments to keep a condensed memory footprint.

4. Custom Memory: For advanced use cases, we can store specialized state, e.g., the user's preference or key facts about them, in a common memory class

💡Key Takeaway: Choose the right memory type based on your use case, conversation length, and token limit to build an efficient and context-aware AI application.

5. Indexes

Indexes in LangChain connect your application to external Knowledge, such as PDFs, websites, or databases.

Problem:

LLM has a limited context window and can not directly search through thousands of documents, PDFs, websites, and databases efficiently.

Solution:

Indexes organize and structure data so that relevant information can be found quickly and provided to the LLM when needed.

Components of Index:

Index Components
  1. Data Loader: Load data from different sources.
  2. Text Splitter: Large documents are broken into smaller chunks.
10 pages pdf ---- convert to -----> 10 chunks (1chunk/page)

Why?
-LLM context Limit.
-Better reterival accuracy.

3. Embedding Model: Convert text into vectors (numerical representation), and these vectors capture the semantic meaning of that text.

"MACHINE LEARNING" ----> [0.23,0.81,0.45,...]
( TEXT) (Vector)

Retrieval Flow:

Retrieval flow

6. Agents

Problem:

A normal LLM or chain follows a fixed workflow

Example: 

User Question ---> Prompt ---> LLM ---> Answer

But What if AI needs to --
1. Search the web
2. Query a Database
3. Call an API

We do not always know beforehand which tool will be needed

Solution:

An Agent is an AI system that has the capabilities of reasoning, deciding, and choosing the appropriate tool to complete a task.

Chain VS Agent

Final Thoughts:

LangChain has become one of the most popular frameworks in the Generative AI ecosystem because it simplifies the process of building intelligent applications. By providing components such as Models, Prompts, Chains, Memory, Indexes, and Agents, it enables developers to move beyond simple chatbot interactions and create powerful real-world AI solutions.

Understanding these core components is the first step toward building advanced applications such as AI assistants, RAG systems, and autonomous agents. As the AI landscape continues to evolve, frameworks like LangChain will play an important role in helping developers create scalable and production-ready AI systems.

Thank you for reading! If you found this article helpful, consider sharing it and following me on Medium for more content on Generative AI and Machine Learning

Connect with me on LinkedIn:

https://www.linkedin.com/in/atulkumar8/

Published via Towards AI