Skip to content

Commit 07d10c8

Browse files
Merge branch 'dev' into feature/dev-localauthchanges
2 parents 6da96a9 + bc8a402 commit 07d10c8

29 files changed

Lines changed: 135 additions & 154 deletions

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
max-line-length = 88
33
extend-ignore = E501
4-
exclude = .venv, frontend
4+
exclude = .venv, frontend, src/backend/tests
55
ignore = E203, W503, G004, G200, E402

.github/workflows/deploy.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,6 @@ jobs:
168168
echo "Azure Container Registry name: ${acr_name}"
169169
fi
170170
171-
172-
- name: Build the image and update the container app
173-
id: build-and-update
174-
run: |
175-
176-
set -e
177-
# Define variables for acr and container app names
178-
acr_name="${{ env.ACR_NAME }}"
179-
echo "ACR name: {$acr_name}"
180-
backend_container_app_name="macae-backend"
181-
backend_build_image_tag="backend:latest"
182-
183-
echo "Building the container image..."
184-
# Build the image
185-
az acr build -r ${acr_name} -t ${backend_build_image_tag} ./src/backend
186-
echo "Backend image build completed successfully."
187-
188-
frontend_container_app_name="${{ env.APP_SERVICE_NAME }}"
189-
frontend_build_image_tag="frontend:latest"
190-
191-
echo "Building the container image..."
192-
# Build the image
193-
az acr build -r ${acr_name} -t ${frontend_build_image_tag} ./src/frontend
194-
echo "Frontend image build completed successfully."
195-
196-
# Add the new container to the website
197-
az webapp config container set --resource-group ${{ env.RESOURCE_GROUP_NAME }} --name ${frontend_container_app_name} --container-image-name ${acr_name}.azurecr.io/frontend:latest --container-registry-url https://${acr_name}.azurecr.io
198-
199171
200172
- name: Delete Bicep Deployment
201173
if: success()

infra/scripts/checkquota.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# List of Azure regions to check for quota (update as needed)
4+
IFS=', ' read -ra REGIONS <<< "$AZURE_REGIONS"
5+
6+
SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}"
7+
GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}"
8+
AZURE_CLIENT_ID="${AZURE_CLIENT_ID}"
9+
AZURE_TENANT_ID="${AZURE_TENANT_ID}"
10+
AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}"
11+
12+
# Authenticate using Managed Identity
13+
echo "Authentication using Managed Identity..."
14+
if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then
15+
echo "❌ Error: Failed to login using Managed Identity."
16+
exit 1
17+
fi
18+
19+
echo "🔄 Validating required environment variables..."
20+
if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$REGIONS" ]]; then
21+
echo "❌ ERROR: Missing required environment variables."
22+
exit 1
23+
fi
24+
25+
echo "🔄 Setting Azure subscription..."
26+
if ! az account set --subscription "$SUBSCRIPTION_ID"; then
27+
echo "❌ ERROR: Invalid subscription ID or insufficient permissions."
28+
exit 1
29+
fi
30+
echo "✅ Azure subscription set successfully."
31+
32+
# Define models and their minimum required capacities
33+
declare -A MIN_CAPACITY=(
34+
["OpenAI.GlobalStandard.gpt-4o"]=$GPT_MIN_CAPACITY
35+
)
36+
37+
VALID_REGION=""
38+
for REGION in "${REGIONS[@]}"; do
39+
echo "----------------------------------------"
40+
echo "🔍 Checking region: $REGION"
41+
42+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
43+
if [ -z "$QUOTA_INFO" ]; then
44+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
45+
continue
46+
fi
47+
48+
INSUFFICIENT_QUOTA=false
49+
for MODEL in "${!MIN_CAPACITY[@]}"; do
50+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" '
51+
BEGIN { RS="},"; FS="," }
52+
$0 ~ model { print $0 }
53+
')
54+
55+
if [ -z "$MODEL_INFO" ]; then
56+
echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping."
57+
continue
58+
fi
59+
60+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
61+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
62+
63+
CURRENT_VALUE=${CURRENT_VALUE:-0}
64+
LIMIT=${LIMIT:-0}
65+
66+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
67+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
68+
69+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
70+
71+
echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
72+
73+
if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then
74+
echo "❌ ERROR: $MODEL in $REGION has insufficient quota."
75+
INSUFFICIENT_QUOTA=true
76+
break
77+
fi
78+
done
79+
80+
if [ "$INSUFFICIENT_QUOTA" = false ]; then
81+
VALID_REGION="$REGION"
82+
break
83+
fi
84+
85+
done
86+
87+
if [ -z "$VALID_REGION" ]; then
88+
echo "❌ No region with sufficient quota found. Blocking deployment."
89+
echo "QUOTA_FAILED=true" >> "$GITHUB_ENV"
90+
exit 0
91+
else
92+
echo "✅ Final Region: $VALID_REGION"
93+
echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV"
94+
exit 0
95+
fi

src/backend/app_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# app_config.py
22
import os
33
import logging
4-
from typing import Optional, List, Dict, Any
4+
from typing import Optional, List
55
from dotenv import load_dotenv
6-
from azure.identity import DefaultAzureCredential, ClientSecretCredential
6+
from azure.identity import DefaultAzureCredential
77
from azure.cosmos.aio import CosmosClient
88
from azure.ai.projects.aio import AIProjectClient
99
from semantic_kernel.kernel import Kernel
10-
from semantic_kernel.contents import ChatHistory
1110
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
1211
from semantic_kernel.functions import KernelFunction
1312

src/backend/app_kernel.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
# app_kernel.py
22
import asyncio
3-
import json
43
import logging
5-
import os
6-
import re
74
import uuid
8-
from typing import Any, Dict, List, Optional
5+
from typing import Dict, List, Optional
96

