Skip to content

Commit f400523

Browse files
authored
Merge pull request #15 from MicrosoftCloudEssentials-LearningHub/agents-new-sdk
agents deployed with new sdk
2 parents 7673b8f + 80b380a commit f400523

7 files changed

Lines changed: 107 additions & 23 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ graph TD
157157
158158
<img width="1881" height="1000" alt="image" src="https://github.com/user-attachments/assets/59a9dcaf-9291-403c-b8b0-1195c1375aac" />
159159

160+
> E.g `New Platform`:
161+
162+
<img width="1887" height="606" alt="image" src="https://github.com/user-attachments/assets/02f9e726-6274-490e-8db7-111885a13871" />
163+
160164
5. **Application Deployment**:
161165
- Builds the Docker container with A2A protocol support in the cloud (ACR Build).
162166
- Configures the Azure Web App with the generated Agent IDs, A2A endpoints, and credentials.
@@ -202,7 +206,7 @@ graph TD
202206

203207
<!-- START BADGE -->
204208
<div align="center">
205-
<img src="https://img.shields.io/badge/Total%20views-1329-limegreen" alt="Total views">
209+
<img src="https://img.shields.io/badge/Total%20views-1325-limegreen" alt="Total views">
206210
<p>Refresh Date: 2026-01-29</p>
207211
</div>
208212
<!-- END BADGE -->

TROUBLESHOOTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2026-01-12
8+
Last updated: 2026-01-29
99

1010
----------
1111

@@ -347,7 +347,7 @@ terraform apply
347347

348348
<!-- START BADGE -->
349349
<div align="center">
350-
<img src="https://img.shields.io/badge/Total%20views-1329-limegreen" alt="Total views">
350+
<img src="https://img.shields.io/badge/Total%20views-1325-limegreen" alt="Total views">
351351
<p>Refresh Date: 2026-01-29</p>
352352
</div>
353353
<!-- END BADGE -->

src/a2a/status_automation.ps1

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1-
# Check A2A Automation Framework Status
1+
param(
2+
[string]$WebAppName = $env:WEB_APP_NAME,
3+
[string]$StatusUrl = $env:A2A_AUTOMATION_STATUS_URL
4+
)
5+
6+
# Check A2A Automation Framework Status
27
Write-Host "Checking A2A Automation Framework status..."
3-
= Get-Process -Name "python" -ErrorAction SilentlyContinue | Where-Object { .CommandLine -like "*automated_main*" }
4-
if () {
8+
$processes = Get-CimInstance Win32_Process -ErrorAction SilentlyContinue |
9+
Where-Object { $_.CommandLine -like "*automated_main*" }
10+
11+
if ($processes) {
512
Write-Host "A2A Automation Framework is RUNNING"
6-
Write-Host "Processes: 0"
7-
| Format-Table Id,ProcessName,StartTime
13+
Write-Host "Processes: $($processes.Count)"
14+
$processes | Select-Object ProcessId,Name,CreationDate | Format-Table -AutoSize
815
} else {
916
Write-Host "A2A Automation Framework is STOPPED"
1017
}
1118

19+
# Build status URL dynamically
20+
if (-not $StatusUrl -and $WebAppName) {
21+
$StatusUrl = "https://$WebAppName.azurewebsites.net/a2a/automation/status"
22+
}
23+
24+
if (-not $StatusUrl) {
25+
Write-Host "Automation endpoint not accessible (missing WebAppName or StatusUrl)"
26+
return
27+
}
28+
1229
# Check automation endpoint
1330
try {
14-
= Invoke-RestMethod -Uri "https://zava-63f59c9f-app.azurewebsites.net/a2a/automation/status" -TimeoutSec 5
15-
Write-Host "Automation Status: "
31+
$status = Invoke-RestMethod -Uri $StatusUrl -TimeoutSec 5
32+
Write-Host "Automation Status: $($status | ConvertTo-Json -Compress)"
1633
} catch {
1734
Write-Host "Automation endpoint not accessible"
1835
}

src/app/agents/deploy_real_agents.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,64 @@ def _create_agent(project_client: AIProjectClient, *, model: str, name: str, ins
8383
except TypeError:
8484
pass
8585

86+
# Preferred: pass name + definition explicitly (newer SDK signature)
87+
try:
88+
from azure.ai.projects.models import PromptAgentDefinition, AgentKind
89+
90+
agent_def = PromptAgentDefinition(
91+
kind=AgentKind.PROMPT,
92+
model=model,
93+
instructions=instructions,
94+
)
95+
return agents.create(name=name, definition=agent_def, description=name)
96+
except Exception:
97+
pass
98+
8699
# Fall back to SDK model definitions
87100
try:
88-
from azure.ai.projects.models import PromptAgentDefinition
101+
from azure.ai.projects.models import PromptAgentDefinition, AgentKind
89102

90-
agent_def = PromptAgentDefinition(model=model, name=name, instructions=instructions)
103+
agent_def = PromptAgentDefinition(
104+
kind=AgentKind.PROMPT,
105+
model=model,
106+
instructions=instructions,
107+
)
91108
return agents.create(agent_def)
92109
except Exception:
93110
pass
94111

95112
try:
96-
from azure.ai.projects.models import AgentDefinition
113+
from azure.ai.projects.models import AgentDefinition, AgentKind
97114

98-
agent_def = AgentDefinition(model=model, name=name, instructions=instructions)
115+
agent_def = AgentDefinition(kind=str(AgentKind.PROMPT))
99116
return agents.create(agent_def)
100117
except Exception:
101118
pass
102119

103-
# Last resort: pass a dict payload
104-
return agents.create({"model": model, "name": name, "instructions": instructions})
120+
# Try AgentCreateRequest with explicit definition
121+
try:
122+
from azure.ai.projects.models import AgentCreateRequest, PromptAgentDefinition, AgentKind
123+
124+
agent_def = PromptAgentDefinition(
125+
kind=AgentKind.PROMPT,
126+
model=model,
127+
instructions=instructions,
128+
)
129+
request = AgentCreateRequest(definition=agent_def, name=name, description=name)
130+
return agents.create(request)
131+
except Exception:
132+
pass
133+
134+
# Some SDKs require a "definition" wrapper in the payload
135+
payload = {
136+
"name": name,
137+
"kind": "prompt",
138+
"definition": {
139+
"model": model,
140+
"instructions": instructions,
141+
},
142+
}
143+
return agents.create(payload)
105144

106145
if hasattr(agents, "create_prompt_agent"):
107146
return agents.create_prompt_agent(model=model, name=name, instructions=instructions)
@@ -166,7 +205,7 @@ def deploy_agents():
166205
"Your role is to help customers find products, answer questions about inventory, provide recommendations, and assist with general shopping needs. "
167206
"Be friendly, professional, and informative. Keep answers concise and helpful."
168207
),
169-
"model": agent_model_map.get("cora", model_deployment)
208+
"model": agent_model_map.get("cora", "model-router")
170209
},
171210
{
172211
"name": "Interior Design Specialist",
@@ -418,8 +457,8 @@ def deploy_agents():
418457
print(f"WARNING: Failed to write state file: {se}")
419458

420459
# Update src/.env with real agent IDs (early propagation)
421-
# NOTE: Terraform generates ../src/.env (workspace-relative), not ../src/app/.env.
422-
env_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '.env'))
460+
# NOTE: Terraform generates ../src/.env (workspace-relative).
461+
env_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src', '.env'))
423462
if os.path.exists(env_path):
424463
try:
425464
import re

