Skip to content

Commit afbaabf

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

File tree

10 files changed

+399
-817
lines changed

10 files changed

+399
-817
lines changed

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: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
@description('Location for all resources.')
2-
param location string //Fixed for model availability, change back to resourceGroup().location
3-
2+
param location string = 'EastUS2' //Fixed for model availability, change back to resourceGroup().location
43

54
@description('Location for OpenAI resources.')
65
param azureOpenAILocation string = 'japaneast' //Fixed for model availability
76

87

98

109
@description('A prefix to add to the start of all resource names. Note: A "unique" suffix will also be added')
11-
param prefix string = take('macaeo-${uniqueString(resourceGroup().id)}', 10)
10+
param prefix string = 'macaeo'
1211

1312
@description('Tags to apply to all deployed resources')
1413
param tags object = {}
@@ -31,7 +30,7 @@ param resourceSize {
3130
maxReplicas: 1
3231
}
3332
}
34-
param capacity int = 1
33+
param capacity int = 10
3534

3635

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

173145
resource aoaiUserRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-05-01-preview' existing = {
174146
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' //'Cognitive Services OpenAI User'
@@ -339,6 +311,10 @@ resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
339311
name: 'AZURE_OPENAI_ENDPOINT'
340312
value: aiServices.properties.endpoint
341313
}
314+
{
315+
name: 'AZURE_OPENAI_MODEL_NAME'
316+
value: gptModelVersion
317+
}
342318
{
343319
name: 'AZURE_OPENAI_DEPLOYMENT_NAME'
344320
value: gptModelVersion
@@ -348,13 +324,34 @@ resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
348324
value: aoaiApiVersion
349325
}
350326
{
351-
name: 'FRONTEND_SITE_NAME'
352-
value: 'https://${format(uniqueNameFormat, 'frontend')}.azurewebsites.net'
327+
name: 'APPLICATIONINSIGHTS_INSTRUMENTATION_KEY'
328+
value: appInsights.properties.InstrumentationKey
353329
}
354330
{
355331
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
356332
value: appInsights.properties.ConnectionString
357333
}
334+
{
335+
name: 'AZURE_AI_AGENT_PROJECT_CONNECTION_STRING'
336+
value: aifoundry.outputs.projectConnectionString
337+
}
338+
{
339+
name: 'AZURE_AI_SUBSCRIPTION_ID'
340+
value: subscription().subscriptionId
341+
}
342+
{
343+
name: 'AZURE_AI_RESOURCE_GROUP'
344+
value: resourceGroup().name
345+
}
346+
{
347+
name: 'AZURE_AI_PROJECT_NAME'
348+
value: aifoundry.outputs.aiProjectName
349+
}
350+
{
351+
name: 'FRONTEND_SITE_NAME'
352+
value: 'https://${format(uniqueNameFormat, 'frontend')}.azurewebsites.net'
353+
}
354+
358355
]
359356
}
360357
]
@@ -417,6 +414,23 @@ resource frontendAppService 'Microsoft.Web/sites@2021-02-01' = {
417414
}
418415
}
419416

417+
resource aiHubProject 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' existing = {
418+
name: '${prefix}-aiproject' // aiProjectName must be calculated - available at main start.
419+
}
420+
421+
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
422+
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
423+
}
424+
425+
resource aiDeveloperAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
426+
name: guid(containerApp.name, aiHubProject.id, aiDeveloper.id)
427+
scope: aiHubProject
428+
properties: {
429+
roleDefinitionId: aiDeveloper.id
430+
principalId: containerApp.identity.principalId
431+
}
432+
}
433+
420434
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}"'
421435

422436
module managedIdentityModule 'deploy_managed_identity.bicep' = {

src/backend/app_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ async def create_azure_ai_agent(
219219
tool_definitions = tools
220220

221221
# Create the agent using the project client
222-
logging.info("Creating agent '%s' with model '%s'", agent_name, self.AZURE_OPENAI_DEPLOYMENT_NAME)
222+
if response_format is not None:
223+
logging.info("Response format provided: %s", response_format)
224+
225+
223226
agent_definition = await project_client.agents.create_agent(
224227
model=self.AZURE_OPENAI_DEPLOYMENT_NAME,
225228
name=agent_name,

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)