Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡§πŸ‡© BD Agent

Multi-Tool AI Agent for Bangladesh

An LLM-powered agent that answers real questions about Bangladeshi hospitals, institutions, and restaurants β€” grounded in real datasets, not hallucinations.

Python LangChain SQLite HuggingFace License

Overview β€’ Demo β€’ Architecture β€’ Setup β€’ Skills Demonstrated


πŸ“Œ Overview

BD Agent is a tool-using AI agent built with LangChain that answers questions about Bangladesh by querying real structured data instead of relying purely on an LLM's memory. It combines:

  • πŸ—„οΈ Three real-world datasets (hospitals, educational institutions, restaurants) ingested from HuggingFace into local SQLite databases
  • 🧠 An LLM-based agent that reasons about which tool best answers a given question
  • 🌐 A live web-search tool for general knowledge questions outside the datasets

The result: a domain-specific assistant that gives accurate, data-backed answers β€” a practical demonstration of retrieval-augmented, tool-using AI systems, one of the most in-demand patterns in applied AI/ML engineering today.

πŸ’¬ Example Queries

> How many hospitals are in Dhaka?
> List hospitals with ICU facilities in Chittagong.
> What universities are listed in the institutions database?
> Show popular restaurants serving Bengali cuisine in Sylhet.
> What is the role of DGHS in Bangladesh?

The agent automatically routes each question to the correct tool β€” SQL query against the right database, or a live web search β€” without the user needing to specify which.


πŸ—οΈ Architecture

                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚     User Question     β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                                    β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   agent.py (LangChain)  β”‚
                       β”‚  LLM decides best tool  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό              β–Ό          β–Ό          β–Ό             
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Hospitals   β”‚β”‚ Institutionsβ”‚β”‚ Restaurants β”‚β”‚  Web Search  β”‚
   β”‚  SQL Tool   β”‚β”‚   SQL Tool  β”‚β”‚   SQL Tool  β”‚β”‚  (SerpAPI)   β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β–Ό              β–Ό              β–Ό
   dbs/hospitals.db dbs/institutions.db dbs/restaurants.db
          β”‚              β”‚              β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚ Final Answer  β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data pipeline: ingest.py pulls each dataset from HuggingFace β†’ converts to a pandas DataFrame β†’ normalizes column names β†’ writes to a local SQLite .db file via to_sql().


πŸ—‚οΈ Project Structure

bd_multi_tool_ai_agent/
β”œβ”€β”€ agent.py                  # Entry point β€” builds & runs the LangChain agent
β”œβ”€β”€ ingest.py                 # Downloads datasets & builds SQLite databases
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ db_tools.py           # SQL tools: hospitals, institutions, restaurants
β”‚   └── web_search_tool.py    # SerpAPI web-search tool
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ .env.example               # API key template
└── .gitignore                 # Excludes secrets, DBs, venv

πŸ“Š Datasets

Source (HuggingFace) Local Table
Mahadih534/Institutional-Information-of-Bangladesh institutions
Mahadih534/all-bangladeshi-hospitals hospitals
Mahadih534/Bangladeshi-Restaurant-Data restaurants

Adding a new dataset is a one-line change β€” add a save_dataset_to_db(dataset_name, table_name, db_path) call in ingest.py.


πŸš€ Getting Started

1. Clone the repository

git clone https://github.com/delowarhossaincse63/bd_multi_tool_ai_agent.git
cd bd_multi_tool_ai_agent

2. Create a virtual environment

python -m venv venv
venv\Scripts\activate        # Windows
source venv/bin/activate     # macOS / Linux

3. Install dependencies

pip install -r requirements.txt

4. Configure environment variables

copy .env.example .env        # Windows
cp .env.example .env          # macOS / Linux

Then add your keys to .env:

OPENAI_API_KEY=your_openai_key_here
SERPAPI_API_KEY=your_serpapi_key_here

5. Build the databases

python ingest.py

Creates dbs/hospitals.db, dbs/institutions.db, dbs/restaurants.db.

6. Run the agent

python agent.py                                   # interactive mode
python agent.py "How many hospitals are in Dhaka?" # direct query

🧠 Skills Demonstrated

This project showcases practical, job-relevant experience with:

  • LLM Agent Design β€” building tool-using agents with LangChain that reason about task routing
  • Data Engineering β€” ETL pipeline: dataset ingestion, cleaning, normalization, and loading into SQLite
  • API Integration β€” OpenAI API and SerpAPI, with secure key management via .env
  • Database Design β€” schema normalization, SQL query tools, de-duplication logic
  • Software Engineering Practices β€” modular code structure, .gitignore hygiene, secret management, reproducible setup
  • Applied AI for Real-World Data β€” grounding LLM output in verified datasets to reduce hallucination

πŸ” Verifying the Databases

sqlite3 dbs/hospitals.db "PRAGMA table_info('hospitals');"
sqlite3 dbs/hospitals.db "SELECT COUNT(*) FROM hospitals;"

Or in Python:

import sqlite3
conn = sqlite3.connect('dbs/hospitals.db')
cur = conn.cursor()
print(cur.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall())
print(cur.execute("SELECT count(*) FROM hospitals;").fetchone())
conn.close()

πŸ›‘οΈ Security Notes

The following are excluded from version control via .gitignore:

  • .env β€” API keys
  • dbs/*.db β€” generated database files
  • venv/ / .venv/ β€” virtual environment
  • __pycache__/, *.pyc

If a secret is ever committed accidentally:

git rm --cached .env
git commit -m "Remove .env from tracking"
git commit --amend --no-edit
git push -f origin main

🧯 Troubleshooting

Issue Solution
OPENAI_API_KEY is required Confirm .env exists and contains the key; restart the terminal.
GitHub blocks push (secret detected) Remove the secret, amend the commit, force-push.
Agent gives unexpected answers Check console logs for tracebacks; verify all keys in .env.
Web search not working Confirm SERPAPI_API_KEY is set β€” without it, only SQL tools work.

πŸ—ΊοΈ Roadmap

  • Add more Bangladesh-specific datasets (transport, weather, government services)
  • Build a lightweight web UI (Streamlit/FastAPI)
  • Add caching for repeated queries
  • Deploy as a public demo

🀝 Contributing

Contributions, issues, and feature requests are welcome. Feel free to check the issues page.

πŸ“„ License

This project is licensed under the MIT License.

πŸ“¬ Contact

Delowar Hossain πŸ“§ delowarhossain.cse.63@gmail.com πŸ”— GitHub


⭐ If you find this project useful, consider giving it a star!

About

Multi-Tool AI Agent for Bangladesh using HuggingFace datasets and LangChain

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages