feat: Agent Factory Refactor + SQL Agent Integration#513
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the agent factory system to use a new BaseAgentFactory, introduces a SQLAgentFactory for T-SQL generation, and integrates SQL agents into the app and the ChatWithDataPlugin.
- Added
BaseAgentFactoryand updated existing factories (ConversationAgentFactory,SearchAgentFactory) to inherit from it. - Implemented
SQLAgentFactoryto create and delete SQL agents via Azure AI Projects. - Updated
ChatWithDataPluginandapp.pyto use the new SQL agent; addedAZURE_AI_AGENT_API_VERSIONto config.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/api/agents/agent_factory_base.py | New base class providing singleton agent creation/deletion |
| src/api/agents/search_agent_factory.py | Refactored to extend base factory; missing ai_search import |
| src/api/agents/sql_agent_factory.py | New SQL agent factory; uses sync credential in async flow |
| src/api/plugins/chat_with_data_plugin.py | Replaced inline SQL logic with SQLAgentFactory calls |
| src/api/app.py | Integrated SQL agent into FastAPI lifecycle |
| src/api/common/config/config.py | Added ai_project_api_version configuration |
Comments suppressed due to low confidence (1)
src/api/agents/search_agent_factory.py:3
- The code references
ai_search.definitionsandai_search.resourcesbut does not importai_search. Please addfrom azure.ai.search import ai_searchto ensure the module is available.
from azure.ai.projects import AIProjectClient
Pavan-Microsoft
marked this pull request as ready for review
July 4, 2025 11:27
Pavan-Microsoft
requested review from
Avijit-Microsoft,
Prajwal-Microsoft,
Roopan-Microsoft,
Vinay-Microsoft,
aniaroramsft and
brittneek
as code owners
July 4, 2025 11:27
Avijit-Microsoft
approved these changes
Jul 4, 2025
Contributor
|
🎉 This PR is included in version 3.11.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This pull request introduces significant enhancements to the agent factory system in the
src/apimodule, including the addition of a base factory class, refactoring of existing agent factories, and the introduction of a new SQL agent factory. These changes improve modularity, reusability, and scalability of the codebase. Additionally, the pull request updates the configuration system and integrates the new SQL agent into the application lifecycle.Agent Factory System Enhancements:
src/api/agents/agent_factory_base.py: Added a newBaseAgentFactoryclass to provide a reusable base for agent factories, implementing common methods likeget_agent,delete_agent, and abstract methods for creating and deleting agents.src/api/agents/conversation_agent_factory.py: RefactoredConversationAgentFactoryto inherit fromBaseAgentFactory, simplifying code and adhering to the new modular structure. Updated agent instructions to handle greetings explicitly.src/api/agents/search_agent_factory.py: RefactoredSearchAgentFactoryto inherit fromBaseAgentFactory, improving code reuse and simplifying agent creation logic.src/api/agents/sql_agent_factory.py: Introduced a newSQLAgentFactoryclass to create SQL agents for generating T-SQL queries based on user input and predefined schemas.Application Integration:
src/api/app.py: Integrated the newSQLAgentFactoryinto the application lifecycle, ensuring its agent is initialized and cleaned up alongside other agents. [1] [2]Configuration Updates:
src/api/.env.sample: AddedAZURE_AI_AGENT_API_VERSIONto support versioning for Azure AI Project APIs.src/api/common/config/config.py: Updated the configuration class to includeai_project_api_versionwith a default value.Plugin Refactoring:
src/api/plugins/chat_with_data_plugin.py: Refactored theChatWithDataPluginto use the newSQLAgentFactoryfor generating and executing SQL queries, replacing the previous logic for handling SQL generation. Improved error handling and cleanup processes. [1] [2]Does this introduce a breaking change?
Golden Path Validation
Deployment Validation