LangChain — Build LLM-Powered Applications
The most popular framework for building applications with large language models. Chains, agents, RAG, memory, tool use, and integrations with 700+ providers.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 803c3d1a-a47e-474d-8b6c-ea7965f5d00c --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
LangChain is the most widely adopted framework for building applications powered by large language models. It provides abstractions for chains, agents, retrieval-augmented generation (RAG), memory, and tool use, with integrations across 700+ providers.
Developers building chatbots, document Q&A systems, autonomous agents, or any LLM-backed workflow will find LangChain's composable primitives useful. It supports Python and JavaScript/TypeScript.
How it saves time or tokens
LangChain provides pre-built components for common LLM patterns. Instead of writing custom code for retrieval, embedding, vector search, and prompt management, you compose existing modules. This reduces boilerplate and lets you iterate on the application logic rather than the plumbing. The token estimate for this workflow is 500 tokens.
How to use
- Install LangChain via pip or npm.
- Configure your LLM provider (OpenAI, Anthropic, or local models).
- Build a chain or agent by composing retrievers, prompts, and tools.
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model='gpt-4o')
prompt = ChatPromptTemplate.from_messages([
('system', 'You are a helpful assistant.'),
('user', '{input}')
])
chain = prompt | llm
result = chain.invoke({'input': 'Explain RAG in one paragraph.'})
print(result.content)
Example
A minimal RAG pipeline loads documents, splits them into chunks, embeds them into a vector store, and retrieves relevant context at query time. LangChain provides RecursiveCharacterTextSplitter, FAISS vector store integration, and RetrievalQA chain out of the box.
Related on TokRepo
- Multi-agent frameworks — Compare LangChain with other agent orchestration tools
- AI tools for RAG — Browse retrieval-augmented generation tools and workflows
Common pitfalls
- LangChain's abstraction layers can obscure what happens at the LLM level. Read the source when debugging.
- Version churn is real; pin your dependencies and check migration guides between major releases.
- For simple single-call LLM tasks, using the provider SDK directly is often simpler than adding LangChain overhead.
常见问题
LangChain provides the building blocks: LLM wrappers, prompt templates, retrievers, and tools. LangGraph is a separate library that orchestrates those blocks into stateful graphs with cycles, branching, and human-in-the-loop. Use LangChain for components, LangGraph for complex agent flows.
Yes. LangChain integrates with Ollama, llama.cpp, vLLM, and other local inference engines. You can swap the LLM provider without changing your chain or agent logic.
Many companies run LangChain in production. The framework provides LangSmith for observability and tracing, which helps monitor token usage, latency, and errors in deployed applications.
RAG in LangChain involves loading documents, splitting them into chunks, creating embeddings, storing them in a vector database, and retrieving relevant chunks at query time. The RetrievalQA chain combines retrieval with LLM generation in a single call.
LangChain has official libraries for Python (langchain) and JavaScript/TypeScript (langchain-js). Both share similar abstractions but are maintained as separate packages with their own release cycles.
引用来源 (3)
- LangChain GitHub— LangChain integrates with 700+ providers
- LangChain Documentation— LangChain supports chains, agents, RAG, memory, and tool use
- LangSmith Docs— LangSmith provides observability for LangChain applications
来源与感谢
Created by LangChain. Licensed under MIT. langchain-ai/langchain — 100K+ GitHub stars
讨论
相关资产
LangGraph — Build Stateful AI Agents as Graphs
LangChain framework for building resilient, stateful AI agents as graphs. Supports cycles, branching, persistence, human-in-the-loop, and streaming. 28K+ stars.
LangChain4j — LLM Integration for Java
LangChain4j integrates 20+ LLM providers and 30+ vector stores into Java apps. 11.4K+ stars. Unified API, RAG, MCP, Spring Boot. Apache 2.0.
Flowise — Build AI Agents Visually
Flowise is a low-code platform for building AI agents and workflows with drag-and-drop. 51.3K+ GitHub stars. LangChain integration, RAG, multi-agent, self-hosted. Apache 2.0.
llm.c — LLM Training in Simple Raw C/CUDA
Train large language models in pure C and CUDA without any deep learning framework. Created by Andrej Karpathy, llm.c demonstrates that GPT-2 training can be expressed in roughly 1,000 lines of C code.