How rishabh-108272/langchain works
1. This is a multi-package Python monorepo for the LangChain ecosystem, not a single application. The top-level repo organizes a shared core, a legacy high-level framework, a newer agent runtime, many provider-specific partner packages, plus shared test and tooling packages.
2. libs/core/langchain_core is the foundation layer. It defines the provider-agnostic primitives: messages, prompts, documents, outputs, embeddings interfaces, language model interfaces, tools, retrievers, vector stores, runnables/graphs, tracers, callbacks, serialization/loaders, caching, rate limiting, and security helpers like SSRF protections. Most other packages build on these abstractions.
3. libs/langchain/langchain_classic is the broad “classic” LangChain API surface. It contains higher-level orchestration pieces such as chains, agents, memory, prompt templates, output parsers, document loaders, document transformers, retrievers, vectorstores, tools, and many integrations. Conceptually, it turns the core primitives into reusable application workflows.
4. The data flow in the classic stack is the usual LangChain pipeline: raw inputs or external content are loaded into Document objects, optionally split/transformed, embedded, stored in a vector store or other store, retrieved back through retrievers, then composed into prompts/chains/agents and executed against chat models or LLMs. Results can be post-processed by output parsers and persisted through memory/history components.
5. libs/langchain_v1/langchain is the newer agent runtime. It focuses on agent construction and execution with middleware, structured output, tool nodes, chat models, embeddings, messages, and rate limiters. The agents/middleware subtree is especially important: it represents a control layer for retries, fallback, redaction/PII handling, tool selection, human-in-the-loop, summarization, file search, shell/tool emulation, and call limits.
6. The partner packages under libs/partners/* are thin provider-specific adapters. Examples include OpenAI, Anthropic, Hugging Face, Ollama, Groq, Fireworks, Qdrant, Chroma, DeepSeek, Mistral, Perplexity, XAI, Nomic, Exa, and others. These packages typically implement provider-specific chat models, embeddings, vector stores, retrievers, tools, or utility wrappers while keeping the shared interface defined by core.
7. libs/text-splitters is a standalone utility package for breaking text into chunks. It provides splitters for character, HTML, JSON, JSX, Python, markdown, spaCy, NLTK, and sentence-transformer-based segmentation. This package feeds the ingestion/indexing path used by both classic and v1-style applications.
8. libs/model-profiles is a small support package for model capability metadata. It appears to generate/aggregate model profile summaries and expose a CLI, which other packages use to keep provider/model behavior descriptions in sync.
9. libs/standard-tests is the cross-package conformance suite. It defines reusable test harnesses for chat models, embeddings, tools, retrievers, vector stores, caches, and base stores so that core and partner packages can prove they satisfy the same behavioral contract. Many package-specific integration tests also use recorded cassettes, making external API interactions reproducible.
10. Observability and evaluation are first-class boundaries. Core and classic both have callbacks/tracers, and there are LangSmith-oriented evaluation and tracing modules in the repo. That means execution flows can be instrumented end-to-end: model/tool calls emit events, tracers collect them, and evaluation tooling can score runs or compare outputs.
11. The repo is heavily test-driven and provider-aware. You can see three broad test styles: fast unit tests, integration tests against real services, and compile/cassette tests for interface stability. This is important for the architecture diagram because provider adapters are intentionally isolated and verified at their boundaries rather than being coupled through shared runtime state.
12. Tooling and delivery are managed as a Python ecosystem, not a single build artifact. Each package has its own pyproject.toml and uv.lock, with shared GitHub Actions for linting, version checks, prerelease dependency checks, integration runs, and release automation. The .devcontainer and CI scaffolding indicate a repo optimized for many independently versioned Python distributions.
Main entry points: langchain_core Core Primitives · chains Chains · langchain_classic/agents Agents · langchain/agents Agent Runtime
Components 23
Core
Provider-agnostic primitives and execution infrastructure.
- Core Primitives · Messages, prompts, documents, outputs, embeddings, models, tools, retrievers, vector stores, stores, caches, and security helpers.
libs/core/langchain_core - Runnables · Composable runnable/graph abstractions, routing, retry, fallback, history, and config.
libs/core/langchain_core/runnables - Callbacks · Callback managers and event hooks for streaming, usage, and lifecycle observation.
libs/core/langchain_core/callbacks - Tracers · Run collection, event streams, evaluation hooks, and tracing backends.
libs/core/langchain_core/tracers - Security · SSRF protection, transport policy, and related safety controls.
libs/core/langchain_core/_security
Classic LangChain
Legacy high-level orchestration, integrations, and workflows.
- Chains · Classic chain compositions such as retrieval QA, summarization, routing, and combine-documents flows.
libs/langchain/langchain_classic/chains - Agents · Legacy agent constructors, output parsers, scratchpads, and agent toolkits.
libs/langchain/langchain_classic/agents - Prompts · Prompt templates, few-shot selection, loading, and prompt utilities.
libs/langchain/langchain_classic/prompts - Ingestion · Document loaders, transformers, text splitters, and chat loaders that prepare raw content for indexing.
libs/langchain/langchain_classic/document_loaders - Retrieval · Retriever implementations plus document compressors and retrieval wrappers.
libs/langchain/langchain_classic/retrievers - Storage · Vector stores, memory, docstore, and storage backends used by classic workflows.
libs/langchain/langchain_classic/vectorstores - Models · Classic chat models, LLMs, and embeddings adapters for many providers.
libs/langchain/langchain_classic/chat_models - Eval · Classic evaluation chains and Smith-oriented evaluation helpers.
libs/langchain/langchain_classic/evaluation
LangChain v1
New agent runtime with middleware-driven execution.
- Agent Runtime · New agent construction and execution runtime.
libs/langchain_v1/langchain/agents - Middleware · Retries, fallbacks, redaction, PII handling, tool selection, human-in-the-loop, summarization, shell/file search, and call limits.
libs/langchain_v1/langchain/agents/middleware - Tool Node · Tool-node wiring for the v1 agent runtime.
libs/langchain_v1/langchain/tools - V1 Models · New runtime chat model, embedding, message, and rate-limiter interfaces.
libs/langchain_v1/langchain/chat_models
Partners
Provider-specific adapters built on shared interfaces.
- Partner Models · Provider-specific chat model, LLM, and embedding adapters such as OpenAI, Anthropic, Ollama, Groq, Fireworks, Mistral, Hugging Face, and DeepSeek.
libs/partners/openai/langchain_openai - Partner Retrieval · Provider-specific retrievers, vector stores, and search tools such as Qdrant, Chroma, Exa, Perplexity, and OpenAI integrations.
libs/partners/qdrant/langchain_qdrant
Support
Shared utilities, conformance tests, and repo tooling.
- Model Profiles · Model profile summaries and CLI for keeping provider capability metadata in sync.
libs/model-profiles/langchain_model_profiles - Standard Tests · Reusable test harnesses that verify chat models, embeddings, tools, retrievers, vector stores, caches, and stores across packages.
libs/standard-tests/langchain_tests - Text Splitters · Standalone chunking and segmentation utilities for ingestion and indexing.
libs/text-splitters/langchain_text_splitters - Repo Tooling · Package-level pyproject/uv workflows, GitHub Actions, prerelease checks, linting, and release automation.
.github/workflows
Connections 31
- Core Primitives → Runnables: foundation · Runnable graphs and orchestration build on the shared primitive layer.
- Core Primitives → Callbacks: events · Core emits lifecycle and usage events through callback hooks.
- Core Primitives → Tracers: runs · Tracers observe runs and stream events from the shared runtime.
- Core Primitives → Security: policy · Security helpers guard network and serialization-adjacent behavior.
- Ingestion → Core Primitives: documents · Loaders and transformers materialize core Document and message types.
- Text Splitters → Ingestion: chunks · Splitters feed ingestion and indexing pipelines.
- Retrieval → Core Primitives: retrieves · Retrievers operate on core documents, embeddings, and vector-store abstractions.
- Storage → Core Primitives: stores · Storage layers implement core store and vector-store contracts.
- Models → Core Primitives: models · Classic providers implement shared chat model, LLM, and embedding interfaces.
- Prompts → Core Primitives: templates · Prompt classes compile to the core prompt and message primitives.
- Chains → Ingestion: ingest · Chains consume loaded and transformed documents.
- Chains → Retrieval: retrieve · Retrieval-aware chains query retrievers and compressors.
- Chains → Models: run · Chains execute against chat models and LLMs.
- Chains → Prompts: prompt · Chains assemble prompt templates before model calls.
- Chains → Storage: memory · Chains persist state through memory and storage backends.
- Agents → Models: act · Classic agents plan and call provider models.
- Agents → Prompts: scratchpad · Agents build prompts and scratchpads from shared templates.
- Agents → Chains: compose · Some agent patterns are built from chain-style orchestration.
- Agent Runtime → Middleware: control · Middleware wraps model/tool execution and shapes agent behavior.
- Agent Runtime → V1 Models: execute · The new runtime calls through its own model interfaces.
- Agent Runtime → Tool Node: tools · Agent loops dispatch through the v1 tool node.
- Middleware → Tool Node: guard · Middleware can mediate tool selection, retries, limits, and emulation.
- V1 Models → Core Primitives: shared types · The new runtime still depends on core messages and common abstractions.
- Partner Models → Core Primitives: adapts · Partner packages implement the shared provider-agnostic contracts.
- Partner Retrieval → Core Primitives: adapts · Partner retrieval and vector-store packages extend shared interfaces.
- Partner Models → Model Profiles: profiles · Provider packages consume model profile metadata.
- Model Profiles → Repo Tooling: sync · Profile refresh and checks are driven by repo automation.
- Standard Tests → Core Primitives: verify · Conformance tests validate the core contracts.
- Standard Tests → Partner Models: verify · Standard tests ensure provider packages behave consistently.
- Standard Tests → Partner Retrieval: verify · Standard tests cover retrievers, vector stores, and tools.
- Callbacks → Tracers: stream · Callback events are consumed by tracer implementations.