LangChain

A Python and JavaScript framework for building applications powered by large language models — providing abstractions for chains, agents, memory, and retrieval-augmented generation.

LangChain is an open-source framework that provides building blocks for LLM applications. Rather than calling OpenAI's API directly and wiring everything by hand, LangChain gives you composable abstractions: chains (sequences of LLM calls), agents (LLMs that choose which tools to call), memory (state across turns), and retrievers (fetch relevant documents).

Core Abstractions

  • LLMs / Chat Models — unified interface to OpenAI, Anthropic, Ollama, and 50+ others
  • Prompts / Prompt Templates — parameterized System Prompt and message templates
  • Chains — pipe an LLM call into another call or tool (LLMChain, SequentialChain)
  • Agents — an LLM that iteratively decides which tool to call based on observations
  • Tools — functions the agent can invoke (web search, calculator, SQL query)
  • Memory — save and load conversation history
  • Retrievers / VectorStores — semantic search over documents for RAG

LangGraph

LangGraph is LangChain's framework for building stateful, cyclical agent workflows — think state machines for AI agents. While LangChain handles linear pipelines, LangGraph handles loops: "try this, check if it worked, if not branch and retry." It's the tool of choice for production-grade agent systems that need reliability and observability.

Common Patterns

RAG (Retrieval-Augmented Generation): Load documents → embed them → store in vector DB → at query time, retrieve relevant chunks → pass to LLM with the question. LangChain has built-in components for every step.

Conversational Agent: Define tools (search, calculator, DB lookup) → give the LLM a System Prompt that explains the tools → use an agent executor that runs the observe-think-act loop.

MCP Integration

LangChain can consume Mcp Model Context Protocol servers as tool sources, making it easy to add MCP-compatible tools to any agent built with LangChain without custom integration work.

Criticisms and Alternatives

LangChain is often criticized for over-abstraction — simple tasks require navigating many layers of indirection, and the API has changed frequently. For straightforward RAG or single-chain tasks, many teams prefer calling the LLM SDK directly. LangGraph specifically has found wider acceptance for complex agents. Alternatives include LlamaIndex (focused on RAG), DSPy (programmatic prompt optimization), and Mcp Model Context Protocol for tool integration.

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon