LangChain Components
Complete reference for the LangChain ecosystem — models, agents, tools, retrieval, memory, middleware, streaming, multi-agent orchestration, LangGraph workflows, Deep Agents, and provider integrations for Python 3.10+.
Component Index
Models & Output
- Models — Chat models, tool calling, multimodal inputs, caching, rate limiting, custom models reference
- Messages — Message types (Human, AI, System, Tool), message operations, serialization, OpenAI format conversion reference
Agents
- Agents — create_agent, tools, structured output, guardrails, human-in-the-loop, context engineering reference
- Multi-Agent — Subagents, handoffs, skills, router, custom workflows, pattern selection reference
Tools & MCP
- Tools — Tool creation (@tool decorator, ToolNode), InjectedState, MCP integration, error handling reference
Retrieval & RAG
- Retrieval — Document loaders, text splitters, embeddings, vector stores, agentic RAG, semantic search reference
Memory
- Memory — Short-term (checkpointers, message trimming, summarization), long-term (store abstraction, namespaces) reference
Middleware & Streaming
- Middleware — 16 built-in middleware, custom middleware (decorator, class, wrap-style), execution order reference
- Streaming — Stream modes (updates, messages, custom), token streaming, useStream React hook reference
Runtime & Architecture
- Runtime — Dependency injection, context schemas, ToolRuntime, component architecture (5 layers) reference
Testing & Deployment
- Testing — Unit testing (GenericFakeChatModel), integration testing (AgentEvals), LangSmith observability reference
LangGraph
- LangGraph Core — Graph API, Functional API, workflows vs agents, state management, quickstart reference
- LangGraph State — Memory, persistence, durable execution, interrupts, checkpointers reference
- LangGraph Advanced — Subgraphs, time-travel, streaming, Graph API usage, Functional API usage reference
Deep Agents
- Deep Agents — Harness framework, models, subagents, skills, sandboxes, human-in-the-loop, long-term memory reference
Integrations
- Integrations — Chat models, document loaders, retrievers, embeddings, vector stores, tools, stores, splitters reference
- Providers — OpenAI, Anthropic, Google, AWS, Ollama setup and configuration reference
Quick Patterns
Create an Agent with Tools
from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_agent
model = init_chat_model("anthropic:claude-sonnet-4-20250514")
def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Sunny, 72F in {city}"
agent = create_agent(model, [get_weather])
response = agent.invoke(
{"messages": [{"role": "user", "content": "What's the weather in SF?"}]}
)
Structured Output
from pydantic import BaseModel
class SearchQuery(BaseModel):
query: str
year: int
structured_model = model.with_structured_output(SearchQuery)
result = structured_model.invoke("Who won the World Cup in 2022?")
RAG with Retrieval
from langchain_community.document_loaders import WebBaseLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_openai import OpenAIEmbeddings
from langchain_core.vectorstores import InMemoryVectorStore
docs = WebBaseLoader("https://example.com").load()
chunks = RecursiveCharacterTextSplitter(chunk_size=1000).split_documents(docs)
vector_store = InMemoryVectorStore.from_documents(chunks, OpenAIEmbeddings())
retriever_tool = vector_store.as_retriever()
Multi-Agent Handoffs
from langgraph.prebuilt import create_agent
billing_agent = create_agent(model, [lookup_billing], name="billing")
tech_agent = create_agent(model, [check_status], name="tech_support")
supervisor = create_agent(
model,
[billing_agent, tech_agent],
prompt="Route to the appropriate specialist."
)
LangGraph Workflow
from langgraph.graph import StateGraph, START, END
graph = StateGraph(dict)
graph.add_node("process", process_fn)
graph.add_node("review", review_fn)
graph.add_edge(START, "process")
graph.add_edge("process", "review")
graph.add_edge("review", END)
app = graph.compile()
Streaming
for chunk in agent.stream(
{"messages": [{"role": "user", "content": "Hello"}]},
stream_mode="messages"
):
print(chunk)
Best Practices
- Use
init_chat_model() for provider-agnostic model initialization
- Prefer
create_agent over building custom agent loops
- Use LangGraph for complex workflows requiring state, persistence, or human-in-the-loop
- Apply middleware for cross-cutting concerns (guardrails, rate limiting, PII detection)
- Use checkpointers for conversation persistence and short-term memory
- Use the Store abstraction for long-term memory across conversations
- Choose the right multi-agent pattern: handoffs for specialization, routers for classification, subagents for parallel work
- Use
with_structured_output() for type-safe LLM responses
- Prefer agentic RAG (tool-based retrieval) over chain-based RAG for flexibility
- Use
stream_mode="messages" for token-level streaming to frontends
1---2name: langchain-components3description: Comprehensive reference for the LangChain ecosystem including LangChain, LangGraph, and Deep Agents for Python 3.10+. Use when the user asks to build AI agents, implement RAG pipelines, configure chat models, create tool-calling agents, set up retrieval chains, manage conversation memory, orchestrate multi-agent workflows, or integrate with LLM providers (OpenAI, Anthropic, Google). Covers models, messages, output parsers, vector stores, embedding strategies, streaming, middleware, and LangGraph state machines.4---56# LangChain Components78Complete reference for the LangChain ecosystem — models, agents, tools, retrieval, memory, middleware, streaming, multi-agent orchestration, LangGraph workflows, Deep Agents, and provider integrations for Python 3.10+.910## Component Index1112### Models & Output13- **Models** — Chat models, tool calling, multimodal inputs, caching, rate limiting, custom models [reference](references/models.md)14- **Messages** — Message types (Human, AI, System, Tool), message operations, serialization, OpenAI format conversion [reference](references/messages.md)1516### Agents17- **Agents** — create_agent, tools, structured output, guardrails, human-in-the-loop, context engineering [reference](references/agents.md)18- **Multi-Agent** — Subagents, handoffs, skills, router, custom workflows, pattern selection [reference](references/multi-agent.md)1920### Tools & MCP21- **Tools** — Tool creation (@tool decorator, ToolNode), InjectedState, MCP integration, error handling [reference](references/tools.md)2223### Retrieval & RAG24- **Retrieval** — Document loaders, text splitters, embeddings, vector stores, agentic RAG, semantic search [reference](references/retrieval.md)2526### Memory27- **Memory** — Short-term (checkpointers, message trimming, summarization), long-term (store abstraction, namespaces) [reference](references/memory.md)2829### Middleware & Streaming30- **Middleware** — 16 built-in middleware, custom middleware (decorator, class, wrap-style), execution order [reference](references/middleware.md)31- **Streaming** — Stream modes (updates, messages, custom), token streaming, useStream React hook [reference](references/streaming.md)3233### Runtime & Architecture34- **Runtime** — Dependency injection, context schemas, ToolRuntime, component architecture (5 layers) [reference](references/runtime.md)3536### Testing & Deployment37- **Testing** — Unit testing (GenericFakeChatModel), integration testing (AgentEvals), LangSmith observability [reference](references/testing.md)3839### LangGraph40- **LangGraph Core** — Graph API, Functional API, workflows vs agents, state management, quickstart [reference](references/langgraph-core.md)41- **LangGraph State** — Memory, persistence, durable execution, interrupts, checkpointers [reference](references/langgraph-state.md)42- **LangGraph Advanced** — Subgraphs, time-travel, streaming, Graph API usage, Functional API usage [reference](references/langgraph-advanced.md)4344### Deep Agents45- **Deep Agents** — Harness framework, models, subagents, skills, sandboxes, human-in-the-loop, long-term memory [reference](references/deep-agents.md)4647### Integrations48- **Integrations** — Chat models, document loaders, retrievers, embeddings, vector stores, tools, stores, splitters [reference](references/integrations.md)49- **Providers** — OpenAI, Anthropic, Google, AWS, Ollama setup and configuration [reference](references/providers.md)5051## Quick Patterns5253### Create an Agent with Tools5455```python56from langchain.chat_models import init_chat_model57from langgraph.prebuilt import create_agent5859model = init_chat_model("anthropic:claude-sonnet-4-20250514")6061def get_weather(city: str) -> str:62 """Get weather for a city."""63 return f"Sunny, 72F in {city}"6465agent = create_agent(model, [get_weather])66response = agent.invoke(67 {"messages": [{"role": "user", "content": "What's the weather in SF?"}]}68)69```7071### Structured Output7273```python74from pydantic import BaseModel7576class SearchQuery(BaseModel):77 query: str78 year: int7980structured_model = model.with_structured_output(SearchQuery)81result = structured_model.invoke("Who won the World Cup in 2022?")82```8384### RAG with Retrieval8586```python87from langchain_community.document_loaders import WebBaseLoader88from langchain_text_splitters import RecursiveCharacterTextSplitter89from langchain_openai import OpenAIEmbeddings90from langchain_core.vectorstores import InMemoryVectorStore9192docs = WebBaseLoader("https://example.com").load()93chunks = RecursiveCharacterTextSplitter(chunk_size=1000).split_documents(docs)94vector_store = InMemoryVectorStore.from_documents(chunks, OpenAIEmbeddings())95retriever_tool = vector_store.as_retriever()96```9798### Multi-Agent Handoffs99100```python101from langgraph.prebuilt import create_agent102103billing_agent = create_agent(model, [lookup_billing], name="billing")104tech_agent = create_agent(model, [check_status], name="tech_support")105supervisor = create_agent(106 model,107 [billing_agent, tech_agent],108 prompt="Route to the appropriate specialist."109)110```111112### LangGraph Workflow113114```python115from langgraph.graph import StateGraph, START, END116117graph = StateGraph(dict)118graph.add_node("process", process_fn)119graph.add_node("review", review_fn)120graph.add_edge(START, "process")121graph.add_edge("process", "review")122graph.add_edge("review", END)123app = graph.compile()124```125126### Streaming127128```python129for chunk in agent.stream(130 {"messages": [{"role": "user", "content": "Hello"}]},131 stream_mode="messages"132):133 print(chunk)134```135136## Best Practices137138- Use `init_chat_model()` for provider-agnostic model initialization139- Prefer `create_agent` over building custom agent loops140- Use LangGraph for complex workflows requiring state, persistence, or human-in-the-loop141- Apply middleware for cross-cutting concerns (guardrails, rate limiting, PII detection)142- Use checkpointers for conversation persistence and short-term memory143- Use the Store abstraction for long-term memory across conversations144- Choose the right multi-agent pattern: handoffs for specialization, routers for classification, subagents for parallel work145- Use `with_structured_output()` for type-safe LLM responses146- Prefer agentic RAG (tool-based retrieval) over chain-based RAG for flexibility147- Use `stream_mode="messages"` for token-level streaming to frontends