Skip to content

feat: Agent Factory Refactor + SQL Agent Integration#513

Merged
Avijit-Microsoft merged 4 commits into
devfrom
psl-pk-km-sqlagent
Jul 4, 2025
Merged

feat: Agent Factory Refactor + SQL Agent Integration#513
Avijit-Microsoft merged 4 commits into
devfrom
psl-pk-km-sqlagent

Conversation

@Pavan-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This pull request introduces significant enhancements to the agent factory system in the src/api module, 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 new BaseAgentFactory class to provide a reusable base for agent factories, implementing common methods like get_agent, delete_agent, and abstract methods for creating and deleting agents.
  • src/api/agents/conversation_agent_factory.py: Refactored ConversationAgentFactory to inherit from BaseAgentFactory, simplifying code and adhering to the new modular structure. Updated agent instructions to handle greetings explicitly.
  • src/api/agents/search_agent_factory.py: Refactored SearchAgentFactory to inherit from BaseAgentFactory, improving code reuse and simplifying agent creation logic.
  • src/api/agents/sql_agent_factory.py: Introduced a new SQLAgentFactory class to create SQL agents for generating T-SQL queries based on user input and predefined schemas.

Application Integration:

  • src/api/app.py: Integrated the new SQLAgentFactory into the application lifecycle, ensuring its agent is initialized and cleaned up alongside other agents. [1] [2]

Configuration Updates:

Plugin Refactoring:

  • src/api/plugins/chat_with_data_plugin.py: Refactored the ChatWithDataPlugin to use the new SQLAgentFactory for 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?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

@Pavan-Microsoft
Pavan-Microsoft requested a review from Copilot July 3, 2025 13:31
@Pavan-Microsoft
Pavan-Microsoft changed the base branch from main to dev July 3, 2025 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BaseAgentFactory and updated existing factories (ConversationAgentFactory, SearchAgentFactory) to inherit from it.
  • Implemented SQLAgentFactory to create and delete SQL agents via Azure AI Projects.
  • Updated ChatWithDataPlugin and app.py to use the new SQL agent; added AZURE_AI_AGENT_API_VERSION to 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.definitions and ai_search.resources but does not import ai_search. Please add from azure.ai.search import ai_search to ensure the module is available.
from azure.ai.projects import AIProjectClient

Comment thread src/api/plugins/chat_with_data_plugin.py
Comment thread src/api/agents/sql_agent_factory.py
Comment thread src/api/plugins/chat_with_data_plugin.py
@Avijit-Microsoft
Avijit-Microsoft merged commit 58fdd82 into dev Jul 4, 2025
7 checks passed
@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants