Skip to content

Commit d485867

Browse files
committed
Merge branch 'feature/azd-semantickernel' of https://github.com/microsoft/Multi-Agent-Custom-Automation-Engine-Solution-Accelerator into azd-semantickernel-marktayl
2 parents c27de44 + 658bc27 commit d485867

File tree

7 files changed

+432
-145
lines changed

7 files changed

+432
-145
lines changed

azure.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
2-
environment:
3-
name: multi-agent-custom-automation-engine-solution-accelerator
4-
location: eastus
52
name: multi-agent-custom-automation-engine-solution-accelerator
6-
# metadata:
7-
# template: [email protected]
8-
parameters:
9-
baseUrl:
10-
type: string
11-
default: 'https://github.com/TravisHilbert/Modernize-your-code-solution-accelerator'
12-
deployment:
13-
mode: Incremental
14-
template: ./infra/main.bicep # Path to the main.bicep file inside the 'deployment' folder
3+

infra/deploy_ai_foundry.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,5 @@ output storageAccountName string = storageNameCleaned
298298

299299
output logAnalyticsId string = logAnalytics.id
300300
output storageAccountId string = storage.id
301+
302+
output projectConnectionString string = '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}'

infra/main.bicep

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
@description('Location for all resources.')
2-
param location string = 'EastUS2' //Fixed for model availability, change back to resourceGroup().location
3-
4-
@description('Location for OpenAI resources.')
5-
param azureOpenAILocation string = 'japaneast' //Fixed for model availability
6-
7-
8-
9-
@description('A prefix to add to the start of all resource names. Note: A "unique" suffix will also be added')
10-
param prefix string = 'macaeo'
2+
param location string
3+
4+
@allowed([
5+
'australiaeast'
6+
'brazilsouth'
7+
'canadacentral'
8+
'canadaeast'
9+
'eastus'
10+
'eastus2'
11+
'francecentral'
12+
'germanywestcentral'
13+
'japaneast'
14+
'koreacentral'
15+
'northcentralus'
16+
'norwayeast'
17+
'polandcentral'
18+
'southafricanorth'
19+
'southcentralus'
20+
'southindia'
21+
'swedencentral'
22+
'switzerlandnorth'
23+
'uaenorth'
24+
'uksouth'
25+
'westeurope'
26+
'westus'
27+
'westus3'
28+
])
29+
@description('Location for all Ai services resources. This location can be different from the resource group location.')
30+
param azureOpenAILocation string // The location used for all deployed resources. This location must be in the same region as the resource group.
31+
32+
@minLength(3)
33+
@maxLength(20)
34+
@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.')
35+
param prefix string
1136

1237
@description('Tags to apply to all deployed resources')
1338
param tags object = {}
@@ -30,7 +55,7 @@ param resourceSize {
3055
maxReplicas: 1
3156
}
3257
}
33-
param capacity int = 1
58+
param capacity int = 10
3459

3560

3661
var modelVersion = '2024-08-06'
@@ -141,33 +166,6 @@ module aifoundry 'deploy_ai_foundry.bicep' = {
141166
}
142167
scope: resourceGroup(resourceGroup().name)
143168
}
144-
// resource openai 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
145-
// name: format(uniqueNameFormat, 'openai')
146-
// location: azureOpenAILocation
147-
// tags: tags
148-
// kind: 'OpenAI'
149-
// sku: {
150-
// name: 'S0'
151-
// }
152-
// properties: {
153-
// customSubDomainName: format(uniqueNameFormat, 'openai')
154-
// }
155-
// resource gpt4o 'deployments' = {
156-
// name: 'gpt-4o'
157-
// sku: {
158-
// name: 'GlobalStandard'
159-
// capacity: resourceSize.gpt4oCapacity
160-
// }
161-
// properties: {
162-
// model: {
163-
// format: 'OpenAI'
164-
// name: gptModelVersion
165-
// version: '2024-08-06'
166-
// }
167-
// versionUpgradeOption: 'NoAutoUpgrade'
168-
// }
169-
// }
170-
// }
171169

