Skip to content

Commit 5fba55d

Browse files
Merge pull request #188 from microsoft/TestingBranch
fix: testing
2 parents 6b7a92a + 53733f0 commit 5fba55d

File tree

4 files changed

+53
-85
lines changed

4 files changed

+53
-85
lines changed

.github/workflows/pylint.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1 @@
1-
name: PyLint
21

3-
on: [push]
4-
5-
jobs:
6-
build:
7-
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
python-version: ["3.11"]
11-
steps:
12-
- uses: actions/checkout@v4
13-
14-
- name: Set up Python ${{ matrix.python-version }}
15-
uses: actions/setup-python@v3
16-
with:
17-
python-version: ${{ matrix.python-version }}
18-
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install -r src/backend/requirements.txt
23-
pip install flake8 # Ensure flake8 is installed explicitly
24-
25-
- name: Run flake8 and pylint
26-
run: |
27-
flake8 --config=.flake8 src/backend # Specify the directory to lint

infra/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var modelVersion = '2024-08-06'
6565
var aiServicesName = '${solutionPrefix}-aiservices'
6666
var deploymentType = 'GlobalStandard'
6767
var gptModelVersion = 'gpt-4o'
68-
var appVersion = 'fnd01'
68+
var appVersion = 'auj01'
6969
var resgistryName = 'biabcontainerreg'
7070
var dockerRegistryUrl = 'https://${resgistryName}.azurecr.io'
7171