107
# Semantic Kernel imports
11-
import semantic_kernel as sk
128
from app_config import config
139
from auth.auth_utils import get_authenticated_user_details
1410

1511
# Azure monitoring
16-
from azure.monitor.opentelemetry import configure_azure_monitor
1712
from config_kernel import Config
18-
from context.cosmos_memory_kernel import CosmosMemoryContext
1913
from event_utils import track_event_if_configured
2014

2115
# FastAPI imports
@@ -26,21 +20,17 @@
2620
# Local imports
2721
from middleware.health_check import HealthCheckMiddleware
2822
from models.messages_kernel import (
29-
ActionRequest,
30-
ActionResponse,
3123
AgentMessage,
3224
AgentType,
3325
HumanClarification,
3426
HumanFeedback,
3527
InputTask,
36-
Plan,
3728
PlanWithSteps,
3829
Step,
3930
)
4031

4132
# Updated import for KernelArguments
42-
from semantic_kernel.functions.kernel_arguments import KernelArguments
43-
from utils_kernel import get_agents, initialize_runtime_and_context, rai_success
33+
from utils_kernel import initialize_runtime_and_context, rai_success
4434

4535
# # Check if the Application Insights Instrumentation Key is set in the environment variables
4636
# connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")

src/backend/config_kernel.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
# config_kernel.py
2-
import os
3-
import logging
4-
import semantic_kernel as sk
5-
from semantic_kernel.kernel import Kernel
6-
7-
# Updated imports for compatibility
8-
try:
9-
# Try newer structure
10-
from semantic_kernel.contents import ChatHistory
11-
except ImportError:
12-
# Fall back to older structure for compatibility
13-
from semantic_kernel.connectors.ai.chat_completion_client import ChatHistory
14-
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
15-
161
# Import AppConfig from app_config
172
from app_config import config
183

src/backend/context/cosmos_memory_kernel.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ async def get_collections(self) -> List[str]:
525525

526526
try:
527527
query = """
528-
SELECT DISTINCT c.collection
529-
FROM c
528+
SELECT DISTINCT c.collection
529+
FROM c
530530
WHERE c.data_type = 'memory' AND c.session_id = @session_id
531531
"""
532532
parameters = [{"name": "@session_id", "value": self.session_id}]
@@ -595,7 +595,7 @@ async def get_memory_record(
595595
) -> Optional[MemoryRecord]:
596596
"""Retrieve a memory record."""
597597
query = """
598-
SELECT * FROM c
598+
SELECT * FROM c
599599
WHERE c.collection=@collection AND c.key=@key AND c.session_id=@session_id AND c.data_type=@data_type
600600
"""
601601
parameters = [
@@ -625,7 +625,7 @@ async def get_memory_record(
625625
async def remove_memory_record(self, collection: str, key: str) -> None:
626626
"""Remove a memory record."""
627627
query = """
628-
SELECT c.id FROM c
628+
SELECT c.id FROM c
629629
WHERE c.collection=@collection AND c.key=@key AND c.session_id=@session_id AND c.data_type=@data_type
630630
"""
631631
parameters = [
@@ -668,7 +668,7 @@ async def get_memory_records(
668668
query = """
669669
SELECT *
670670
FROM c
671-
WHERE c.collection = @collection
671+
WHERE c.collection = @collection
672672
AND c.data_type = 'memory'
673673
AND c.session_id = @session_id
674674
ORDER BY c._ts DESC

src/backend/handlers/runtime_interrupt_kernel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Any, Dict, List, Optional
22

33
import semantic_kernel as sk
4-
from semantic_kernel.kernel_arguments import KernelArguments
54
from semantic_kernel.kernel_pydantic import KernelBaseModel
65

76

src/backend/kernel_agents/agent_base.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import json
21
import logging
3-
import os
4-
from typing import Any, Awaitable, Callable, Dict, List, Mapping, Optional, Union
2+
from typing import Any, List, Mapping, Optional
53

6-
import semantic_kernel as sk
74
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
85
from semantic_kernel.functions import KernelFunction
9-
from semantic_kernel.functions.kernel_arguments import KernelArguments
10-
from semantic_kernel.functions.kernel_function_decorator import kernel_function
11-
from semantic_kernel.agents import AzureAIAgentThread
126

137

148
# Import the new AppConfig instance

src/backend/kernel_agents/agent_factory.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
"""Factory for creating agents in the Multi-Agent Custom Automation Engine."""
22

33
import logging
4-
from typing import Dict, List, Callable, Any, Optional, Type
5-
from types import SimpleNamespace
6-
from semantic_kernel import Kernel
7-
from semantic_kernel.functions import KernelFunction
4+
from typing import Dict, Any, Optional, Type
85
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
96
import inspect
107

@@ -23,7 +20,6 @@
2320
from kernel_agents.product_agent import ProductAgent
2421
from kernel_agents.planner_agent import PlannerAgent # Add PlannerAgent import
2522
from kernel_agents.group_chat_manager import GroupChatManager
26-
from semantic_kernel.prompt_template.prompt_template_config import PromptTemplateConfig
2723
from context.cosmos_memory_kernel import CosmosMemoryContext
2824
from models.messages_kernel import PlannerResponsePlan, AgentType
2925

@@ -216,7 +212,7 @@ async def create_agent(
216212
if hasattr(agent, "async_init") and inspect.iscoroutinefunction(
217213
agent.async_init
218214
):
219-
init_result = await agent.async_init()
215+
await agent.async_init()
220216

221217
except Exception as e:
222218
logger.error(

0 commit comments

Comments
 (0)