|
2 | 2 |
|
3 | 3 | import logging |
4 | 4 |
|
| 5 | +from azure.ai.projects.models import ( |
| 6 | + ResponseFormatJsonSchema, |
| 7 | + ResponseFormatJsonSchemaType, |
| 8 | +) |
| 9 | +from common.config.config import app_config |
5 | 10 | from common.models.api import AgentType |
6 | | -from sql_agents.helpers.sk_utils import create_kernel_with_chat_completion |
7 | | -from sql_agents.helpers.utils import get_prompt |
8 | | -from semantic_kernel.agents import ChatCompletionAgent |
| 11 | +from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent |
9 | 12 | from semantic_kernel.functions import KernelArguments |
10 | 13 | from sql_agents.agent_config import AgentModelDeployment, AgentsConfigDialect |
| 14 | +from sql_agents.helpers.utils import get_prompt |
11 | 15 | from sql_agents.migrator.response import MigratorResponse |
12 | 16 |
|
13 | 17 | logger = logging.getLogger(__name__) |
14 | 18 | logger.setLevel(logging.DEBUG) |
15 | 19 |
|
16 | 20 |
|
17 | | -def setup_migrator_agent( |
| 21 | +async def setup_migrator_agent( |
18 | 22 | name: AgentType, config: AgentsConfigDialect, deployment_name: AgentModelDeployment |
19 | | -) -> ChatCompletionAgent: |
| 23 | +) -> AzureAIAgent: |
20 | 24 | """Setup the migrator agent.""" |
21 | 25 | _deployment_name = deployment_name.value |
22 | 26 | _name = name.value |
23 | | - NUM_CANDIDATES = 3 |
24 | | - |
25 | | - kernel = create_kernel_with_chat_completion(_name, _deployment_name) |
| 27 | + num_candidates = 3 |
26 | 28 |
|
27 | 29 | try: |
28 | 30 | template_content = get_prompt(_name) |
29 | 31 | except FileNotFoundError as exc: |
30 | 32 | logger.error("Prompt file for %s not found.", _name) |
31 | 33 | raise ValueError(f"Prompt file for {_name} not found.") from exc |
32 | 34 |
|
33 | | - settings = kernel.get_prompt_execution_settings_from_service_id( |
34 | | - service_id="migrator" |
35 | | - ) |
36 | | - settings.response_format = MigratorResponse |
37 | | - settings.temperature = 0.0 |
38 | | - |
39 | 35 | kernel_args = KernelArguments( |
40 | 36 | target=config.sql_dialect_out, |
41 | | - numCandidates=str(NUM_CANDIDATES), |
| 37 | + numCandidates=str(num_candidates), |
42 | 38 | source=config.sql_dialect_in, |
43 | | - settings=settings, |
44 | 39 | ) |
45 | 40 |
|
46 | | - migrator_agent = ChatCompletionAgent( |
47 | | - kernel=kernel, |
48 | | - name=name, |
| 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, |
49 | 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, |
50 | 61 | arguments=kernel_args, |
51 | 62 | ) |
52 | 63 |
|
|
0 commit comments