LangChain - LLM Applications with Agents & RAG
The most popular framework for building LLM-powered applications.
When to Use
- Building agents with tool calling and reasoning (ReAct pattern)
- Implementing RAG (retrieval-augmented generation) pipelines
- Need to swap LLM providers easily (OpenAI, Anthropic, Google)
- Creating chatbots with conversation memory
- Rapid prototyping of LLM applications
Core Components
| Component |
Purpose |
Key Concept |
| Chat Models |
LLM interface |
Unified API across providers |
| Agents |
Tool use + reasoning |
ReAct pattern |
| Chains |
Sequential operations |
Composable pipelines |
| Memory |
Conversation state |
Buffer, summary, vector |
| Retrievers |
Document lookup |
Vector search, hybrid |
| Tools |
External capabilities |
Functions agents can call |
Agent Patterns
| Pattern |
Description |
Use Case |
| ReAct |
Reason-Act-Observe loop |
General tool use |
| Plan-and-Execute |
Plan first, then execute |
Complex multi-step |
| Self-Ask |
Generate sub-questions |
Research tasks |
| Structured Chat |
JSON tool calling |
API integration |
Tool Definition
| Element |
Purpose |
| Name |
How agent refers to tool |
| Description |
When to use (critical for selection) |
| Parameters |
Input schema |
| Return type |
What agent receives back |
Key concept: Tool descriptions are critical—the LLM uses them to decide which tool to call. Be specific about when and why to use each tool.
RAG Pipeline Stages
| Stage |
Purpose |
Options |
| Load |
Ingest documents |
Web, PDF, GitHub, DBs |
| Split |
Chunk into pieces |
Recursive, semantic |
| Embed |
Convert to vectors |
OpenAI, Cohere, local |
| Store |
Index vectors |
Chroma, FAISS, Pinecone |
| Retrieve |
Find relevant chunks |
Similarity, MMR, hybrid |
| Generate |
Create response |
LLM with context |
Chunking Strategies
| Strategy |
Best For |
Typical Size |
| Recursive |
General text |
500-1000 chars |
| Semantic |
Coherent passages |
Variable |
| Token-based |
LLM context limits |
256-512 tokens |
Retrieval Strategies
| Strategy |
How It Works |
| Similarity |
Nearest neighbors by embedding |
| MMR |
Diversity + relevance balance |
| Hybrid |
Keyword + semantic combined |
| Self-query |
LLM generates metadata filters |
Memory Types
| Type |
Stores |
Best For |
| Buffer |
Full conversation |
Short conversations |
| Window |
Last N messages |
Medium conversations |
| Summary |
LLM-generated summary |
Long conversations |
| Vector |
Embedded messages |
Semantic recall |
| Entity |
Extracted entities |
Track facts about people/things |
Key concept: Buffer memory grows unbounded. Use summary or vector for long conversations to stay within context limits.
Document Loaders
| Source |
Loader Type |
| Web pages |
WebBaseLoader, AsyncChromium |
| PDFs |
PyPDFLoader, UnstructuredPDF |
| Code |
GitHubLoader, DirectoryLoader |
| Databases |
SQLDatabase, Postgres |
| APIs |
Custom loaders |
Vector Stores
| Store |
Type |
Best For |
| Chroma |
Local |
Development, small datasets |
| FAISS |
Local |
Large local datasets |
| Pinecone |
Cloud |
Production, scale |
| Weaviate |
Self-hosted/Cloud |
Hybrid search |
| Qdrant |
Self-hosted/Cloud |
Filtering, metadata |
LangSmith Observability
| Feature |
Benefit |
| Tracing |
See every LLM call, tool use |
| Evaluation |
Test prompts systematically |
| Datasets |
Store test cases |
| Monitoring |
Track production performance |
Key concept: Enable LangSmith tracing early—debugging agents without observability is extremely difficult.
Best Practices
| Practice |
Why |
| Start simple |
create_agent() covers most cases |
| Enable streaming |
Better UX for long responses |
| Use LangSmith |
Essential for debugging |
| Optimize chunk size |
500-1000 chars typically works |
| Cache embeddings |
They're expensive to compute |
| Test retrieval separately |
RAG quality depends on retrieval |
LangChain vs LangGraph
| Aspect |
LangChain |
LangGraph |
| Best for |
Quick agents, RAG |
Complex workflows |
| Code to start |
<10 lines |
~30 lines |
| State management |
Limited |
Native |
| Branching logic |
Basic |
Advanced |
| Human-in-loop |
Manual |
Built-in |
Key concept: Use LangChain for straightforward agents and RAG. Use LangGraph when you need complex state machines, branching, or human checkpoints.
Resources
1---
2name: langchain-agents
3description: Use when "LangChain", "LLM chains", "ReAct agents", "tool calling", or asking about "RAG pipelines", "conversation memory", "document QA", "agent tools", "LangSmith"
4version: 1.0.0
5metadata:
6 source: https://skillmd.com/skills/eyadsibai/langchain-agents
7---
8
9# LangChain - LLM Applications with Agents & RAG
10
11The most popular framework for building LLM-powered applications.
12
13## When to Use
14
15- Building agents with tool calling and reasoning (ReAct pattern)
16- Implementing RAG (retrieval-augmented generation) pipelines
17- Need to swap LLM providers easily (OpenAI, Anthropic, Google)
18- Creating chatbots with conversation memory
19- Rapid prototyping of LLM applications
20
21---
22
23## Core Components
24
25| Component | Purpose | Key Concept |
26|-----------|---------|-------------|
27| **Chat Models** | LLM interface | Unified API across providers |
28| **Agents** | Tool use + reasoning | ReAct pattern |
29| **Chains** | Sequential operations | Composable pipelines |
30| **Memory** | Conversation state | Buffer, summary, vector |
31| **Retrievers** | Document lookup | Vector search, hybrid |
32| **Tools** | External capabilities | Functions agents can call |
33
34---
35
36## Agent Patterns
37
38| Pattern | Description | Use Case |
39|---------|-------------|----------|
40| **ReAct** | Reason-Act-Observe loop | General tool use |
41| **Plan-and-Execute** | Plan first, then execute | Complex multi-step |
42| **Self-Ask** | Generate sub-questions | Research tasks |
43| **Structured Chat** | JSON tool calling | API integration |
44
45### Tool Definition
46
47| Element | Purpose |
48|---------|---------|
49| **Name** | How agent refers to tool |
50| **Description** | When to use (critical for selection) |
51| **Parameters** | Input schema |
52| **Return type** | What agent receives back |
53
54**Key concept**: Tool descriptions are critical—the LLM uses them to decide which tool to call. Be specific about when and why to use each tool.
55
56---
57
58## RAG Pipeline Stages
59
60| Stage | Purpose | Options |
61|-------|---------|---------|
62| **Load** | Ingest documents | Web, PDF, GitHub, DBs |
63| **Split** | Chunk into pieces | Recursive, semantic |
64| **Embed** | Convert to vectors | OpenAI, Cohere, local |
65| **Store** | Index vectors | Chroma, FAISS, Pinecone |
66| **Retrieve** | Find relevant chunks | Similarity, MMR, hybrid |
67| **Generate** | Create response | LLM with context |
68
69### Chunking Strategies
70
71| Strategy | Best For | Typical Size |
72|----------|----------|--------------|
73| **Recursive** | General text | 500-1000 chars |
74| **Semantic** | Coherent passages | Variable |
75| **Token-based** | LLM context limits | 256-512 tokens |
76
77### Retrieval Strategies
78
79| Strategy | How It Works |
80|----------|--------------|
81| **Similarity** | Nearest neighbors by embedding |
82| **MMR** | Diversity + relevance balance |
83| **Hybrid** | Keyword + semantic combined |
84| **Self-query** | LLM generates metadata filters |
85
86---
87
88## Memory Types
89
90| Type | Stores | Best For |
91|------|--------|----------|
92| **Buffer** | Full conversation | Short conversations |
93| **Window** | Last N messages | Medium conversations |
94| **Summary** | LLM-generated summary | Long conversations |
95| **Vector** | Embedded messages | Semantic recall |
96| **Entity** | Extracted entities | Track facts about people/things |
97
98**Key concept**: Buffer memory grows unbounded. Use summary or vector for long conversations to stay within context limits.
99
100---
101
102## Document Loaders
103
104| Source | Loader Type |
105|--------|-------------|
106| **Web pages** | WebBaseLoader, AsyncChromium |
107| **PDFs** | PyPDFLoader, UnstructuredPDF |
108| **Code** | GitHubLoader, DirectoryLoader |
109| **Databases** | SQLDatabase, Postgres |
110| **APIs** | Custom loaders |
111
112---
113
114## Vector Stores
115
116| Store | Type | Best For |
117|-------|------|----------|
118| **Chroma** | Local | Development, small datasets |
119| **FAISS** | Local | Large local datasets |
120| **Pinecone** | Cloud | Production, scale |
121| **Weaviate** | Self-hosted/Cloud | Hybrid search |
122| **Qdrant** | Self-hosted/Cloud | Filtering, metadata |
123
124---
125
126## LangSmith Observability
127
128| Feature | Benefit |
129|---------|---------|
130| **Tracing** | See every LLM call, tool use |
131| **Evaluation** | Test prompts systematically |
132| **Datasets** | Store test cases |
133| **Monitoring** | Track production performance |
134
135**Key concept**: Enable LangSmith tracing early—debugging agents without observability is extremely difficult.
136
137---
138
139## Best Practices
140
141| Practice | Why |
142|----------|-----|
143| Start simple | `create_agent()` covers most cases |
144| Enable streaming | Better UX for long responses |
145| Use LangSmith | Essential for debugging |
146| Optimize chunk size | 500-1000 chars typically works |
147| Cache embeddings | They're expensive to compute |
148| Test retrieval separately | RAG quality depends on retrieval |
149
150---
151
152## LangChain vs LangGraph
153
154| Aspect | LangChain | LangGraph |
155|--------|-----------|-----------|
156| **Best for** | Quick agents, RAG | Complex workflows |
157| **Code to start** | <10 lines | ~30 lines |
158| **State management** | Limited | Native |
159| **Branching logic** | Basic | Advanced |
160| **Human-in-loop** | Manual | Built-in |
161
162**Key concept**: Use LangChain for straightforward agents and RAG. Use LangGraph when you need complex state machines, branching, or human checkpoints.
163
164## Resources
165
166- Docs: <https://docs.langchain.com>
167- LangSmith: <https://smith.langchain.com>
168- Templates: <https://github.com/langchain-ai/langchain/tree/master/templates>