How anshlambagit/ai_data_agent works
This is a LangGraph-based natural-language data agent. Users submit a question to the router, which dispatches SQL requests to a safety-checked database-analysis workflow or ETL requests to an extraction/transformation agent. The SQL path gathers schema context, generates and judges SQL, then executes or cancels it; the ETL path invokes tools for API extraction or file transformation. The graph includes the shared state model and LLM selector. Database utility internals were not sampled, so their connection to PostgreSQL is documented rather than source-verified.
Main entry points: llm_pick.py LLM selector · data_agent.py Query router · sql_analyst.py SQL safety judge · etl_tools.py ETL toolkit
Components 21
Agent orchestration
- CLI entry
main.py - Query router
agents/data_agent.py - SQL dispatch
agents/data_agent.py - ETL dispatch
agents/data_agent.py
SQL analysis
- Question curation
agents/sql_analyst.py - Schema context
agents/sql_analyst.py - SQL generation
agents/sql_analyst.py - SQL safety judge
agents/sql_analyst.py - Unsafe query response
agents/sql_analyst.py - Query execution
agents/sql_analyst.py - Answer generation
agents/sql_analyst.py
ETL processing
- ETL agent
agents/etl_analyst.py - ETL toolkit
utils/etl_tools.py
Shared services
- Agent state schemas
Models/schema.py - LLM selector
utils/llm_pick.py - Database utility
utils/database.py
Other components
- User
- PostgreSQL
- Data API
- Input and output files
- LLM providers
Connections 27
- User → CLI entry: submits query
main.py - CLI entry → Query router: invokes
main.py - Query router → SQL dispatch: routes SQL
agents/data_agent.py - Query router → ETL dispatch: routes ETL
agents/data_agent.py - Query router → Agent state schemas: uses state
agents/data_agent.py - Query router → LLM selector: selects router model
agents/data_agent.py - LLM selector → LLM providers: configures provider client
utils/llm_pick.py - SQL dispatch → Question curation: invokes SQL agent
agents/data_agent.py - ETL dispatch → ETL agent: invokes ETL agent
agents/data_agent.py - Question curation → Schema context: passes curated query
agents/sql_analyst.py - Question curation → LLM selector: selects model
agents/sql_analyst.py - Schema context → Database utility: fetches schema
agents/sql_analyst.py - Schema context → SQL generation: passes prompt context
agents/sql_analyst.py - SQL generation → LLM selector: selects model
agents/sql_analyst.py - SQL generation → SQL safety judge: passes generated SQL
agents/sql_analyst.py - SQL safety judge → LLM selector: selects judge model
agents/sql_analyst.py - SQL safety judge → Unsafe query response: cancels unsafe SQL
agents/sql_analyst.py - SQL safety judge → Query execution: dispatches safe SQL
agents/sql_analyst.py - Query execution → Database utility: executes query
agents/sql_analyst.py - Query execution → Answer generation: passes execution result
agents/sql_analyst.py - Answer generation → LLM selector: selects response model
agents/sql_analyst.py - Database utility → PostgreSQL: queries database
README.md - ETL agent → LLM selector: selects agent model
agents/etl_analyst.py - ETL agent → ETL toolkit: invokes ETL tools
agents/etl_analyst.py - ETL toolkit → LLM selector: selects transform model
agents/etl_analyst.py - ETL toolkit → Data API: requests JSON data
utils/etl_tools.py - ETL toolkit → Input and output files: reads and writes datasets
utils/etl_tools.py