# rishabh-108272/langchain architecture

> Architecture diagram of the GitHub repository rishabh-108272/langchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishabh-108272/langchain
- Repository: https://github.com/rishabh-108272/langchain

## Overview

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: [`libs/core/langchain_core`](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core) (Core Primitives), [`libs/langchain/langchain_classic/chains`](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/chains) (Chains), [`libs/langchain/langchain_classic/agents`](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/agents) (Agents), [`libs/langchain_v1/langchain/agents`](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/agents) (Agent Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core"]
  node_node_core_primitives["Core Primitives"]
  node_node_core_runnables["Runnables<br/>execution graph"]
  node_node_core_callbacks["Callbacks<br/>telemetry hooks"]
  node_node_core_tracers["Tracers<br/>observability"]
  node_node_core_security["Security<br/>policy helpers"]
end

subgraph group_group_classic["Classic LangChain"]
  node_node_classic_chains["Chains<br/>workflow orchestration"]
  node_node_classic_agents["Agents<br/>classic agent runtime"]
  node_node_classic_prompts["Prompts<br/>prompting"]
  node_node_classic_ingest["Ingestion<br/>document pipeline"]
  node_node_classic_retrieval["Retrieval<br/>search and compression"]
  node_node_classic_storage["Storage"]
  node_node_classic_models["Models<br/>provider adapters"]
  node_node_classic_eval["Eval"]
end

subgraph group_group_v1["LangChain v1"]
  node_node_v1_agents["Agent Runtime<br/>agent engine"]
  node_node_v1_middleware["Middleware<br/>control layer"]
  node_node_v1_tools["Tool Node<br/>tool execution"]
  node_node_v1_models["V1 Models<br/>runtime adapters"]
end

subgraph group_group_partners["Partners"]
  node_node_partners_models["Partner Models<br/>provider packages"]
  node_node_partners_retrieval["Partner Retrieval<br/>provider extensions"]
end

subgraph group_group_support["Support"]
  node_node_profiles["Model Profiles<br/>capability metadata"]
  node_node_standard_tests["Standard Tests<br/>conformance suite"]
  node_node_text_splitters["Text Splitters<br/>chunking utilities"]
  node_node_repo_tooling["Repo Tooling<br/>build and CI<br/>[workflows]"]
end

node_node_core_primitives -->|"foundation"| node_node_core_runnables
node_node_core_primitives -->|"events"| node_node_core_callbacks
node_node_core_primitives -->|"runs"| node_node_core_tracers
node_node_core_primitives -->|"policy"| node_node_core_security
node_node_classic_ingest -->|"documents"| node_node_core_primitives
node_node_text_splitters -->|"chunks"| node_node_classic_ingest
node_node_classic_retrieval -->|"retrieves"| node_node_core_primitives
node_node_classic_storage -->|"stores"| node_node_core_primitives
node_node_classic_models -->|"models"| node_node_core_primitives
node_node_classic_prompts -->|"templates"| node_node_core_primitives
node_node_classic_chains -->|"ingest"| node_node_classic_ingest
node_node_classic_chains -->|"retrieve"| node_node_classic_retrieval
node_node_classic_chains -->|"run"| node_node_classic_models
node_node_classic_chains -->|"prompt"| node_node_classic_prompts
node_node_classic_chains -->|"memory"| node_node_classic_storage
node_node_classic_agents -->|"act"| node_node_classic_models
node_node_classic_agents -->|"scratchpad"| node_node_classic_prompts
node_node_classic_agents -->|"compose"| node_node_classic_chains
node_node_v1_agents -->|"control"| node_node_v1_middleware
node_node_v1_agents -->|"execute"| node_node_v1_models
node_node_v1_agents -->|"tools"| node_node_v1_tools
node_node_v1_middleware -->|"guard"| node_node_v1_tools
node_node_v1_models -->|"shared types"| node_node_core_primitives
node_node_partners_models -->|"adapts"| node_node_core_primitives
node_node_partners_retrieval -->|"adapts"| node_node_core_primitives
node_node_partners_models -->|"profiles"| node_node_profiles
node_node_profiles -->|"sync"| node_node_repo_tooling
node_node_standard_tests -->|"verify"| node_node_core_primitives
node_node_standard_tests -->|"verify"| node_node_partners_models
node_node_standard_tests -->|"verify"| node_node_partners_retrieval
node_node_core_callbacks -->|"stream"| node_node_core_tracers

click node_node_core_primitives "https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core"
click node_node_core_runnables "https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/runnables"
click node_node_core_callbacks "https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/callbacks"
click node_node_core_tracers "https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/tracers"
click node_node_core_security "https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/_security"
click node_node_classic_chains "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/chains"
click node_node_classic_agents "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/agents"
click node_node_classic_prompts "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/prompts"
click node_node_classic_ingest "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/document_loaders"
click node_node_classic_retrieval "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/retrievers"
click node_node_classic_storage "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/vectorstores"
click node_node_classic_models "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/chat_models"
click node_node_classic_eval "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/evaluation"
click node_node_v1_agents "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/agents"
click node_node_v1_middleware "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/agents/middleware"
click node_node_v1_tools "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/tools"
click node_node_v1_models "https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/chat_models"
click node_node_partners_models "https://github.com/rishabh-108272/langchain/tree/master/libs/partners/openai/langchain_openai"
click node_node_partners_retrieval "https://github.com/rishabh-108272/langchain/tree/master/libs/partners/qdrant/langchain_qdrant"
click node_node_profiles "https://github.com/rishabh-108272/langchain/tree/master/libs/model-profiles/langchain_model_profiles"
click node_node_standard_tests "https://github.com/rishabh-108272/langchain/tree/master/libs/standard-tests/langchain_tests"
click node_node_text_splitters "https://github.com/rishabh-108272/langchain/tree/master/libs/text-splitters/langchain_text_splitters"
click node_node_repo_tooling "https://github.com/rishabh-108272/langchain/blob/master/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_core_primitives,node_node_core_runnables,node_node_core_callbacks,node_node_core_tracers,node_node_core_security toneBlue
class node_node_classic_chains,node_node_classic_agents,node_node_classic_prompts,node_node_classic_ingest,node_node_classic_retrieval,node_node_classic_storage,node_node_classic_models,node_node_classic_eval toneAmber
class node_node_v1_agents,node_node_v1_middleware,node_node_v1_tools,node_node_v1_models toneMint
class node_node_partners_models,node_node_partners_retrieval toneRose
class node_node_profiles,node_node_standard_tests,node_node_text_splitters,node_node_repo_tooling toneIndigo
```

## Components

### Core

Provider-agnostic primitives and execution infrastructure.

- [Core Primitives](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core): package · Messages, prompts, documents, outputs, embeddings, models, tools, retrievers, vector stores, stores, caches, and security helpers. · `libs/core/langchain_core`
- [Runnables](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/runnables): execution graph · Composable runnable/graph abstractions, routing, retry, fallback, history, and config. · `libs/core/langchain_core/runnables`
- [Callbacks](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/callbacks): telemetry hooks · Callback managers and event hooks for streaming, usage, and lifecycle observation. · `libs/core/langchain_core/callbacks`
- [Tracers](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/tracers): observability · Run collection, event streams, evaluation hooks, and tracing backends. · `libs/core/langchain_core/tracers`
- [Security](https://github.com/rishabh-108272/langchain/tree/master/libs/core/langchain_core/_security): policy helpers · SSRF protection, transport policy, and related safety controls. · `libs/core/langchain_core/_security`

### Classic LangChain

Legacy high-level orchestration, integrations, and workflows.

- [Chains](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/chains): workflow orchestration · Classic chain compositions such as retrieval QA, summarization, routing, and combine-documents flows. · `libs/langchain/langchain_classic/chains`
- [Agents](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/agents): classic agent runtime · Legacy agent constructors, output parsers, scratchpads, and agent toolkits. · `libs/langchain/langchain_classic/agents`
- [Prompts](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/prompts): prompting · Prompt templates, few-shot selection, loading, and prompt utilities. · `libs/langchain/langchain_classic/prompts`
- [Ingestion](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/document_loaders): document pipeline · Document loaders, transformers, text splitters, and chat loaders that prepare raw content for indexing. · `libs/langchain/langchain_classic/document_loaders`
- [Retrieval](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/retrievers): search and compression · Retriever implementations plus document compressors and retrieval wrappers. · `libs/langchain/langchain_classic/retrievers`
- [Storage](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/vectorstores): state and index storage · Vector stores, memory, docstore, and storage backends used by classic workflows. · `libs/langchain/langchain_classic/vectorstores`
- [Models](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/chat_models): provider adapters · Classic chat models, LLMs, and embeddings adapters for many providers. · `libs/langchain/langchain_classic/chat_models`
- [Eval](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain/langchain_classic/evaluation): evaluation · Classic evaluation chains and Smith-oriented evaluation helpers. · `libs/langchain/langchain_classic/evaluation`

### LangChain v1

New agent runtime with middleware-driven execution.

- [Agent Runtime](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/agents): agent engine · New agent construction and execution runtime. · `libs/langchain_v1/langchain/agents`
- [Middleware](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/agents/middleware): control layer · 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](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/tools): tool execution · Tool-node wiring for the v1 agent runtime. · `libs/langchain_v1/langchain/tools`
- [V1 Models](https://github.com/rishabh-108272/langchain/tree/master/libs/langchain_v1/langchain/chat_models): runtime adapters · 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](https://github.com/rishabh-108272/langchain/tree/master/libs/partners/openai/langchain_openai): provider packages · 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](https://github.com/rishabh-108272/langchain/tree/master/libs/partners/qdrant/langchain_qdrant): provider extensions · 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](https://github.com/rishabh-108272/langchain/tree/master/libs/model-profiles/langchain_model_profiles): capability metadata · Model profile summaries and CLI for keeping provider capability metadata in sync. · `libs/model-profiles/langchain_model_profiles`
- [Standard Tests](https://github.com/rishabh-108272/langchain/tree/master/libs/standard-tests/langchain_tests): conformance suite · Reusable test harnesses that verify chat models, embeddings, tools, retrievers, vector stores, caches, and stores across packages. · `libs/standard-tests/langchain_tests`
- [Text Splitters](https://github.com/rishabh-108272/langchain/tree/master/libs/text-splitters/langchain_text_splitters): chunking utilities · Standalone chunking and segmentation utilities for ingestion and indexing. · `libs/text-splitters/langchain_text_splitters`
- [Repo Tooling](https://github.com/rishabh-108272/langchain/blob/master/.github/workflows): build and CI · Package-level pyproject/uv workflows, GitHub Actions, prerelease checks, linting, and release automation. · `.github/workflows`

## Connections

- 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.
