# langchain-ai/rag-research-agent-template architecture

> Architecture diagram of the GitHub repository langchain-ai/rag-research-agent-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/langchain-ai/rag-research-agent-template
- Repository: https://github.com/langchain-ai/rag-research-agent-template

## Overview

This is a LangGraph RAG research-agent template with separate document-indexing and conversational-retrieval graphs. Indexing accepts documents (or configured sample documents) and adds them to a selected vector store. For questions, the retrieval graph classifies intent, requests clarification or declines out-of-scope questions, or creates a research plan; its researcher subgraph generates parallel search queries, retrieves documents, and returns them for a context-grounded response. Configuration, prompts, and shared document state support these workflows. Relationships follow the README and shown call sites; external model and vector-store connections are represented at the integration boundary.

Main entry points: [`src/retrieval_graph/graph.py`](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/graph.py) (Retrieval graph), [`src/shared/retrieval.py`](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/retrieval.py) (Retriever factory), [`src/index_graph/graph.py`](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/graph.py) (Index graph), [`src/retrieval_graph/researcher_graph/graph.py`](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/researcher_graph/graph.py) (Researcher graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_indexing["Document indexing"]
  node_index_graph["Index graph<br/>[graph.py]"]
  node_index_config["Index settings<br/>[configuration.py]"]
  node_index_state["Index state<br/>[state.py]"]
end

subgraph group_conversation["Conversation workflow"]
  node_retrieval_graph["Retrieval graph<br/>[graph.py]"]
  node_agent_config["Agent settings<br/>[configuration.py]"]
  node_prompts["Agent prompts<br/>[prompts.py]"]
  node_agent_state["Conversation state<br/>[state.py]"]
end

subgraph group_research["Research subgraph"]
  node_query_researcher["Researcher graph<br/>[graph.py]"]
  node_research_state["Research state<br/>[state.py]"]
end

subgraph group_shared["Shared services"]
  node_retriever_factory["Retriever factory<br/>[retrieval.py]"]
  node_base_config["Base configuration<br/>[configuration.py]"]
  node_document_reducer["Document reducer<br/>[state.py]"]
  node_model_loader["Chat model loader<br/>[utils.py]"]
  node_doc_formatter["Document formatter<br/>[utils.py]"]
end

node_user(("User"))
node_document_source["Document source"]
node_chat_model{{"Chat model provider"}}
node_embedding_provider{{"Embedding provider"}}
node_elasticsearch[("Elasticsearch")]
node_pinecone[("Pinecone")]
node_mongodb[("MongoDB Atlas")]

node_document_source -->|"supplies documents"| node_index_graph
node_index_graph -->|"adds documents"| node_retriever_factory
node_index_graph -->|"loads settings"| node_index_config
node_index_graph -->|"normalizes sample docs"| node_document_reducer
node_index_state -->|"reduces documents"| node_document_reducer
node_user -->|"submits query"| node_retrieval_graph
node_retrieval_graph -->|"maintains conversation"| node_agent_state
node_retrieval_graph -->|"loads settings"| node_agent_config
node_agent_config -->|"uses defaults"| node_prompts
node_retrieval_graph -->|"loads models"| node_model_loader
node_model_loader -->|"initializes"| node_chat_model
node_retrieval_graph -->|"invokes per plan step"| node_query_researcher
node_query_researcher -->|"uses research state"| node_research_state
node_query_researcher -->|"loads query model"| node_model_loader
node_query_researcher -->|"retrieves documents"| node_retriever_factory
node_retrieval_graph -->|"formats retrieved context"| node_doc_formatter
node_retrieval_graph -->|"reduces documents"| node_document_reducer
node_research_state -->|"reduces documents"| node_document_reducer
node_retriever_factory -->|"resolves settings"| node_base_config
node_retriever_factory -->|"creates embeddings"| node_embedding_provider
node_retriever_factory -->|"configures retriever"| node_elasticsearch
node_retriever_factory -->|"configures retriever"| node_pinecone
node_retriever_factory -->|"configures retriever"| node_mongodb
node_index_graph -->|"loads sample fallback"| node_document_source

click node_index_graph "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/graph.py"
click node_index_config "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/configuration.py"
click node_index_state "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/state.py"
click node_retrieval_graph "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/graph.py"
click node_agent_config "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/configuration.py"
click node_prompts "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/prompts.py"
click node_agent_state "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/state.py"
click node_query_researcher "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/researcher_graph/graph.py"
click node_research_state "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/researcher_graph/state.py"
click node_retriever_factory "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/retrieval.py"
click node_base_config "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/configuration.py"
click node_document_reducer "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/state.py"
click node_model_loader "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/utils.py"
click node_doc_formatter "https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/utils.py"

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_index_graph,node_index_config,node_index_state,node_user toneBlue
class node_retrieval_graph,node_agent_config,node_prompts,node_agent_state,node_elasticsearch,node_pinecone,node_mongodb toneAmber
class node_query_researcher,node_research_state toneMint
class node_retriever_factory,node_base_config,node_document_reducer,node_model_loader,node_doc_formatter toneRose
class node_document_source,node_chat_model,node_embedding_provider toneIndigo
```

## Components

### Document indexing

- [Index graph](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/graph.py): `src/index_graph/graph.py`
- [Index settings](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/configuration.py): `src/index_graph/configuration.py`
- [Index state](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/index_graph/state.py): `src/index_graph/state.py`

### Conversation workflow

- [Retrieval graph](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/graph.py): `src/retrieval_graph/graph.py`
- [Agent settings](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/configuration.py): `src/retrieval_graph/configuration.py`
- [Agent prompts](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/prompts.py): `src/retrieval_graph/prompts.py`
- [Conversation state](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/state.py): `src/retrieval_graph/state.py`

### Research subgraph

- [Researcher graph](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/researcher_graph/graph.py): `src/retrieval_graph/researcher_graph/graph.py`
- [Research state](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/retrieval_graph/researcher_graph/state.py): `src/retrieval_graph/researcher_graph/state.py`

### Shared services

- [Retriever factory](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/retrieval.py): `src/shared/retrieval.py`
- [Base configuration](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/configuration.py): `src/shared/configuration.py`
- [Document reducer](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/state.py): `src/shared/state.py`
- [Chat model loader](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/utils.py): `src/shared/utils.py`
- [Document formatter](https://github.com/langchain-ai/rag-research-agent-template/blob/main/src/shared/utils.py): `src/shared/utils.py`

### Other components

- **User**
- **Document source**
- **Chat model provider**
- **Embedding provider**
- **Elasticsearch**
- **Pinecone**
- **MongoDB Atlas**

## Connections

- Document source → Index graph: supplies documents (evidence: `README.md`)
- Index graph → Retriever factory: adds documents (evidence: `src/index_graph/graph.py`)
- Index graph → Index settings: loads settings (evidence: `src/index_graph/graph.py`)
- Index graph → Document reducer: normalizes sample docs (evidence: `src/index_graph/graph.py`)
- Index state → Document reducer: reduces documents (evidence: `src/index_graph/state.py`)
- User → Retrieval graph: submits query (evidence: `README.md`)
- Retrieval graph → Conversation state: maintains conversation (evidence: `src/retrieval_graph/graph.py`)
- Retrieval graph → Agent settings: loads settings (evidence: `src/retrieval_graph/graph.py`)
- Agent settings → Agent prompts: uses defaults (evidence: `src/retrieval_graph/configuration.py`)
- Retrieval graph → Chat model loader: loads models (evidence: `src/retrieval_graph/graph.py`)
- Chat model loader → Chat model provider: initializes (evidence: `src/shared/utils.py`)
- Retrieval graph → Researcher graph: invokes per plan step (evidence: `src/retrieval_graph/graph.py`)
- Researcher graph → Research state: uses research state (evidence: `src/retrieval_graph/researcher_graph/graph.py`)
- Researcher graph → Chat model loader: loads query model (evidence: `src/retrieval_graph/researcher_graph/graph.py`)
- Researcher graph → Retriever factory: retrieves documents (evidence: `src/retrieval_graph/researcher_graph/graph.py`)
- Retrieval graph → Document formatter: formats retrieved context (evidence: `src/retrieval_graph/graph.py`)
- Retrieval graph → Document reducer: reduces documents
- Research state → Document reducer: reduces documents (evidence: `src/retrieval_graph/researcher_graph/state.py`)
- Retriever factory → Base configuration: resolves settings (evidence: `src/shared/retrieval.py`)
- Retriever factory → Embedding provider: creates embeddings (evidence: `src/shared/retrieval.py`)
- Retriever factory → Elasticsearch: configures retriever (evidence: `src/shared/retrieval.py`)
- Retriever factory → Pinecone: configures retriever (evidence: `src/shared/retrieval.py`)
- Retriever factory → MongoDB Atlas: configures retriever (evidence: `src/shared/retrieval.py`)
- Index graph → Document source: loads sample fallback (evidence: `README.md`)
