|
6 | 6 | ResponseFormatJsonSchema, |
7 | 7 | ResponseFormatJsonSchemaType, |
8 | 8 | ) |
| 9 | +from backend.sql_agents.agent_base import BaseSQLAgent |
| 10 | +from backend.sql_agents.agent_factory import SQLAgentFactory |
9 | 11 | from common.config.config import app_config |
10 | 12 | from common.models.api import AgentType |
11 | 13 | from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent |
|
18 | 20 | logger.setLevel(logging.DEBUG) |
19 | 21 |
|
20 | 22 |
|
| 23 | +class MigratorAgent(BaseSQLAgent[MigratorResponse]): |
| 24 | + """Migrator agent for translating SQL from one dialect to another.""" |
| 25 | + |
| 26 | + @property |
| 27 | + def response_schema(self) -> type: |
| 28 | + """Get the response schema for the migrator agent.""" |
| 29 | + return MigratorResponse |
| 30 | + |
| 31 | + @property |
| 32 | + def num_candidates(self) -> int: |
| 33 | + """Get the number of candidates for the migrator agent.""" |
| 34 | + return 3 |
| 35 | + |
| 36 | + |
21 | 37 | async def setup_migrator_agent( |
22 | 38 | name: AgentType, config: AgentsConfigDialect, deployment_name: AgentModelDeployment |
23 | 39 | ) -> AzureAIAgent: |
24 | | - """Setup the migrator agent.""" |
25 | | - _deployment_name = deployment_name.value |
26 | | - _name = name.value |
27 | | - num_candidates = 3 |
28 | | - |
29 | | - try: |
30 | | - template_content = get_prompt(_name) |
31 | | - except FileNotFoundError as exc: |
32 | | - logger.error("Prompt file for %s not found.", _name) |
33 | | - raise ValueError(f"Prompt file for {_name} not found.") from exc |
34 | | - |
35 | | - kernel_args = KernelArguments( |
36 | | - target=config.sql_dialect_out, |
37 | | - numCandidates=str(num_candidates), |
38 | | - source=config.sql_dialect_in, |
39 | | - ) |
40 | | - |
41 | | - # Define an agent on the Azure AI agent service |
42 | | - agent_definition = await app_config.ai_project_client.agents.create_agent( |
43 | | - model=_deployment_name, |
44 | | - name=_name, |
45 | | - instructions=template_content, |
46 | | - temperature=0.0, |
47 | | - response_format=ResponseFormatJsonSchemaType( |
48 | | - json_schema=ResponseFormatJsonSchema( |
49 | | - name="MigratorResponse", |
50 | | - description="respond with migrator response", |
51 | | - schema=MigratorResponse.model_json_schema(), |
52 | | - ) |
53 | | - ), |
54 | | - ) |
55 | | - |
56 | | - # Create a Semantic Kernel agent based on the agent definition. |
57 | | - # Add RAG with docs programmatically for this one |
58 | | - migrator_agent = AzureAIAgent( |
59 | | - client=app_config.ai_project_client, |
60 | | - definition=agent_definition, |
61 | | - arguments=kernel_args, |
62 | | - ) |
63 | | - |
64 | | - return migrator_agent |
| 40 | + """Setup the migrator agent using the factory.""" |
| 41 | + return await SQLAgentFactory.create_agent(name, config, deployment_name) |
| 42 | + |
| 43 | + |
| 44 | +# async def setup_migrator_agent( |
| 45 | +# name: AgentType, config: AgentsConfigDialect, deployment_name: AgentModelDeployment |
| 46 | +# ) -> AzureAIAgent: |
| 47 | +# """Setup the migrator agent.""" |
| 48 | +# _deployment_name = deployment_name.value |
| 49 | +# _name = name.value |
| 50 | +# num_candidates = 3 |
| 51 | + |
| 52 | +# try: |
| 53 | +# template_content = get_prompt(_name) |
| 54 | +# except FileNotFoundError as exc: |
| 55 | +# logger.error("Prompt file for %s not found.", _name) |
| 56 | +# raise ValueError(f"Prompt file for {_name} not found.") from exc |
| 57 | + |
| 58 | +# kernel_args = KernelArguments( |
| 59 | +# target=config.sql_dialect_out, |
| 60 | +# numCandidates=str(num_candidates), |
| 61 | +# source=config.sql_dialect_in, |
| 62 | +# ) |
| 63 | + |
| 64 | +# # Define an agent on the Azure AI agent service |
| 65 | +# agent_definition = await app_config.ai_project_client.agents.create_agent( |
| 66 | +# model=_deployment_name, |
| 67 | +# name=_name, |
| 68 | +# instructions=template_content, |
| 69 | +# temperature=0.0, |
| 70 | +# response_format=ResponseFormatJsonSchemaType( |
| 71 | +# json_schema=ResponseFormatJsonSchema( |
| 72 | +# name="MigratorResponse", |
| 73 | +# description="respond with migrator response", |
| 74 | +# schema=MigratorResponse.model_json_schema(), |
| 75 | +# ) |
| 76 | +# ), |
| 77 | +# ) |
| 78 | + |
| 79 | +# # Create a Semantic Kernel agent based on the agent definition. |
| 80 | +# # Add RAG with docs programmatically for this one |
| 81 | +# migrator_agent = AzureAIAgent( |
| 82 | +# client=app_config.ai_project_client, |
| 83 | +# definition=agent_definition, |
| 84 | +# arguments=kernel_args, |
| 85 | +# ) |
| 86 | + |
| 87 | +# return migrator_agent |
0 commit comments