Skip to content

Commit 25f18b6

Browse files
committed
2 parents fbd733b + b1ecaaa commit 25f18b6

13 files changed

Lines changed: 202 additions & 73 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,6 @@ __pycache__/
470470
data/sample_code/
471471
# Bicep local files
472472
*.local*.bicepparam
473-
*.local*.parameters.json
473+
*.local*.parameters.json
474+
# Local debug/ops scripts (not for repo)
475+
scripts/

data/agent_teams/content_gen.json

Lines changed: 10 additions & 26 deletions
Large diffs are not rendered by default.

infra/scripts/Selecting-Team-Config-And-Data.ps1

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ Write-Host "2. Retail Customer Satisfaction"
395395
Write-Host "3. HR Employee Onboarding"
396396
Write-Host "4. Marketing Press Release"
397397
Write-Host "5. Contract Compliance Review"
398-
Write-Host "6. All"
398+
Write-Host "7. All"
399399
Write-Host "==============================================="
400400
Write-Host ""
401401

@@ -404,7 +404,7 @@ do {
404404
$useCaseSelection = Read-Host "Please enter the number of the use case you would like to install."
405405

406406
# Handle both numeric and text input for 'all'
407-
if ($useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
407+
if ($useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
408408
$selectedUseCase = "All"
409409
$useCaseValid = $true
410410
Write-Host "Selected: All use cases will be installed."
@@ -439,9 +439,13 @@ do {
439439
Write-Host "Selected: Contract Compliance Review"
440440
Write-Host "Note: If you choose to install a single use case, installation of other use cases will require re-running this script."
441441
}
442+
elseif ($useCaseSelection -eq "6") {
443+
$useCaseValid = $false
444+
Write-Host "Invalid selection. Please enter a number from 1-5 or 7." -ForegroundColor Red
445+
}
442446
else {
443447
$useCaseValid = $false
444-
Write-Host "Invalid selection. Please enter a number from 1-6." -ForegroundColor Red
448+
Write-Host "Invalid selection. Please enter a number from 1-5 or 7." -ForegroundColor Red
445449
}
446450
} while (-not $useCaseValid)
447451

@@ -526,7 +530,7 @@ $isSampleDataFailed = $false
526530
$failedTeamConfigs = 0
527531

528532
# Use Case 3 -----=--
529-
if($useCaseSelection -eq "3" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
533+
if($useCaseSelection -eq "3" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
530534
Write-Host "Uploading Team Configuration for HR Employee Onboarding..."
531535
$directoryPath = "data/agent_teams"
532536
$teamId = "00000000-0000-0000-0000-000000000001"
@@ -545,7 +549,7 @@ if($useCaseSelection -eq "3" -or $useCaseSelection -eq "all" -or $useCaseSelecti
545549
}
546550

547551
# Use Case 4 -----=--
548-
if($useCaseSelection -eq "4" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
552+
if($useCaseSelection -eq "4" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
549553
Write-Host "Uploading Team Configuration for Marketing Press Release..."
550554
$directoryPath = "data/agent_teams"
551555
$teamId = "00000000-0000-0000-0000-000000000002"
@@ -566,7 +570,7 @@ if($useCaseSelection -eq "4" -or $useCaseSelection -eq "all" -or $useCaseSelecti
566570
$stIsPublicAccessDisabled = $false
567571
$srchIsPublicAccessDisabled = $false
568572
# Enable public access for resources
569-
if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6"){
573+
if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection -eq "5" -or $useCaseSelection -eq "6" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7"){
570574
if ($ResourceGroup) {
571575
# Check if resource group has Type=WAF tag
572576
$rgTypeTag = (az group show --name $ResourceGroup --query "tags.Type" -o tsv 2>$null)
@@ -658,7 +662,7 @@ if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection
658662

659663

660664

661-
if($useCaseSelection -eq "1" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
665+
if($useCaseSelection -eq "1" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
662666
Write-Host "Uploading Team Configuration for RFP Evaluation..."
663667
$directoryPath = "data/agent_teams"
664668
$teamId = "00000000-0000-0000-0000-000000000004"
@@ -732,7 +736,7 @@ if($useCaseSelection -eq "1" -or $useCaseSelection -eq "all" -or $useCaseSelecti
732736
}
733737

734738

735-
if($useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
739+
if($useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
736740
Write-Host "Uploading Team Configuration for Contract Compliance Review..."
737741
$directoryPath = "data/agent_teams"
738742
$teamId = "00000000-0000-0000-0000-000000000005"
@@ -805,7 +809,7 @@ if($useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelecti
805809
Write-Host "Python script to index data for Contract Compliance Review successfully executed."
806810
}
807811

808-
if($useCaseSelection -eq "2" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6") {
812+
if($useCaseSelection -eq "2" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7") {
809813
Write-Host "Uploading Team Configuration for Retail Customer Satisfaction..."
810814
$directoryPath = "data/agent_teams"
811815
$teamId = "00000000-0000-0000-0000-000000000003"
@@ -866,7 +870,7 @@ if ($isTeamConfigFailed -or $isSampleDataFailed) {
866870
Write-Host "`nOne or more tasks failed. Please check the error messages above."
867871
exit 1
868872
} else {
869-
if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6"){
873+
if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "7"){
870874
Write-Host "`nTeam configuration upload and sample data processing completed successfully."
871875
}else {
872876
Write-Host "`nTeam configuration upload completed successfully."

infra/scripts/selecting_team_config_and_data.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ echo "2. Retail Customer Satisfaction"
408408
echo "3. HR Employee Onboarding"
409409
echo "4. Marketing Press Release"
410410
echo "5. Contract Compliance Review"
411-
echo "6. All"
411+
echo "7. All"
412412
echo "==============================================="
413413
echo ""
414414

@@ -418,7 +418,7 @@ while [[ "$useCaseValid" != true ]]; do
418418
read -p "Please enter the number of the use case you would like to install: " useCaseSelection
419419

420420
# Handle both numeric and text input for 'all'
421-
if [[ "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
421+
if [[ "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
422422
selectedUseCase="All"
423423
useCaseValid=true
424424
echo "Selected: All use cases will be installed."
@@ -447,9 +447,12 @@ while [[ "$useCaseValid" != true ]]; do
447447
useCaseValid=true
448448
echo "Selected: Contract Compliance Review"
449449
echo "Note: If you choose to install a single use case, installation of other use cases will require re-running this script."
450+
elif [[ "$useCaseSelection" == "6" ]]; then
451+
useCaseValid=false
452+
echo -e "\033[31mInvalid selection. Please enter a number from 1-5 or 7.\033[0m"
450453
else
451454
useCaseValid=false
452-
echo -e "\033[31mInvalid selection. Please enter a number from 1-6.\033[0m"
455+
echo -e "\033[31mInvalid selection. Please enter a number from 1-5 or 7.\033[0m"
453456
fi
454457
done
455458

@@ -523,7 +526,7 @@ isSampleDataFailed=false
523526
failedTeamConfigs=0
524527

525528
# Use Case 3 - HR Employee Onboarding
526-
if [[ "$useCaseSelection" == "3" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
529+
if [[ "$useCaseSelection" == "3" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
527530
echo "Uploading Team Configuration for HR Employee Onboarding..."
528531
directoryPath="data/agent_teams"
529532
teamId="00000000-0000-0000-0000-000000000001"
@@ -538,7 +541,7 @@ if [[ "$useCaseSelection" == "3" || "$useCaseSelection" == "all" || "$useCaseSel
538541
fi
539542

540543
# Use Case 4 - Marketing Press Release
541-
if [[ "$useCaseSelection" == "4" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
544+
if [[ "$useCaseSelection" == "4" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
542545
echo "Uploading Team Configuration for Marketing Press Release..."
543546
directoryPath="data/agent_teams"
544547
teamId="00000000-0000-0000-0000-000000000002"
@@ -553,7 +556,7 @@ if [[ "$useCaseSelection" == "4" || "$useCaseSelection" == "all" || "$useCaseSel
553556
fi
554557

555558
# Enable public access for resources
556-
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
559+
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelection" == "5" || "$useCaseSelection" == "6" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
557560
if [[ -n "$ResourceGroup" ]]; then
558561
# Check if resource group has Type=WAF tag
559562
rgTypeTag=$(az group show --name "$ResourceGroup" --query "tags.Type" -o tsv 2>/dev/null)
@@ -643,7 +646,7 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelec
643646
fi
644647

645648
# Use Case 1 - RFP Evaluation
646-
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
649+
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
647650
echo "Uploading Team Configuration for RFP Evaluation..."
648651
directoryPath="data/agent_teams"
649652
teamId="00000000-0000-0000-0000-000000000004"
@@ -706,7 +709,7 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "all" || "$useCaseSel
706709
fi
707710

708711
# Use Case 5 - Contract Compliance Review
709-
if [[ "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
712+
if [[ "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
710713
echo "Uploading Team Configuration for Contract Compliance Review..."
711714
directoryPath="data/agent_teams"
712715
teamId="00000000-0000-0000-0000-000000000005"
@@ -769,7 +772,7 @@ if [[ "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSel
769772
fi
770773

771774
# Use Case 2 - Retail Customer Satisfaction
772-
if [[ "$useCaseSelection" == "2" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
775+
if [[ "$useCaseSelection" == "2" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
773776
echo "Uploading Team Configuration for Retail Customer Satisfaction..."
774777
directoryPath="data/agent_teams"
775778
teamId="00000000-0000-0000-0000-000000000003"
@@ -821,7 +824,7 @@ if [[ "$isTeamConfigFailed" == true || "$isSampleDataFailed" == true ]]; then
821824
echo "One or more tasks failed. Please check the error messages above."
822825
exit 1
823826
else
824-
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSelection" == "6" ]]; then
827+
if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelection" == "5" || "$useCaseSelection" == "all" || "$useCaseSelection" == "7" ]]; then
825828
echo ""
826829
echo "Team configuration upload and sample data processing completed successfully."
827830
else

infra/scripts/upload_team_config.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def check_team_exists(backend_url, team_id, user_principal_id):
5252
("retail.json", "00000000-0000-0000-0000-000000000003"),
5353
("rfp_analysis_team.json", "00000000-0000-0000-0000-000000000004"),
5454
("contract_compliance_team.json", "00000000-0000-0000-0000-000000000005"),
55+
("ad_copy_team.json", "00000000-0000-0000-0000-000000000006"),
5556
]
5657

5758
upload_endpoint = backend_url.rstrip('/') + '/api/v4/upload_team_config'
@@ -65,15 +66,20 @@ def check_team_exists(backend_url, team_id, user_principal_id):
6566
print(f"Uploading file: {filename}")
6667
team_exists = check_team_exists(backend_url, team_id, user_principal_id)
6768
if team_exists:
69+
# Delete existing team to allow re-upload with updated config
70+
print(f"Team (ID: {team_id}) already exists. Deleting to re-upload with latest config...")
71+
delete_endpoint = backend_url.rstrip('/') + f'/api/v4/team_configs/{team_id}'
72+
headers = {
73+
'x-ms-client-principal-id': user_principal_id
74+
}
6875
try:
69-
with open(file_path, 'r', encoding='utf-8') as f:
70-
team_data = json.load(f)
71-
team_name = team_data.get('name', 'Unknown')
72-
print(f"Team '{team_name}' (ID: {team_id}) already exists!")
73-
continue
76+
delete_response = requests.delete(delete_endpoint, headers=headers)
77+
if delete_response.status_code == 200:
78+
print(f"Successfully deleted existing team (ID: {team_id}).")
79+
else:
80+
print(f"Warning: Could not delete existing team (ID: {team_id}). Status: {delete_response.status_code}. Will attempt upload anyway.")
7481
except Exception as e:
75-
print(f"Error reading {filename}: {str(e)}")
76-
continue
82+
print(f"Warning: Exception deleting team (ID: {team_id}): {str(e)}. Will attempt upload anyway.")
7783

7884
try:
7985
with open(file_path, 'rb') as file_data:

src/backend/common/config/app_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,14 @@ def get_ai_project_client(self):
241241
)
242242

243243
endpoint = self.AZURE_AI_AGENT_ENDPOINT
244+
# Extended HTTP timeouts to reduce transient "Request timed out"
245+
# responses that cause the Magentic orchestrator to reset.
244246
self._ai_project_client = AIProjectClient(
245-
endpoint=endpoint, credential=credential
247+
endpoint=endpoint,
248+
credential=credential,
249+
connection_timeout=30,
250+
read_timeout=180,
251+
retry_total=5,
246252
)
247253

248254
return self._ai_project_client

src/backend/v4/api/router.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,26 @@ async def process_request(
332332
try:
333333

334334
async def run_orchestration_task():
335-
await OrchestrationManager().run_orchestration(user_id, input_task)
336-
337-
background_tasks.add_task(run_orchestration_task)
335+
try:
336+
await OrchestrationManager().run_orchestration(user_id, input_task)
337+
finally:
338+
# Clear our slot if we're still the registered active task
339+
current = orchestration_config.active_tasks.get(user_id)
340+
if current is not None and current.done():
341+
orchestration_config.active_tasks.pop(user_id, None)
342+
343+
# Cancel any in-flight orchestration for this user before starting a new one
344+
prior_task = orchestration_config.active_tasks.get(user_id)
345+
if prior_task is not None and not prior_task.done():
346+
try:
347+
prior_task.cancel()
348+
except Exception:
349+
pass
350+
orchestration_config.active_tasks.pop(user_id, None)
351+
352+
# Schedule new task and register it so subsequent requests can cancel it
353+
new_task = asyncio.create_task(run_orchestration_task())
354+
orchestration_config.active_tasks[user_id] = new_task
338355

339356
return {
340357
"status": "Request started successfully",

src/backend/v4/config/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def __init__(self):
9191
self.sockets: Dict[str, WebSocket] = {} # user_id -> WebSocket
9292
self.clarifications: Dict[str, str] = {} # m_plan_id -> clarification response
9393
self.max_rounds: int = 20 # Maximum replanning rounds
94+
# Track in-flight orchestration tasks per user so a new plan cancels any old one
95+
self.active_tasks: Dict[str, asyncio.Task] = {} # user_id -> running asyncio.Task
9496

9597
# Event-driven notification system for approvals and clarifications
9698
self._approval_events: Dict[str, asyncio.Event] = {}

src/backend/v4/magentic_agents/common/lifecycle.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ async def open(self) -> "MCPEnabledBase":
7070
self.creds = DefaultAzureCredential()
7171
if self._stack:
7272
await self._stack.enter_async_context(self.creds)
73-
# Create AgentsClient
73+
# Create AgentsClient with extended HTTP timeouts to reduce transient
74+
# "Request timed out" responses on /threads/{id}/messages that cause the
75+
# Magentic orchestrator to reset and re-run prior agents.
7476
self.client = AgentsClient(
7577
endpoint=self.project_endpoint,
7678
credential=self.creds,
79+
connection_timeout=30,
80+
read_timeout=180,
81+
retry_total=5,
7782
)
7883
if self._stack:
7984
await self._stack.enter_async_context(self.client)

0 commit comments

Comments
 (0)