Medical AI Agent Development by Rabiul IslamMedical AI Agent Development by Rabiul Islam

Medical AI Agent Development

Rabiul Islam

Rabiul Islam

๐Ÿฅ Multi-Tool AI Agent for Medical Datasets and Web

A LangChain-based Medical AI Agent that answers dataset-specific medical questions using three SQLite databases and provides general medical information using web search.
The agent automatically selects the appropriate tool based on the user's question.

๐Ÿš€ Features

โค๏ธ Heart Disease dataset queries
๐ŸŽ—๏ธ Cancer dataset queries
๐Ÿฉบ Diabetes dataset queries
๐ŸŒ General medical information through web search
๐Ÿค– Groq LLM with tool calling
๐Ÿ”Ž Automatic tool selection
๐Ÿ—„๏ธ SQLite databases
๐Ÿ” Read-only SQL validation
๐Ÿ”‘ Secure API key management using environment variables
๐Ÿ’ฌ Natural-language answers

๐Ÿง  Project Overview

This project is a multi-tool AI agent designed to work with medical datasets.
The agent can answer two major types of questions:

1. Dataset-specific questions

For example:

These questions are answered using the appropriate SQLite database.

2. General medical questions

For example:

These questions are answered using the web search tool.

๐Ÿ—๏ธ System Architecture


๐Ÿ› ๏ธ Tools

The project contains four main tools.

โค๏ธ HeartDiseaseDBTool

Queries the Heart Disease SQLite database.
Used for:
Record counts
Averages
Percentages
Filtering
Dataset statistics
Numerical questions
Table:

๐ŸŽ—๏ธ CancerDBTool

Queries the Cancer SQLite database.
Used for:
Record counts
Averages
Percentages
Filtering
Dataset statistics
Numerical questions
Table:

๐Ÿฉบ DiabetesDBTool

Queries the Diabetes SQLite database.
Used for:
Record counts
Averages
Percentages
Filtering
Dataset statistics
Numerical questions
Table:

๐ŸŒ MedicalWebSearchTool

Searches the web for general medical information.
Used for:
Definitions
Symptoms
Causes
Risk factors
Prevention
Diagnosis
General treatment information

๐Ÿ“Š Datasets

1. Heart Disease Dataset

Kaggle dataset:

Records:

SQLite database:

Table:

Columns:

2. Cancer Prediction Dataset

Kaggle dataset:

Records:

SQLite database:

Table:

Columns:

3. Diabetes Dataset

Kaggle dataset:

Records:

SQLite database:

Table:

Columns:

๐Ÿ“ Project Structure


The raw datasets are kept locally inside the data/ directory and are excluded from GitHub using .gitignore.

๐Ÿ’ป Technologies Used

Python
LangChain
LangChain Core
LangChain Groq
Groq
SQLite
Pandas
Tavily
python-dotenv

โš™๏ธ Installation

Step 1: Clone the Repository


Go to the project directory:

Step 2: Create Virtual Environment

For Windows:

Activate the virtual environment:

Step 3: Install Dependencies


๐Ÿ”‘ API Key Configuration

Create a .env file in the project root directory.
Use .env.example as a reference.

Never upload your .env file to GitHub.
The .gitignore file is configured to prevent .env from being committed.

๐Ÿ—„๏ธ Database Setup

To create the SQLite databases, run:

This creates:

The database setup script also verifies the number of records.
Expected records:

โ–ถ๏ธ Running the Agent

Start the application with:

You should see:

Now enter a question.
Example:

The agent will select the Diabetes database tool and return the result.

๐Ÿ’ก Example Questions

โค๏ธ Heart Disease




๐ŸŽ—๏ธ Cancer




๐Ÿฉบ Diabetes




๐ŸŒ General Medical Questions






๐Ÿ”€ Automatic Tool Routing

The AI agent automatically determines which tool should be used.
For example:

For a general medical question:

๐Ÿ” SQL Safety

The database tools are designed to perform read-only SQL queries.
Allowed query types:

The following SQL operations are blocked:

This helps prevent accidental modification of the medical databases.

๐Ÿงช Verified Test Results

The agent was tested with several questions.

Diabetes Record Count


Heart Disease


Cancer


Average Glucose


Web Search


๐Ÿ”„ Agent Workflow


๐Ÿ”’ Security

API keys are stored in environment variables.
The following files/directories are excluded from GitHub:

This prevents API keys, virtual environments and raw datasets from being accidentally uploaded.

โš ๏ธ Medical Disclaimer

This project is created for educational and demonstration purposes only.
The AI agent does not provide professional medical diagnosis or treatment.
Information returned by the web search tool may not always be appropriate for an individual's specific medical situation.
Always consult a qualified healthcare professional for medical advice.

๐Ÿ‘จโ€๐Ÿ’ป Author

Rabiul Islam
AI/ML Developer specializing in:
Computer Vision
Generative AI
Machine Learning
Intelligent Automation
GitHub:

๐Ÿ”— Repository


Like this project

Posted Sep 18, 2026

Developed an AI agent to answer medical dataset and web queries.