LangChain is built as a modular Python monorepo with a clear separation of concerns across multiple layers. This architecture enables both flexibility and stability while supporting a rich ecosystem of integrations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/langchain-ai/langchain/llms.txt
Use this file to discover all available pages before exploring further.
Monorepo Structure
The LangChain project is organized into independently versioned packages:Package Dependencies
Each package maintains its ownpyproject.toml and dependency specifications. The dependency flow is:
- Partners depend on Core
- LangChain depends on Core
- Core has minimal third-party dependencies
The
langchain-core package intentionally keeps dependencies lightweight to serve as a stable foundation. No third-party integrations are defined in core.Layered Architecture
LangChain uses a three-layer architecture that separates abstractions from implementations:Core Layer (langchain-core)
Defines base abstractions, interfaces, and protocols that all components implement:
- Runnable: Universal invocation protocol
- BaseLanguageModel: Language model interface
- BaseMessage: Message types for chat interactions
- BaseTool: Tool interface for agent actions
- BasePromptTemplate: Prompt template system
- BaseOutputParser: Output parsing interface
- Serializable: Serialization support
/libs/core/langchain_core/
Implementation Layer (langchain)
Provides concrete implementations and high-level utilities:
- Pre-built chains and agent patterns
- Memory systems for stateful applications
- Document loaders and transformers
- Utilities for common workflows
/libs/langchain_v1/langchain/
Integration Layer (Partners)
Third-party service integrations as separate packages:- Lives in its own versioned package
- Depends only on
langchain-core - Implements core abstractions
- May be maintained in this monorepo or external repositories
/libs/partners/*/
Extension Points
LangChain provides multiple extension mechanisms to customize behavior:1. Custom Runnables
Extend theRunnable protocol to create composable components:
- Async support (
ainvoke,astream,abatch) - Streaming capabilities
- Batch processing
- Composition with
|operator
/libs/core/langchain_core/runnables/base.py:124
2. Tool Development
Create custom tools by extendingBaseTool:
/libs/core/langchain_core/tools/base.py:289
3. Custom Language Models
Implement custom LLM wrappers:/libs/core/langchain_core/language_models/chat_models.py
4. Callbacks and Tracing
Hook into the execution lifecycle:/libs/core/langchain_core/callbacks/base.py
Plugin Lifecycle
Components in LangChain follow a consistent lifecycle:1. Initialization
Components are initialized with configuration:2. Configuration
Runtime configuration throughRunnableConfig:
/libs/core/langchain_core/runnables/config.py:49:
tags: For filtering and categorizationmetadata: JSON-serializable contextcallbacks: Lifecycle hooksrun_name: Custom tracer namemax_concurrency: Parallel execution limit
3. Invocation
Components expose standard invocation methods:4. Composition
Components compose using the pipe operator:5. Serialization
Components can be serialized for storage and versioning:/libs/core/langchain_core/load/serializable.py:88
Development Tools
The monorepo uses modern Python tooling:- uv: Fast package installer and resolver
- ruff: Linting and formatting
- mypy: Static type checking
- pytest: Testing framework
- make: Task automation
Common Development Commands
Common Development Commands
Package Management
Each package in/libs/ has:
pyproject.toml: Package metadata and dependenciesuv.lock: Locked dependency versions- Independent versioning and release cycle
[tool.uv.sources] configuration.
Testing Strategy
LangChain uses a layered testing approach:- Unit tests (
tests/unit_tests/): No network calls, fast feedback - Integration tests (
tests/integration_tests/): Real API calls - Standard tests (
libs/standard-tests/): Shared test suite for integrations
Next Steps
Runnables
Learn about the universal invocation protocol
Messages
Understand message types and structure
Tools
Build custom tools for agents
Agents
Create autonomous agent systems