# amanotooko7/agentrag architecture

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

- Interactive diagram: https://gitdiagram.com/amanotooko7/agentrag
- Repository: https://github.com/amanotooko7/agentrag

## Overview

AgentRAG is a single-question research agent: it plans subquestions, generates retrieval queries, gathers evidence, answers each subquestion, reflects on progress, and either continues, replans, or synthesizes a final answer. Retrieval supports a hybrid Wikipedia path and a documented dense Lilian Weng blog path; a separate dense-only Wikipedia implementation is also present. The graph and node excerpts establish the main orchestration; unsampled blog-retriever wiring is not asserted.

Main entry points: [`V2_Py_project/src/graph.py`](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/graph.py) (Agent graph), [`V2_Py_project/src/nodes.py`](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py) (Progress reflection), [`V2_Py_project/src/prompts.py`](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/prompts.py) (Prompt templates), [`V2_Py_project/src/retriever_of_wiki.py`](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever_of_wiki.py) (Hybrid wiki retriever)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Agent workflow"]
  node_runner["Single-question runner<br/>[main-singleQ.py]"]
  node_graph["Agent graph<br/>[graph.py]"]
  node_planner["Plan and replan<br/>[nodes.py]"]
  node_querygen["Query generation<br/>[nodes.py]"]
  node_tool_dispatch["Retriever tool dispatch<br/>[graph.py]"]
  node_subanswer["Subquestion answering<br/>[nodes.py]"]
  node_reflection["Progress reflection<br/>[nodes.py]"]
  node_synthesis["Final synthesis<br/>[nodes.py]"]
end

subgraph group_retrieval["Evidence retrieval"]
  node_wiki_hybrid["Hybrid wiki retriever"]
  node_wiki_dense["Dense-only wiki retriever"]
  node_blog_retriever["Blog dense retriever<br/>[retriever.py]"]
  node_reranker["Document reranker<br/>[re_ranker.py]"]
end

subgraph group_reasoning["Prompts and state"]
  node_shared_state["Graph state<br/>[state.py]"]
  node_prompt_templates["Prompt templates<br/>[prompts.py]"]
end

subgraph group_data["Knowledge sources"]
  node_wiki_sqlite[("Wikipedia document store")]
  node_wiki_indexes[("Wiki search indexes")]
  node_blog_data[("Blog database")]
end

node_questioner(("Question input"))
node_answer(("Final answer"))

node_questioner -->|"provides question"| node_runner
node_runner -->|"builds and streams"| node_graph
node_graph -->|"starts at"| node_planner
node_graph -->|"routes to"| node_querygen
node_graph -->|"routes to"| node_tool_dispatch
node_graph -->|"routes to"| node_subanswer
node_graph -->|"routes to"| node_reflection
node_graph -->|"routes to"| node_synthesis
node_graph -->|"uses state"| node_shared_state
node_planner -->|"sets plan"| node_querygen
node_querygen -->|"requests retrieval"| node_tool_dispatch
node_tool_dispatch -->|"passes evidence"| node_subanswer
node_subanswer -->|"records answer"| node_reflection
node_reflection -->|"continues"| node_querygen
node_reflection -->|"replans"| node_planner
node_reflection -->|"ends at"| node_synthesis
node_synthesis -->|"produces"| node_answer
node_planner -->|"uses prompts"| node_prompt_templates
node_querygen -->|"uses prompts"| node_prompt_templates
node_subanswer -->|"uses prompts"| node_prompt_templates
node_reflection -->|"uses prompts"| node_prompt_templates
node_synthesis -->|"uses prompts"| node_prompt_templates
node_tool_dispatch -->|"invokes tool"| node_wiki_hybrid
node_wiki_hybrid -->|"reads documents"| node_wiki_sqlite
node_wiki_hybrid -->|"searches indexes"| node_wiki_indexes
node_subanswer -->|"reranks candidates"| node_reranker
node_wiki_dense -->|"reads documents"| node_wiki_sqlite
node_wiki_dense -->|"searches index"| node_wiki_indexes
node_blog_retriever -.->|"retrieves from"| node_blog_data

