How langchain-ai/langchain works
LangChain is a Python framework for composing interoperable LLM applications and agents. The principal workflow is an application invoking a model through a standard interface and receiving generated text or messages; larger applications can add agent orchestration, tools, retrieval, and data augmentation. Core abstractions live in langchain_core, while the repository also includes classic and newer agent packages and provider integrations. Some subsystem links below are documented capabilities rather than inspected call paths; those are marked dashed with no evidence path.
Main entry points: language_models/base.py Model interface · llms.py Text LLMs · runnables/base.py Runnable workflows · factory.py Agent orchestration
Components 21
Composition
- Runnable workflows
libs/core/langchain_core/runnables/base.py - Prompt templates
libs/core/langchain_core/prompts - Output parsing
libs/core/langchain_core/output_parsers
Models
- Model interface
libs/core/langchain_core/language_models/base.py - Chat models
libs/core/langchain_core/language_models/chat_models.py - Text LLMs
libs/core/langchain_core/language_models/llms.py - Model results
libs/core/langchain_core/outputs
Data and retrieval
- Documents
libs/core/langchain_core/documents/base.py - Document loaders
libs/core/langchain_core/document_loaders - Text splitting
libs/text-splitters/langchain_text_splitters - Embeddings
libs/core/langchain_core/embeddings/embeddings.py - Vector stores
libs/core/langchain_core/vectorstores/base.py - Retrievers
libs/core/langchain_core/retrievers.py
Agent capabilities
- Agent orchestration
libs/langchain_v1/langchain/agents/factory.py - Agent middleware
libs/langchain_v1/langchain/agents/middleware/types.py - Classic agents
libs/langchain/langchain_classic/agents/agent.py - Tools and toolkits
libs/core/langchain_core/tools/base.py
Observability and integrations
- Provider integrations
libs/partners - Callback managers
libs/core/langchain_core/callbacks/manager.py - LangSmith tracing
libs/core/langchain_core/tracers/langchain.py
Other components
- Application developer
Connections 19
- Application developer → Runnable workflows: composes
- Application developer → Model interface: invokes
- Model interface → Chat models: specializes
- Model interface → Text LLMs: specializes
libs/core/langchain_core/language_models/llms.py - Text LLMs → Model results: returns
libs/core/langchain_core/language_models/llms.py - Text LLMs → Callback managers: configures
libs/core/langchain_core/language_models/llms.py - Text LLMs → Runnable workflows: implements
libs/core/langchain_core/language_models/llms.py - Runnable workflows → Prompt templates: composes
- Runnable workflows → Output parsing: composes
- Provider integrations → Model interface: implements
- Document loaders → Documents: produces
- Documents → Text splitting: transforms
- Embeddings → Vector stores: indexes
- Vector stores → Retrievers: retrieves
- Agent orchestration → Agent middleware: applies
- Agent orchestration → Model interface: uses
- Agent orchestration → Tools and toolkits: uses
- Classic agents → Tools and toolkits: uses
- Callback managers → LangSmith tracing: dispatches
libs/core/langchain_core/callbacks/manager.py