-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathagents_manager.py
More file actions
80 lines (67 loc) · 2.79 KB
/
agents_manager.py
File metadata and controls
80 lines (67 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Module to manage the SQL agents for migration."""
import logging
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent # pylint: disable=E0611
from sql_agents.agents.agent_config import AgentBaseConfig
from sql_agents.agents.fixer.setup import setup_fixer_agent
from sql_agents.agents.migrator.setup import setup_migrator_agent
from sql_agents.agents.picker.setup import setup_picker_agent
from sql_agents.agents.semantic_verifier.setup import setup_semantic_verifier_agent
from sql_agents.agents.syntax_checker.setup import setup_syntax_checker_agent
from sql_agents.helpers.models import AgentType
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
class SqlAgents:
"""Class to setup the SQL agents for migration."""
# List of agents in the solution
agent_fixer: AzureAIAgent = None
agent_migrator: AzureAIAgent = None
agent_picker: AzureAIAgent = None
agent_syntax_checker: AzureAIAgent = None
agent_semantic_verifier: AzureAIAgent = None
agent_config: AgentBaseConfig = None
def __init__(self):
pass
@classmethod
async def create(cls, config: AgentBaseConfig):
"""Create the SQL agents for migration.
Required as init cannot be async
"""
self = cls() # Create an instance
try:
self.agent_config = config
self.agent_fixer = await setup_fixer_agent(config)
self.agent_migrator = await setup_migrator_agent(config)
self.agent_picker = await setup_picker_agent(config)
self.agent_syntax_checker = await setup_syntax_checker_agent(config)
self.agent_semantic_verifier = await setup_semantic_verifier_agent(config)
except ValueError as exc:
logger.error("Error setting up agents.")
raise exc
return self
@property
def agents(self):
"""Return a list of the agents."""
return [
self.agent_migrator,
self.agent_picker,
self.agent_syntax_checker,
self.agent_fixer,
self.agent_semantic_verifier,
]
@property
def idx_agents(self):
"""Return a list of the main agents."""
return {
AgentType.MIGRATOR: self.agent_migrator,
AgentType.PICKER: self.agent_picker,
AgentType.SYNTAX_CHECKER: self.agent_syntax_checker,
AgentType.FIXER: self.agent_fixer,
AgentType.SEMANTIC_VERIFIER: self.agent_semantic_verifier,
}
async def delete_agents(self):
"""Cleans up the agents from Azure Foundry"""
try:
for agent in self.agents:
await self.agent_config.ai_project_client.agents.delete_agent(agent.id)
except Exception as exc:
logger.error("Error deleting agents: %s", exc)