click node_runner "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/main-singleQ.py"
click node_graph "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/graph.py"
click node_planner "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py"
click node_querygen "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py"
click node_tool_dispatch "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/graph.py"
click node_subanswer "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py"
click node_reflection "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py"
click node_synthesis "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py"
click node_shared_state "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/state.py"
click node_prompt_templates "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/prompts.py"
click node_wiki_hybrid "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever_of_wiki.py"
click node_wiki_dense "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever_of_wiki_dense_search_only.py"
click node_blog_retriever "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever.py"
click node_reranker "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/re_ranker.py"
click node_blog_data "https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/DB/LilianWeng_Three_blogs_DB.pkl"

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_runner,node_graph,node_planner,node_querygen,node_tool_dispatch,node_subanswer,node_reflection,node_synthesis toneBlue
class node_wiki_hybrid,node_wiki_dense,node_blog_retriever,node_reranker toneAmber
class node_shared_state,node_prompt_templates toneMint
class node_wiki_sqlite,node_wiki_indexes,node_blog_data toneRose
class node_questioner,node_answer toneIndigo
```

## Components

### Agent workflow

- [Single-question runner](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/main-singleQ.py): `V2_Py_project/main-singleQ.py`
- [Agent graph](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/graph.py): `V2_Py_project/src/graph.py`
- [Plan and replan](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py): `V2_Py_project/src/nodes.py`
- [Query generation](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py): `V2_Py_project/src/nodes.py`
- [Retriever tool dispatch](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/graph.py): `V2_Py_project/src/graph.py`
- [Subquestion answering](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py): `V2_Py_project/src/nodes.py`
- [Progress reflection](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py): `V2_Py_project/src/nodes.py`
- [Final synthesis](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/nodes.py): `V2_Py_project/src/nodes.py`

### Evidence retrieval

- [Hybrid wiki retriever](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever_of_wiki.py): `V2_Py_project/src/retriever_of_wiki.py`
- [Dense-only wiki retriever](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever_of_wiki_dense_search_only.py): `V2_Py_project/src/retriever_of_wiki_dense_search_only.py`
- [Blog dense retriever](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/retriever.py): `V2_Py_project/src/retriever.py`
- [Document reranker](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/re_ranker.py): `V2_Py_project/src/re_ranker.py`

### Prompts and state

- [Graph state](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/state.py): `V2_Py_project/src/state.py`
- [Prompt templates](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/src/prompts.py): `V2_Py_project/src/prompts.py`

### Knowledge sources

- **Wikipedia document store**
- **Wiki search indexes**
- [Blog database](https://github.com/amanotooko7/agentrag/blob/main/V2_Py_project/DB/LilianWeng_Three_blogs_DB.pkl): `V2_Py_project/DB/LilianWeng_Three_blogs_DB.pkl`

### Other components

- **Question input**
- **Final answer**

## Connections

- Question input → Single-question runner: provides question (evidence: `V2_Py_project/main-singleQ.py`)
- Single-question runner → Agent graph: builds and streams (evidence: `V2_Py_project/main-singleQ.py`)
- Agent graph → Plan and replan: starts at (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Query generation: routes to (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Retriever tool dispatch: routes to (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Subquestion answering: routes to (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Progress reflection: routes to (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Final synthesis: routes to (evidence: `V2_Py_project/src/graph.py`)
- Agent graph → Graph state: uses state (evidence: `V2_Py_project/src/graph.py`)
- Plan and replan → Query generation: sets plan (evidence: `V2_Py_project/src/graph.py`)
- Query generation → Retriever tool dispatch: requests retrieval (evidence: `V2_Py_project/src/graph.py`)
- Retriever tool dispatch → Subquestion answering: passes evidence (evidence: `V2_Py_project/src/graph.py`)
- Subquestion answering → Progress reflection: records answer (evidence: `V2_Py_project/src/graph.py`)
- Progress reflection → Query generation: continues (evidence: `V2_Py_project/src/graph.py`)
- Progress reflection → Plan and replan: replans (evidence: `V2_Py_project/src/graph.py`)
- Progress reflection → Final synthesis: ends at (evidence: `V2_Py_project/src/graph.py`)
- Final synthesis → Final answer: produces
- Plan and replan → Prompt templates: uses prompts (evidence: `V2_Py_project/src/nodes.py`)
- Query generation → Prompt templates: uses prompts (evidence: `V2_Py_project/src/nodes.py`)
- Subquestion answering → Prompt templates: uses prompts (evidence: `V2_Py_project/src/nodes.py`)
- Progress reflection → Prompt templates: uses prompts (evidence: `V2_Py_project/src/nodes.py`)
- Final synthesis → Prompt templates: uses prompts (evidence: `V2_Py_project/src/nodes.py`)
- Retriever tool dispatch → Hybrid wiki retriever: invokes tool (evidence: `V2_Py_project/src/graph.py`)
- Hybrid wiki retriever → Wikipedia document store: reads documents (evidence: `V2_Py_project/src/retriever_of_wiki.py`)
- Hybrid wiki retriever → Wiki search indexes: searches indexes (evidence: `V2_Py_project/src/retriever_of_wiki.py`)
- Subquestion answering → Document reranker: reranks candidates (evidence: `V2_Py_project/src/nodes.py`)
- Dense-only wiki retriever → Wikipedia document store: reads documents (evidence: `V2_Py_project/src/retriever_of_wiki_dense_search_only.py`)
- Dense-only wiki retriever → Wiki search indexes: searches index (evidence: `V2_Py_project/src/retriever_of_wiki_dense_search_only.py`)
- Blog dense retriever → Blog database: retrieves from (evidence: `README.md`)