172170
resource aoaiUserRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-05-01-preview' existing = {
173171
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' //'Cognitive Services OpenAI User'
@@ -338,6 +336,10 @@ resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
338336
name: 'AZURE_OPENAI_ENDPOINT'
339337
value: aiServices.properties.endpoint
340338
}
339+
{
340+
name: 'AZURE_OPENAI_MODEL_NAME'
341+
value: gptModelVersion
342+
}
341343
{
342344
name: 'AZURE_OPENAI_DEPLOYMENT_NAME'
343345
value: gptModelVersion
@@ -347,13 +349,34 @@ resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
347349
value: aoaiApiVersion
348350
}
349351
{
350-
name: 'FRONTEND_SITE_NAME'
351-
value: 'https://${format(uniqueNameFormat, 'frontend')}.azurewebsites.net'
352+
name: 'APPLICATIONINSIGHTS_INSTRUMENTATION_KEY'
353+
value: appInsights.properties.InstrumentationKey
352354
}
353355
{
354356
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
355357
value: appInsights.properties.ConnectionString
356358
}
359+
{
360+
name: 'AZURE_AI_AGENT_PROJECT_CONNECTION_STRING'
361+
value: aifoundry.outputs.projectConnectionString
362+
}
363+
{
364+
name: 'AZURE_AI_SUBSCRIPTION_ID'
365+
value: subscription().subscriptionId
366+
}
367+
{
368+
name: 'AZURE_AI_RESOURCE_GROUP'
369+
value: resourceGroup().name
370+
}
371+
{
372+
name: 'AZURE_AI_PROJECT_NAME'
373+
value: aifoundry.outputs.aiProjectName
374+
}
375+
{
376+
name: 'FRONTEND_SITE_NAME'
377+
value: 'https://${format(uniqueNameFormat, 'frontend')}.azurewebsites.net'
378+
}
379+
357380
]
358381
}
359382
]
@@ -416,6 +439,23 @@ resource frontendAppService 'Microsoft.Web/sites@2021-02-01' = {
416439
}
417440
}
418441

442+
resource aiHubProject 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' existing = {
443+
name: '${prefix}-aiproject' // aiProjectName must be calculated - available at main start.
444+
}
445+
446+
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
447+
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
448+
}
449+
450+
resource aiDeveloperAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
451+
name: guid(containerApp.name, aiHubProject.id, aiDeveloper.id)
452+
scope: aiHubProject
453+
properties: {
454+
roleDefinitionId: aiDeveloper.id
455+
principalId: containerApp.identity.principalId
456+
}
457+
}
458+
419459
var cosmosAssignCli = 'az cosmosdb sql role assignment create --resource-group "${resourceGroup().name}" --account-name "${cosmos.name}" --role-definition-id "${cosmos::contributorRoleDefinition.id}" --scope "${cosmos.id}" --principal-id "${containerApp.identity.principalId}"'
420460

421461
module managedIdentityModule 'deploy_managed_identity.bicep' = {

src/backend/app_kernel.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,6 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
144144

145145
print(f"Plan: {plan}")
146146

147-
if not plan or not plan.id:
148-
# If plan not found by session, try to extract plan ID from result
149-
plan_id_match = re.search(r"Plan '([^']+)'", result)
150-
151-
if plan_id_match:
152-
plan_id = plan_id_match.group(1)
153-
plan = await memory_store.get_plan(plan_id)
154-
155-
# If still no plan found, handle the failure
156-
if not plan or not plan.id:
157-
track_event_if_configured(
158-
"PlanCreationFailed",
159-
{
160-
"session_id": input_task.session_id,
161-
"description": input_task.description,
162-
}
163-
)
164-
raise HTTPException(status_code=400, detail="Error: Failed to create plan")
165-
166147
# Log custom event for successful input task processing
167148
track_event_if_configured(
168149
"InputTaskProcessed",

src/backend/event_utils.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44

55

66
def track_event_if_configured(event_name: str, event_data: dict):
7-
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
8-
if instrumentation_key:
9-
track_event(event_name, event_data)
10-
# else:
11-
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
7+
"""Track an event if Application Insights is configured.
8+
9+
This function safely wraps the Azure Monitor track_event function
10+
to handle potential errors with the ProxyLogger.
11+
12+
Args:
13+
event_name: The name of the event to track
14+
event_data: Dictionary of event data/dimensions
15+
"""
16+
try:
17+
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
18+
if instrumentation_key:
19+
track_event(event_name, event_data)
20+
# else:
21+
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
22+
except AttributeError as e:
23+
# Handle the 'ProxyLogger' object has no attribute 'resource' error
24+
logging.warning(f"ProxyLogger error in track_event: {e}")
25+
except Exception as e:
26+
# Catch any other exceptions to prevent them from bubbling up
27+
logging.warning(f"Error in track_event: {e}")

src/backend/kernel_agents/agent_base.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def __init__(
110110
# Required properties for AgentGroupChat compatibility
111111
self.name = agent_name # This is crucial for AgentGroupChat to identify agents
112112

113-
# Log initialization
114-
logging.info(f"Initialized {agent_name} with {len(self._tools)} tools")
115113

116114
# Register the handler functions
117115
self._register_functions()
@@ -541,11 +539,6 @@ def get_tools_from_config(cls, kernel: sk.Kernel, agent_type: str, config_path:
541539
except Exception as e:
542540
logging.error(f"Failed to create tool '{tool.get('name', 'unknown')}': {str(e)}")
543541

544-
# Log the total number of tools created
545-
if kernel_functions:
546-
logging.info(f"Created {len(kernel_functions)} tools for agent type '{agent_type}'")
547-
else:
548-
logging.info(f"No tools were successfully created for agent type '{agent_type}'")
549542

550543
return kernel_functions
551544

0 commit comments

Comments
 (0)