A sophisticated multi-agent system for intelligent data processing and analysis using LangGraph. This project demonstrates a complete implementation of an agentic architecture with specialized sub-agents for SQL operations and ETL workflows.
- Overview
- Architecture
- Features
- Project Structure
- Configuration
- Usage
- Agent Descriptions
- Data Models
- Examples
Agentic AI Data Agent is an intelligent system that processes natural language queries and routes them to specialized agents for execution. The main agent acts as an intelligent router that understands user intent and delegates tasks to either the SQL Analyst Agent (for database queries) or the ETL Analyst Agent (for data extraction and transformation operations).
This project showcases modern AI engineering practices including:
- Multi-agent orchestration with LangGraph
- Intelligent routing based on natural language understanding
- Safety validation for SQL queries
- Tool-based agent architecture
- Dynamic LLM selection based on task complexity
The system follows a hierarchical agent architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Agent (Router) β
β Routes user queries to appropriate sub-agents β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββ΄ββββββββββββ
β β
βΌ βΌ
ββββββββββββββββ ββββββββββββββββ
β SQL Analyst β β ETL Analyst β
β Agent β β Agent β
ββββββββββββββββ ββββββββββββββββ
β β
βββΊ Query Curation βββΊ Extract Load
βββΊ Schema Context βββΊ Transform Load
βββΊ SQL Generation βββΊ Code Execution
βββΊ Safety Validation
βββΊ Query Execution
βββΊ Answer Generation
- User Input β Natural language query
- Router Node β Classifies query as SQL or ETL
- Agent Dispatch β Routes to appropriate sub-agent
- Processing β Each agent processes the task
- Output β Returns structured result to user
-
Intelligent Query Routing: Automatically classifies user queries as SQL or ETL operations
-
SQL Analysis Agent:
- Natural language to SQL query conversion
- Automatic schema context gathering
- SQL safety validation (prevents harmful operations)
- Query execution on PostgreSQL database
- Intelligent query refinement
-
ETL Agent:
- API data extraction (JSON to structured formats)
- Data transformation using Pandas
- Multi-format support (CSV, JSON, Parquet)
- Dynamic code generation based on user requirements
- Safe code execution
-
Multi-LLM Support:
- Low-complexity queries: Faster, cost-effective LLM
- Medium-complexity queries: Balanced LLM
- High-complexity queries: Premium LLM (Claude)
-
Safety & Validation:
- SQL query safety checking
- Protection against database modifications (INSERT, UPDATE, DELETE, DROP, etc.)
- Input validation and sanitization
- Structured output validation using Pydantic
Data_Agent/
βββ agents/ # Agent implementations
β βββ __init__.py
β βββ data_agent.py # Main router agent
β βββ sql_analyst.py # SQL query agent
β βββ etl_analyst.py # ETL operations agent
β
βββ Models/ # Data models
β βββ __init__.py
β βββ schema.py # Pydantic schemas for state management
β
βββ utils/ # Utility modules
β βββ __init__.py
β βββ database.py # PostgreSQL utilities
β βββ etl_tools.py # ETL operations toolkit
β βββ llm_pick.py # LLM selection logic
β
βββ data/ # Data directory
β βββ extract/ # Extracted data storage
β βββ transform/ # Transformed data storage
β βββ payments.csv # Sample dataset
β βββ ratings.csv # Sample dataset
β βββ rides.csv # Sample dataset
β βββ users.csv # Sample dataset
β βββ vehicles.csv # Sample dataset
β
βββ main.py # Entry point
βββ app.py # streamlit code
βββ feed_db.py # Database initialization script
βββ pyproject.toml # Project metadata and dependencies
βββ README.md # This file
The pick_llm() function intelligently selects the appropriate LLM based on complexity:
from utils.llm_pick import pick_llm
# Select based on complexity
llm_fast = pick_llm("low") # Cost-effective for simple queries
llm_balanced = pick_llm("medium") # Balanced performance and cost
llm_powerful = pick_llm("claude") # Premium model for complex tasksBasic Usage:
from agents.data_agent import data_agent
from langchain_core.messages import HumanMessage
# Example: Extract data from API
response = data_agent.invoke({
"messages": [
HumanMessage(content="""
I want to extract the data from the API endpoint
'https://pokeapi.co/api/v2/pokemon' and save it to
data/extract folder in CSV format
""")
],
"route_response": ""
})
print(response)SQL Query Example:
response = data_agent.invoke({
"messages": [
HumanMessage(content="""
Show me the top 5 users with the highest ratings
""")
],
"route_response": ""
})ETL Example:
response = data_agent.invoke({
"messages": [
HumanMessage(content="""
Transform the rides.csv data by filtering only rides
with rating > 4.5 and save to data/transform
""")
],
"route_response": ""
})# Run the main data agent
python main.py
# Run individual agents
python agents/sql_analyst.py
python agents/etl_analyst.pyFile: agents/data_agent.py
Responsibility:
- Receives natural language user queries
- Classifies queries as either SQL or ETL operations
- Routes queries to appropriate sub-agents
- Aggregates results and returns to user
Components:
- Router Node: Uses structured output to classify query intent
- Conditional Routing: Routes to SQL or ETL based on classification
- Graph Orchestration: Manages workflow using LangGraph
File: agents/sql_analyst.py
Responsibility:
- Converts natural language queries to SQL
- Handles all database query operations
- Validates query safety
- Executes queries and returns results
Workflow:
- Query Curation - Refines user question for clarity
- Context Gathering - Fetches database schema details
- Prompt Construction - Creates detailed context for LLM
- SQL Generation - Generates SQL query using LLM
- Safety Check - Validates query safety
- Query Execution - Executes validated query on database
- Answer Generation - Formats and returns results
Safety Features:
- Prevents execution of dangerous commands (INSERT, UPDATE, DELETE, DROP, ALTER)
- Validates query before execution
- Automatic result limiting to 10 rows (unless specified)
- Schema validation against database
File: agents/etl_analyst.py
Responsibility:
- Handles data extraction from APIs
- Performs data transformation using Pandas
- Manages data loading to various formats
- Executes code safely in controlled environment
Workflow:
- Tool Binding - Attaches ETL tools to LLM
- User Intent Understanding - Analyzes transformation requirements
- Tool Selection - Chooses appropriate ETL operation
- Code Generation - Generates Pandas code for transformation
- Safe Execution - Executes generated code in sandboxed environment
- Result Reporting - Returns execution status and generated code
Supported Tools:
- extract_load_tool: Extract from API β Load to storage
- transform_load_tool: Transform data using Pandas β Load result
Supported Formats:
- CSV (default)
- JSON (Lines or Records)
- Parquet
class AgentSchema(BaseModel):
messages: List # Conversation messages
user_question: str # Original user query
curated_ques: str # Refined question
prompt_query_context: str # Database context + prompt
generated_sql_query: str # Generated SQL
is_safe: Literal["Yes", "No"] # Safety validation result
comments: str # Safety check comments
sql_query_execution_result: str # Query result
final_answer: str # Final formatted answerclass ETLAgentSchema(BaseModel):
messages: List # Conversation messagesclass RouterSchema(BaseModel):
answer: Literal["sql", "etl"] # Query classification
comments: str # Reasoning for classificationclass DataAgentSchema(BaseModel):
messages: List # All conversation messages
route_response: str # Router decision (sql/etl)User Query:
"Show me the average rating for each vehicle type"
Processing:
- Router classifies as SQL query
- SQL Agent fetches schema
- Generates:
SELECT vehicle_type, AVG(rating) FROM rides GROUP BY vehicle_type LIMIT 10 - Validates safety β
- Executes and returns results
User Query:
"Extract the data from 'https://pokeapi.co/api/v2/pokemon' and save it as CSV"
Processing:
- Router classifies as ETL operation
- ETL Agent selects extract_load_tool
- Makes API request to endpoint
- Normalizes JSON response
- Saves to
data/extract/extracted_data.csv
User Query:
"Transform rides.csv to filter only rides with rating > 4.0 and save as JSON"
Processing:
- Router classifies as ETL operation
- ETL Agent analyzes requirement
- Generates Pandas code to filter and transform
- Executes code safely
- Saves result to
data/transform/in JSON format
Overview Tab
Question 1
"Delete data from users table"
Workflow changes based on the Questions

Question 2
"Show the first 10 payment records."
Question 3:
"Transform the data and show squirtle pokemon only"
Workflow changes based on the Questions
β SQL Safety Validation
- Query inspection before execution
- Blocks destructive operations
- Database structure protection
β Safe Code Execution
- Sandboxed Python code execution
- Input validation
- Error handling and reporting
β Environment Security
- Credentials stored in
.env(not in code) - Sensitive data protection
- Proper exception handling


