LangChain is a comprehensive framework for building applications powered by large language models (LLMs), transforming simple prompts into production-ready AI agents. With the v1.0 release in October 2025, it has been streamlined around three pillars: create_agent (the new standard agent builder), middleware (composable hooks for customization), and standard content blocks (provider-agnostic message content). LangChain abstracts the complexity of chaining LLM calls, managing memory, integrating tools, and orchestrating retrieval-augmented generation (RAG) pipelines, while LangGraph (stateful graph workflows) and LangSmith (observability) complete the ecosystem. A critical mental model: every component implements the Runnable interface (invoke, stream, batch), and legacy functionality now lives in the separate langchain-classic package.
What This Cheat Sheet Covers
This topic spans 22 focused tables and 169 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Components
| Component | Example | Description |
|---|---|---|
ChatOpenAI(model="gpt-4o")ChatAnthropic(model="claude-3-5-sonnet") | β’ Unified wrappers for conversational LLMs from OpenAI, Anthropic, Google, and more β’ returns structured AIMessage objects with metadata | |
from langchain.chat_models import init_chat_modelllm = init_chat_model("openai:gpt-4o")llm = init_chat_model("anthropic:claude-3-5-sonnet") | β’ Unified model initialization via provider:model string β no provider-specific import neededβ’ supports fully configurable runtime model selection via config["configurable"]β’ recommended v1.0 pattern for provider-agnostic code | |
OpenAIEmbeddings()HuggingFaceEmbeddings() | β’ Convert text to vectors for semantic search β’ used with vector stores; supports batch processing for efficiency | |
PromptTemplate(template="Answer: {question}")ChatPromptTemplate.from_messages([...]) | β’ Templating system for dynamic prompt construction β’ supports f-string syntax, Jinja2, and chat message formatting | |
JsonOutputParser()PydanticOutputParser(pydantic_object=MyModel) | β’ Extract structured data from LLM text responses β’ handles JSON, Pydantic models, lists, and custom formats with validation | |
chain.invoke(input)chain.stream(input)chain.batch([inputs]) | β’ Unified execution protocol for all LangChain components β’ enables invoke (single), stream (tokens), batch (multiple), and async variants |