infra/main.json

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"_generator": {
77
"name": "bicep",
88
"version": "0.34.44.8038",
9-
"templateHash": "7719893060553487435"
9+
"templateHash": "8198085377798825433"
1010
}
1111
},
1212
"parameters": {
@@ -48,13 +48,12 @@
4848
"description": "Location for all Ai services resources. This location can be different from the resource group location."
4949
}
5050
},
51-
"prefix": {
51+
"environmentName": {
5252
"type": "string",
53-
"defaultValue": "macae",
5453
"minLength": 3,
5554
"maxLength": 20,
5655
"metadata": {
57-
"description": "Prefix for all resources created by this template. This prefix will be used to create unique names for all resources. The prefix must be unique within the resource group."
56+
"description": "A unique prefix for all resources in this deployment. This should be 3-20 characters long:"
5857
}
5958
},
6059
"tags": {
@@ -107,16 +106,18 @@
107106
}
108107
},
109108
"variables": {
109+
"uniqueId": "[toLower(uniqueString(subscription().id, parameters('environmentName'), resourceGroup().location))]",
110+
"solutionPrefix": "[format('ma{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]",
110111
"modelVersion": "2024-08-06",
111-
"aiServicesName": "[format('{0}-aiservices', parameters('prefix'))]",
112+
"aiServicesName": "[format('{0}-aiservices', variables('solutionPrefix'))]",
112113
"deploymentType": "GlobalStandard",
113114
"gptModelVersion": "gpt-4o",
114-
"appVersion": "fnd01",
115+
"appVersion": "auj01",
115116
"resgistryName": "biabcontainerreg",
116117
"dockerRegistryUrl": "[format('https://{0}.azurecr.io', variables('resgistryName'))]",
117118
"backendDockerImageURL": "[format('{0}.azurecr.io/macaebackend:{1}', variables('resgistryName'), variables('appVersion'))]",
118119
"frontendDockerImageURL": "[format('{0}.azurecr.io/macaefrontend:{1}', variables('resgistryName'), variables('appVersion'))]",
119-
"uniqueNameFormat": "[format('{0}-{{0}}-{1}', parameters('prefix'), uniqueString(resourceGroup().id, parameters('prefix')))]",
120+
"uniqueNameFormat": "[format('{0}-{{0}}-{1}', variables('solutionPrefix'), uniqueString(resourceGroup().id, variables('solutionPrefix')))]",
120121
"aoaiApiVersion": "2025-01-01-preview",
121122
"aiModelDeployments": [
122123
{
@@ -224,8 +225,7 @@
224225
"kind": "AIServices",
225226
"properties": {
226227
"customSubDomainName": "[variables('aiServicesName')]",
227-
"apiProperties": {},
228-
"disableLocalAuth": true
228+
"apiProperties": {}
229229
}
230230
},
231231
"aiServicesDeployments": {
@@ -262,7 +262,7 @@
262262
"type": "Microsoft.Authorization/roleAssignments",
263263
"apiVersion": "2022-04-01",
264264
"scope": "[format('Microsoft.CognitiveServices/accounts/{0}', variables('aiServicesName'))]",
265-
"name": "[guid(resourceId('Microsoft.App/containerApps', format('{0}-backend', parameters('prefix'))), resourceId('Microsoft.CognitiveServices/accounts', variables('aiServicesName')), resourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'))]",
265+
"name": "[guid(resourceId('Microsoft.App/containerApps', format('{0}-backend', variables('solutionPrefix'))), resourceId('Microsoft.CognitiveServices/accounts', variables('aiServicesName')), resourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'))]",
266266
"properties": {
267267
"principalId": "[reference('containerApp', '2024-03-01', 'full').identity.principalId]",
268268
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd')]",
@@ -293,8 +293,7 @@
293293
{
294294
"name": "EnableServerless"
295295
}
296-
],
297-
"disableLocalAuth": true
296+
]
298297
}
299298
},
300299
"pullIdentity": {
@@ -327,7 +326,7 @@
327326
"acaCosomsRoleAssignment": {
328327
"type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments",
329328
"apiVersion": "2024-05-15",
330-
"name": "[format('{0}/{1}', format(variables('uniqueNameFormat'), 'cosmos'), guid(resourceId('Microsoft.App/containerApps', format('{0}-backend', parameters('prefix'))), resourceId('Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions', format(variables('uniqueNameFormat'), 'cosmos'), '00000000-0000-0000-0000-000000000002')))]",
329+
"name": "[format('{0}/{1}', format(variables('uniqueNameFormat'), 'cosmos'), guid(resourceId('Microsoft.App/containerApps', format('{0}-backend', variables('solutionPrefix'))), resourceId('Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions', format(variables('uniqueNameFormat'), 'cosmos'), '00000000-0000-0000-0000-000000000002')))]",
331330
"properties": {
332331
"principalId": "[reference('containerApp', '2024-03-01', 'full').identity.principalId]",
333332
"roleDefinitionId": "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions', format(variables('uniqueNameFormat'), 'cosmos'), '00000000-0000-0000-0000-000000000002')]",
@@ -341,7 +340,7 @@
341340
"containerApp": {
342341
"type": "Microsoft.App/containerApps",
343342
"apiVersion": "2024-03-01",
344-
"name": "[format('{0}-backend', parameters('prefix'))]",
343+
"name": "[format('{0}-backend', variables('solutionPrefix'))]",
345344
"location": "[parameters('location')]",
346345
"tags": "[parameters('tags')]",
347346
"identity": {
@@ -532,7 +531,7 @@
532531
"existing": true,
533532
"type": "Microsoft.MachineLearningServices/workspaces",
534533
"apiVersion": "2024-01-01-preview",
535-
"name": "[format('{0}-aiproject', parameters('prefix'))]"
534+
"name": "[format('{0}-aiproject', variables('solutionPrefix'))]"
536535
},
537536
"aiDeveloper": {
538537
"existing": true,
@@ -543,8 +542,8 @@
543542
"aiDeveloperAccessProj": {
544543
"type": "Microsoft.Authorization/roleAssignments",
545544
"apiVersion": "2022-04-01",
546-
"scope": "[format('Microsoft.MachineLearningServices/workspaces/{0}', format('{0}-aiproject', parameters('prefix')))]",
547-
"name": "[guid(format('{0}-backend', parameters('prefix')), resourceId('Microsoft.MachineLearningServices/workspaces', format('{0}-aiproject', parameters('prefix'))), resourceId('Microsoft.Authorization/roleDefinitions', '64702f94-c441-49e6-a78b-ef80e0188fee'))]",
545+
"scope": "[format('Microsoft.MachineLearningServices/workspaces/{0}', format('{0}-aiproject', variables('solutionPrefix')))]",
546+
"name": "[guid(format('{0}-backend', variables('solutionPrefix')), resourceId('Microsoft.MachineLearningServices/workspaces', format('{0}-aiproject', variables('solutionPrefix'))), resourceId('Microsoft.Authorization/roleDefinitions', '64702f94-c441-49e6-a78b-ef80e0188fee'))]",
548547
"properties": {
549548
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', '64702f94-c441-49e6-a78b-ef80e0188fee')]",
550549
"principalId": "[reference('containerApp', '2024-03-01', 'full').identity.principalId]"
@@ -565,7 +564,7 @@
565564
"mode": "Incremental",
566565
"parameters": {
567566
"solutionName": {
568-
"value": "[parameters('prefix')]"
567+
"value": "[variables('solutionPrefix')]"
569568
},
570569
"solutionLocation": {
571570
"value": "[parameters('location')]"
@@ -685,7 +684,7 @@
685684
"mode": "Incremental",
686685
"parameters": {
687686
"solutionName": {
688-
"value": "[parameters('prefix')]"
687+
"value": "[variables('solutionPrefix')]"
689688
},
690689
"solutionLocation": {
691690
"value": "[parameters('azureOpenAILocation')]"
@@ -1094,7 +1093,7 @@
10941093
"mode": "Incremental",
10951094
"parameters": {
10961095
"solutionName": {
1097-
"value": "[parameters('prefix')]"
1096+
"value": "[variables('solutionPrefix')]"
10981097
},
10991098
"managedIdentityId": {
11001099
"value": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format(variables('uniqueNameFormat'), 'containerapp-pull'))]"

src/backend/app_config.py

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,10 @@ async def create_azure_ai_agent(
203203
If an agent with the given name (assistant_id) already exists, it tries to retrieve it first.
204204
205205
Args:
206-
kernel: The Semantic Kernel instance
207206
agent_name: The name of the agent (will be used as assistant_id)
208207
instructions: The system message / instructions for the agent
209-
agent_type: The type of agent (defaults to "assistant")
210208
tools: Optional tool definitions for the agent
211-
tool_resources: Optional tool resources required by the tools
209+
client: Optional AIProjectClient instance
212210
response_format: Optional response format to control structured output
213211
temperature: The temperature setting for the agent (defaults to 0.0)
214212
@@ -220,41 +218,38 @@ async def create_azure_ai_agent(
220218
if client is None:
221219
client = self.get_ai_project_client()
222220

223-
# # ToDo: This is the fixed code but commenting it out as agent clean up is no happening yet
224-
# # and there are multiple versions of agents due to testing
225-
# # First try to get an existing agent with this name as assistant_id
226-
# try:
227-
# agent_id = None
228-
# agent_list = await client.agents.list_agents()
229-
# for agent in agent_list.data:
230-
# if agent.name == agent_name:
231-
# agent_id = agent.id
232-
# break
233-
# # If the agent already exists, we can use it directly
234-
# # Get the existing agent definition
235-
# existing_definition = await client.agents.get_agent(agent_id)
236-
# # Create the agent instance directly with project_client and existing definition
237-
# agent = AzureAIAgent(
238-
# client=client,
239-
# definition=existing_definition,
240-
# plugins=tools,
241-
# )
242-
243-
# client.agents.list_agents()
244-
245-
# return agent
246-
# except Exception as e:
247-
# # The Azure AI Projects SDK throws an exception when the agent doesn't exist
248-
# # (not returning None), so we catch it and proceed to create a new agent
249-
# if "ResourceNotFound" in str(e) or "404" in str(e):
250-
# logging.info(
251-
# f"Agent with ID {agent_name} not found. Will create a new one."
252-
# )
253-
# else:
254-
# # Log unexpected errors but still try to create a new agent
255-
# logging.warning(
256-
# f"Unexpected error while retrieving agent {agent_name}: {str(e)}. Attempting to create new agent."
257-
# )
221+
# First try to get an existing agent with this name as assistant_id
222+
try:
223+
agent_id = None
224+
agent_list = await client.agents.list_agents()
225+
for agent in agent_list.data:
226+
if agent.name == agent_name:
227+
agent_id = agent.id
228+
break
229+
230+
# If the agent already exists, we can use it directly
231+
if agent_id:
232+
# Get the existing agent definition
233+
existing_definition = await client.agents.get_agent(agent_id)
234+
# Create the agent instance directly with project_client and existing definition
235+
agent = AzureAIAgent(
236+
client=client,
237+
definition=existing_definition,
238+
plugins=tools,
239+
)
240+
return agent
241+
except Exception as e:
242+
# The Azure AI Projects SDK throws an exception when the agent doesn't exist
243+
# (not returning None), so we catch it and proceed to create a new agent
244+
if "ResourceNotFound" in str(e) or "404" in str(e):
245+
logging.info(
246+
f"Agent with ID {agent_name} not found. Will create a new one."
247+
)
248+
else:
249+
# Log unexpected errors but still try to create a new agent
250+
logging.warning(
251+
f"Unexpected error while retrieving agent {agent_name}: {str(e)}. Attempting to create new agent."
252+
)
258253

259254
# Create the agent using the project client with the agent_name as both name and assistantId
260255
agent_definition = await client.agents.create_agent(

0 commit comments

Comments
 (0)