
The sections below expand each building block in the order you’ll typically encounter them when designing a LangChain system.
- Model I/O (LLMs and Embeddings)
- What it is: Wrappers and interfaces for language models (text generation/completion) and embedding models (vector encodings).
- Role: Provide natural language generation, completions, and semantic embeddings used for tasks like RAG (retrieval-augmented generation) and similarity search.
- Typical components:
- LLM provider wrappers (e.g.,
OpenAI, other hosted or self-hosted models) - Embedding APIs and models
- Tokenizer utilities and streaming output handling
- Provider-specific configuration (temperature, max tokens, batching)
- LLM provider wrappers (e.g.,
- Prompts (Prompt Templates and Formatting)
- What it is: Structured templates and utilities for building repeatable prompts.
- Role: Encapsulate prompt patterns, inject variables safely, and enable prompt engineering best practices (reusability, testability).
- Typical components:
PromptTemplateclasses and formatters- Few-shot/example injection helpers and conditioning utilities
- Prompt validation and safety checks
- Chains (Composable Workflows)
- What it is: Sequences or graphs that compose multiple steps—model calls, retrievals, tool invocations, and business logic.
- Role: Turn atomic operations into higher-level pipelines (e.g., user question → retrieve docs → summarize → respond).
- Typical components:
- Simple sequential chains for linear workflows
- Branching/conditional chains for decision points
- Orchestration utilities for error handling, retries, and parallelism
- Memory (State and Context Management)
- What it is: Mechanisms for persisting conversational or application state between calls to the model.
- Role: Maintain context across multi-turn interactions so LLMs can reference prior exchanges, user preferences, or saved facts.
- Typical components:
- In-memory buffers for short-lived sessions
- Session-based memory for per-user conversations
- Persistent integrations (databases, key-value stores) for long-term memory
- Retrieval (Indexes and Vector Stores)
- What it is: Retrieval systems that provide relevant context—often powered by embeddings and vector similarity search.
- Role: Ground model outputs with external data by augmenting prompts with relevant documents or knowledge snippets (RAG).
- Typical components:
- Vector stores and indexers: FAISS, Weaviate, Pinecone, etc.
- Retriever interfaces and similarity search utilities
- Document loaders and preprocessing/indexing pipelines
- Agents and Tools (Decision-Making & External Actions)
- What it is: Agent frameworks enabling models to select and call external tools or APIs.
- Role: Let models do more than generate text—search, interact with APIs, run code, or perform automated workflows based on model reasoning.
- Typical components:
- Tool wrappers (custom actions, API clients)
- Agent controllers and reasoning patterns (e.g., ReAct)
- Safety, authorization, and sandboxing layers to limit agent actions
These building blocks are designed to be combined into complete applications. A common flow is: create embeddings (Model I/O) → index documents (Retrieval) → compose a retrieval-augmented prompt (Prompts + Chains) → maintain conversation history (Memory) → hand off to an agent when external actions are required.
- Modularity: Each block can be replaced or upgraded independently (swap vector DB, change LLM provider).
- Testability: Smaller, focused components are easier to unit test and validate.
- Maintainability: Clear separation of responsibilities helps manage complexity as features grow.
- Reusability: Standardized prompts, chains, and tools accelerate building new capabilities.
- LangChain documentation: https://python.langchain.com/
- Retrieval & Vector DBs: FAISS (https://github.com/facebookresearch/faiss), Weaviate (https://www.semi.technology/), Pinecone (https://www.pinecone.io/)
- OpenAI: https://platform.openai.com/