# jeongeunyeom/petroleum-rag-agent architecture

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

- Interactive diagram: https://gitdiagram.com/jeongeunyeom/petroleum-rag-agent
- Repository: https://github.com/jeongeunyeom/petroleum-rag-agent

## Overview

Petroleum Engineering AI Agent is a local-first research and calculation product centered on a single chat input. A message becomes a goal run, which retrieves internal evidence by default and conditionally calculates, simulates, analyzes, and verifies before returning cited results or requesting clarification; completed runs can produce reports. Separate documented capabilities include evidence-based Research, document ingestion and Q&A, figure review, and a constrained workspace agent. Edges reflect README workflows and source-index references; several feature branches have directory-level paths because their implementation was not sampled.

Main entry points: [`backend/app/services/goal_execution_agent.py`](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_execution_agent.py) (Goal controller), [`backend/app/api/goal_research_routes.py`](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/goal_research_routes.py) (Goal run API), [`backend/app/services/goal_research_agent.py`](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_research_agent.py) (Goal researcher), [`backend/app/api/routes.py`](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/routes.py) (Core API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat experience"]
  node_chat_ui["Chat UI<br/>[page.tsx]"]
  node_goal_panel["Goal results"]
  node_cite_view["Citation display"]
end

subgraph group_api["API and orchestration"]
  node_goal_api["Goal run API"]
  node_research_api["Research API<br/>[research_routes.py]"]
  node_core_api["Core API<br/>[routes.py]"]
end

subgraph group_research["Research and evidence"]
  node_research_agent["Evidence research<br/>[research_agent.py]"]
  node_qa["Knowledge Q&amp;A<br/>[qa.py]"]
  node_vector_store[("Knowledge store<br/>[vector_store.py]")]
  node_web_research["Web research<br/>[web_research.py]"]
  node_validators["Engineering checks"]
  node_document_processor["Document ingestion"]
  node_figure_review["Figure review<br/>[figure_review.py]"]
end

subgraph group_execution["Goal execution"]
  node_goal_service["Run lifecycle"]
  node_goal_parser["Message parsing"]
  node_goal_agent["Goal controller"]
  node_goal_research["Goal researcher"]
  node_tool_planner["Action planner"]
  node_evaluator["Goal evaluator<br/>[goal_evaluator.py]"]
  node_requirements["Calc requirements"]
  node_claim_grounding["Claim grounding"]
  node_user_facts["User fact registry"]
end

subgraph group_tools["Agents and deliverables"]
  node_python_tools["Python sandbox<br/>[python_tools.py]"]
  node_permission["Tool permissions"]
  node_deliverables["Report generation<br/>[service.py]"]
end

node_user(("Researcher"))
node_ollama["Ollama models"]
node_ddgs["DDGS search"]

node_user -->|"submits goal"| node_chat_ui
node_chat_ui -->|"starts run"| node_goal_api
node_goal_api -->|"parses message"| node_goal_parser
node_goal_api -->|"starts run"| node_goal_service
node_goal_service -->|"runs controller"| node_goal_agent
node_goal_agent -->|"researches goal"| node_goal_research
node_goal_agent -->|"plans actions"| node_tool_planner
node_goal_agent -->|"evaluates outcome"| node_evaluator
node_goal_agent -->|"checks inputs"| node_requirements
node_goal_agent -->|"grounds claims"| node_claim_grounding
node_goal_agent -->|"tracks user facts"| node_user_facts
node_goal_research -->|"gathers evidence"| node_research_agent
node_research_agent -.->|"retrieves evidence"| node_vector_store
node_goal_research -.->|"searches when requested"| node_web_research
node_web_research -->|"discovers sources"| node_ddgs
node_goal_research -.->|"checks claims"| node_validators
node_goal_agent -.->|"runs calculations"| node_python_tools
node_goal_agent -.->|"uses language model"| node_ollama
node_goal_service -->|"creates deliverables"| node_deliverables
node_goal_api -.->|"returns run results"| node_goal_panel
node_goal_panel -.->|"shows citations"| node_cite_view
node_user -.->|"requests evidence"| node_research_api
node_research_api -->|"dispatches research"| node_research_agent
node_core_api -->|"answers questions"| node_qa
node_qa -.->|"retrieves context"| node_vector_store
node_core_api -->|"processes uploads"| node_document_processor
node_user -.->|"opens figure review"| node_figure_review
node_core_api -->|"serves review API"| node_figure_review
node_permission -.->|"authorizes tool use"| node_python_tools

click node_chat_ui "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/app/page.tsx"
click node_goal_panel "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/components/GoalResearchPanel.tsx"
click node_cite_view "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/components/DocumentInfoPanel.tsx"
click node_goal_api "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/goal_research_routes.py"
click node_research_api "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/research_routes.py"
click node_core_api "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/routes.py"
click node_goal_service "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_research_service.py"
click node_goal_parser "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_message_parser.py"
click node_goal_agent "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_execution_agent.py"
click node_goal_research "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_research_agent.py"
click node_tool_planner "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_tool_planner.py"
click node_evaluator "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_evaluator.py"
click node_requirements "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/calculation_requirements.py"
click node_claim_grounding "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/calc_claim_grounding.py"
click node_user_facts "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/user_fact_registry.py"
click node_research_agent "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/research_agent.py"
click node_qa "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/qa.py"
click node_vector_store "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/vector_store.py"
click node_web_research "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/web_research.py"
click node_validators "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/engineering_validator.py"
click node_python_tools "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/tools/python_tools.py"
click node_permission "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/agents/permission_manager.py"
click node_deliverables "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/deliverables/service.py"
click node_document_processor "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/document_processor.py"
click node_figure_review "https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/figure_review.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_chat_ui,node_goal_panel,node_cite_view toneBlue
class node_goal_api,node_research_api,node_core_api toneAmber
class node_research_agent,node_qa,node_vector_store,node_web_research,node_validators,node_document_processor,node_figure_review toneMint
class node_goal_service,node_goal_parser,node_goal_agent,node_goal_research,node_tool_planner,node_evaluator,node_requirements,node_claim_grounding,node_user_facts toneRose
class node_python_tools,node_permission,node_deliverables,node_user,node_ollama,node_ddgs toneIndigo
```

## Components

### Chat experience

- [Chat UI](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Goal results](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/components/GoalResearchPanel.tsx): `frontend/components/GoalResearchPanel.tsx`
- [Citation display](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/frontend/components/DocumentInfoPanel.tsx): `frontend/components/DocumentInfoPanel.tsx`

### API and orchestration

- [Goal run API](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/goal_research_routes.py): `backend/app/api/goal_research_routes.py`
- [Research API](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/research_routes.py): `backend/app/api/research_routes.py`
- [Core API](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`

### Research and evidence

- [Evidence research](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/research_agent.py): `backend/app/services/research_agent.py`
- [Knowledge Q&A](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/qa.py): `backend/app/services/qa.py`
- [Knowledge store](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/vector_store.py): `backend/app/services/vector_store.py`
- [Web research](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/web_research.py): `backend/app/services/web_research.py`
- [Engineering checks](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/engineering_validator.py): `backend/app/services/engineering_validator.py`
- [Document ingestion](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/document_processor.py): `backend/app/services/document_processor.py`
- [Figure review](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/figure_review.py): `backend/app/services/figure_review.py`

### Goal execution

- [Run lifecycle](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_research_service.py): `backend/app/services/goal_research_service.py`
- [Message parsing](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_message_parser.py): `backend/app/services/goal_message_parser.py`
- [Goal controller](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_execution_agent.py): `backend/app/services/goal_execution_agent.py`
- [Goal researcher](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_research_agent.py): `backend/app/services/goal_research_agent.py`
- [Action planner](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_tool_planner.py): `backend/app/services/goal_tool_planner.py`
- [Goal evaluator](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/goal_evaluator.py): `backend/app/services/goal_evaluator.py`
- [Calc requirements](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/calculation_requirements.py): `backend/app/services/calculation_requirements.py`
- [Claim grounding](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/calc_claim_grounding.py): `backend/app/services/calc_claim_grounding.py`
- [User fact registry](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/user_fact_registry.py): `backend/app/services/user_fact_registry.py`

### Agents and deliverables

- [Python sandbox](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/tools/python_tools.py): `backend/app/tools/python_tools.py`
- [Tool permissions](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/agents/permission_manager.py): `backend/app/agents/permission_manager.py`
- [Report generation](https://github.com/jeongeunyeom/petroleum-rag-agent/blob/main/backend/app/services/deliverables/service.py): `backend/app/services/deliverables/service.py`

### Other components

- **Researcher**
- **Ollama models**
- **DDGS search**

## Connections

- Researcher → Chat UI: submits goal
- Chat UI → Goal run API: starts run
- Goal run API → Message parsing: parses message (evidence: `backend/app/api/goal_research_routes.py`)
- Goal run API → Run lifecycle: starts run (evidence: `backend/app/api/goal_research_routes.py`)
- Run lifecycle → Goal controller: runs controller (evidence: `backend/app/services/goal_research_service.py`)
- Goal controller → Goal researcher: researches goal (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal controller → Action planner: plans actions (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal controller → Goal evaluator: evaluates outcome (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal controller → Calc requirements: checks inputs (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal controller → Claim grounding: grounds claims (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal controller → User fact registry: tracks user facts (evidence: `backend/app/services/goal_execution_agent.py`)
- Goal researcher → Evidence research: gathers evidence (evidence: `backend/app/services/goal_research_agent.py`)
- Evidence research → Knowledge store: retrieves evidence
- Goal researcher → Web research: searches when requested
- Web research → DDGS search: discovers sources
- Goal researcher → Engineering checks: checks claims
- Goal controller → Python sandbox: runs calculations
- Goal controller → Ollama models: uses language model
- Run lifecycle → Report generation: creates deliverables (evidence: `backend/app/services/goal_research_service.py`)
- Goal run API → Goal results: returns run results
- Goal results → Citation display: shows citations
- Researcher → Research API: requests evidence
- Research API → Evidence research: dispatches research (evidence: `backend/app/api/research_routes.py`)
- Core API → Knowledge Q&A: answers questions (evidence: `backend/app/api/routes.py`)
- Knowledge Q&A → Knowledge store: retrieves context
- Core API → Document ingestion: processes uploads (evidence: `backend/app/api/routes.py`)
- Researcher → Figure review: opens figure review
- Core API → Figure review: serves review API (evidence: `backend/app/api/routes.py`)
- Tool permissions → Python sandbox: authorizes tool use (evidence: `backend/app/agents/permission_manager.py`)