terraform-infrastructure/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2026-01-12
8+
Last updated: 2026-01-29
99

1010
----------
1111

@@ -119,7 +119,7 @@ graph TD;
119119

120120
<!-- START BADGE -->
121121
<div align="center">
122-
<img src="https://img.shields.io/badge/Total%20views-1329-limegreen" alt="Total views">
122+
<img src="https://img.shields.io/badge/Total%20views-1325-limegreen" alt="Total views">
123123
<p>Refresh Date: 2026-01-29</p>
124124
</div>
125125
<!-- END BADGE -->

terraform-infrastructure/main.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ resource "azapi_resource" "ai_project" {
151151
depends_on = [azapi_update_resource.ai_foundry_enable_project_mgmt]
152152
}
153153

154+
# Grant current principal access to AI Foundry + AI Project for Agents API
155+
resource "azurerm_role_assignment" "ai_foundry_openai_user" {
156+
scope = azapi_resource.ai_foundry.id
157+
role_definition_name = "Cognitive Services OpenAI User"
158+
principal_id = local.principal_id
159+
depends_on = [azapi_resource.ai_foundry]
160+
}
161+
162+
resource "azurerm_role_assignment" "ai_project_user" {
163+
scope = azapi_resource.ai_project.id
164+
role_definition_name = "Azure AI User"
165+
principal_id = local.principal_id
166+
depends_on = [azapi_resource.ai_project]
167+
}
168+
154169
# === Real Multi-Agent Creation (ochartarotr) ===
155170
# NOTE: Azure Agents API not yet available via ARM/Terraform (returns 500 Internal Server Error)
156171
# Keeping these commented for future use when the API becomes available
@@ -1969,7 +1984,9 @@ resource "null_resource" "deploy_multi_agents" {
19691984
depends_on = [
19701985
null_resource.create_env_file,
19711986
null_resource.ai_model_deployments,
1972-
azapi_resource.ai_project
1987+
azapi_resource.ai_project,
1988+
azurerm_role_assignment.ai_foundry_openai_user,
1989+
azurerm_role_assignment.ai_project_user
19731990
]
19741991

19751992
provisioner "local-exec" {
@@ -2006,6 +2023,13 @@ resource "null_resource" "deploy_multi_agents" {
20062023
$agentEndpointBase = $rawEndpoint -replace "cognitiveservices\.azure\.com", "services.ai.azure.com"
20072024
$agentEndpoint = "$agentEndpointBase/api/projects/${local.ai_project_name}"
20082025
$env:AZURE_AI_PROJECT_ENDPOINT = $agentEndpoint
2026+
$env:AZURE_AI_FOUNDRY_ENDPOINT = $rawEndpoint
2027+
$env:AZURE_AI_FOUNDRY_NAME = "${local.ai_foundry_name}"
2028+
$env:AZURE_AI_PROJECT_NAME = "${local.ai_project_name}"
2029+
$env:AZURE_SUBSCRIPTION_ID = "${data.azurerm_client_config.current.subscription_id}"
2030+
$env:AZURE_RESOURCE_GROUP = "${azurerm_resource_group.rg.name}"
2031+
$env:AZURE_LOCATION = "${var.location}"
2032+
$env:AZURE_AI_PROJECT_CONNECTION_STRING = "${var.location}.api.azureml.ms;subscription_id=${data.azurerm_client_config.current.subscription_id};resource_group=${azurerm_resource_group.rg.name};project_name=${local.ai_project_name}"
20092033
Write-Host "Using Agents API endpoint: $agentEndpoint"
20102034
20112035
# Deploy agents using Python script

terraform-infrastructure/terraform.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resource_group_name = "RG-AI-Retail-DemoX9"
1+
resource_group_name = "RG-AI-Retail-DemoX0"
22
location = "eastus2"
33
name_prefix = "zava"
44

0 commit comments

Comments
 (0)