# hsmshubham007-code/week5task2 architecture

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

- Interactive diagram: https://gitdiagram.com/hsmshubham007-code/week5task2
- Repository: https://github.com/hsmshubham007-code/week5task2

## Overview

This is a read-only natural-language SQL agent for the Chinook SQLite database. A user question enters the LangGraph agent, which uses a Groq-backed model to select tools; database queries are validated, executed read-only, and returned to the agent for a response. Schema inspection, value search, and safe arithmetic are separate tool capabilities. An evaluation branch compares agent results with a predefined golden set and can rescore saved results. The source excerpts show core tool and database calls; README statements support the documented model and evaluation relationships.

Main entry points: [`src/agent_tools.py`](https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent_tools.py) (Agent tools), [`src/agent.py`](https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent.py) (SQL agent), [`src/database.py`](https://github.com/hsmshubham007-code/week5task2/blob/main/src/database.py) (Query execution), [`evals/evaluate_agent.py`](https://github.com/hsmshubham007-code/week5task2/blob/main/evals/evaluate_agent.py) (Agent evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent workflow"]
  node_agent["SQL agent<br/>[agent.py]"]
  node_tools["Agent tools<br/>[agent_tools.py]"]
end

subgraph group_data["Database tools"]
  node_schema["Schema inspection<br/>[schema_tools.py]"]
  node_search["Value search<br/>[schema_tools.py]"]
  node_calculator["Safe calculator<br/>[calculator.py]"]
  node_validation["SQL validation<br/>[sql_safety.py]"]
  node_database["Query execution<br/>[database.py]"]
  node_chinook[("Chinook database<br/>[chinook.db]")]
end

subgraph group_eval["Evaluation"]
  node_questions["Golden questions<br/>[questions.py]"]
  node_evaluator["Agent evaluation<br/>[evaluate_agent.py]"]
  node_rescorer["Saved-result rescorer"]
end

node_user(("User"))
node_model{{"Groq model"}}

node_user -->|"asks question"| node_agent
node_agent -->|"prompts model"| node_model
node_agent -->|"dispatches tools"| node_tools
node_tools -->|"calls inspection"| node_schema
node_tools -->|"calls search"| node_search
node_tools -->|"calls calculation"| node_calculator
node_tools -->|"executes SQL"| node_database
node_database -->|"validates query"| node_validation
node_database -->|"queries read-only"| node_chinook
node_schema -->|"inspects schema"| node_chinook
node_search -->|"searches values"| node_chinook
node_agent -->|"supplies results"| node_evaluator
node_questions -->|"sets expected results"| node_evaluator
node_evaluator -->|"provides saved results"| node_rescorer

click node_agent "https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent.py"
click node_tools "https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent_tools.py"
click node_schema "https://github.com/hsmshubham007-code/week5task2/blob/main/src/schema_tools.py"
click node_search "https://github.com/hsmshubham007-code/week5task2/blob/main/src/schema_tools.py"
click node_calculator "https://github.com/hsmshubham007-code/week5task2/blob/main/src/calculator.py"
click node_validation "https://github.com/hsmshubham007-code/week5task2/blob/main/src/sql_safety.py"
click node_database "https://github.com/hsmshubham007-code/week5task2/blob/main/src/database.py"
click node_chinook "https://github.com/hsmshubham007-code/week5task2/blob/main/data/chinook.db"
click node_questions "https://github.com/hsmshubham007-code/week5task2/blob/main/evals/questions.py"
click node_evaluator "https://github.com/hsmshubham007-code/week5task2/blob/main/evals/evaluate_agent.py"
click node_rescorer "https://github.com/hsmshubham007-code/week5task2/blob/main/evals/rescore_saved_results.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_agent,node_tools,node_user toneBlue
class node_schema,node_search,node_calculator,node_validation,node_database,node_chinook toneAmber
class node_questions,node_evaluator,node_rescorer toneMint
class node_model toneIndigo
```

## Components

### Agent workflow

- [SQL agent](https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent.py): `src/agent.py`
- [Agent tools](https://github.com/hsmshubham007-code/week5task2/blob/main/src/agent_tools.py): `src/agent_tools.py`

### Database tools

- [Schema inspection](https://github.com/hsmshubham007-code/week5task2/blob/main/src/schema_tools.py): `src/schema_tools.py`
- [Value search](https://github.com/hsmshubham007-code/week5task2/blob/main/src/schema_tools.py): `src/schema_tools.py`
- [Safe calculator](https://github.com/hsmshubham007-code/week5task2/blob/main/src/calculator.py): `src/calculator.py`
- [SQL validation](https://github.com/hsmshubham007-code/week5task2/blob/main/src/sql_safety.py): `src/sql_safety.py`
- [Query execution](https://github.com/hsmshubham007-code/week5task2/blob/main/src/database.py): `src/database.py`
- [Chinook database](https://github.com/hsmshubham007-code/week5task2/blob/main/data/chinook.db): `data/chinook.db`

### Evaluation

- [Golden questions](https://github.com/hsmshubham007-code/week5task2/blob/main/evals/questions.py): `evals/questions.py`
- [Agent evaluation](https://github.com/hsmshubham007-code/week5task2/blob/main/evals/evaluate_agent.py): `evals/evaluate_agent.py`
- [Saved-result rescorer](https://github.com/hsmshubham007-code/week5task2/blob/main/evals/rescore_saved_results.py): `evals/rescore_saved_results.py`

### Other components

- **User**
- **Groq model**

## Connections

- User → SQL agent: asks question (evidence: `README.md`)
- SQL agent → Groq model: prompts model (evidence: `README.md`)
- SQL agent → Agent tools: dispatches tools (evidence: `src/agent.py`)
- Agent tools → Schema inspection: calls inspection (evidence: `src/agent_tools.py`)
- Agent tools → Value search: calls search (evidence: `src/agent_tools.py`)
- Agent tools → Safe calculator: calls calculation (evidence: `src/agent_tools.py`)
- Agent tools → Query execution: executes SQL (evidence: `src/agent_tools.py`)
- Query execution → SQL validation: validates query (evidence: `src/database.py`)
- Query execution → Chinook database: queries read-only (evidence: `src/database.py`)
- Schema inspection → Chinook database: inspects schema (evidence: `src/schema_tools.py`)
- Value search → Chinook database: searches values (evidence: `src/schema_tools.py`)
- SQL agent → Agent evaluation: supplies results (evidence: `README.md`)
- Golden questions → Agent evaluation: sets expected results (evidence: `README.md`)
- Agent evaluation → Saved-result rescorer: provides saved results (evidence: `evals/rescore_saved_results.py`)
