What does it actually take to build an AI agent that can reason over a relational database?
A few months ago, I attended a Snowflake presentation where they demonstrated their AI Agent capabilities. I was genuinely impressed by how naturally an AI agent could interact with enterprise data.
That presentation inspired me to build a simplified version myself—not to compete with Snowflake, but to better understand how these systems actually work behind the scenes, what challenges arise during development, and how all the components integrate together.
Over the past few months, I’ve been building a Python-based AI Agent with the following architecture:
✅ Azure OpenAI as the reasoning engine
✅ Telegram Bot as the user interface
✅ MySQL (on-premises) as the data source (my personal laptop)
✅ Recursive AI ↔ SQL interaction until the final answer is produced
This is a personal learning project built using a demo database and publicly available technologies.
The agent doesn’t simply generate a single SQL statement. Instead, it follows an iterative workflow:
The user asks a question in Telegram.
The application sends the prompt and database schema to Azure OpenAI.
The model decides whether it has enough information or needs additional data from the database.
If SQL is required, the application executes it against MySQL.
The results are returned to the model.
The process repeats until the model can produce the final answer.
To make this process transparent and easy to debug, every interaction is stored as a structured JSON conversation log. This has been incredibly useful for understanding the model’s reasoning and troubleshooting complex scenarios.
Along the way, I also implemented:
• Automatic database schema discovery
• Role-based access control (Read / Write / Admin)
• Automatic user provisioning and management
• Conversation and audit logging
• Recursive execution with configurable iteration limits
• SQL execution
#AI #AIAgents #Python #AzureOpenAI #MySQL #Snowflake #DataEngineering #GenerativeAI #LLM #OpenAI #Automation #SQL #EnterpriseAI #SoftwareEngineerin


