1
---
2
name: foundry-agent-sync
3
description: "Create and synchronize prompt-based AI agents directly within Azure AI Foundry via REST API, from a local JSON manifest. Unlike scaffolding skills that only generate local code, this skill registers agents in the Foundry service itself — making them immediately available for invocation. Use when the user asks to create agents in Foundry, sync, deploy, register, or push agents to Foundry, update agent instructions, or scaffold the manifest and sync script for a new repository. Triggers: 'create agent in foundry', 'sync foundry agents', 'deploy agents to foundry', 'register agents in foundry', 'push agents', 'create foundry agent manifest', 'scaffold agent sync'."
4
---
5
6
# Foundry Agent Sync
7
8
## Overview
9
10
Create and synchronize prompt-based AI agents directly within Azure AI Foundry via the Agent Service REST API. This skill registers agents in the Foundry service itself — making them immediately available for invocation, evaluation, and management through the Foundry portal or API. Each agent is created or updated idempotently via a named POST call, using definitions from a local JSON manifest file.
11
12
> **Key distinction:** This skill creates agents inside AI Foundry (server-side). It does not scaffold local agent code or container images — for that, use the `microsoft-foundry` skill's `create` sub-skill.
13
14
## Prerequisites
15
16
The user must have:
17
18
1. An Azure AI Foundry project with a deployed model (e.g. `gpt-5-4`)
19
2. Azure CLI (`az`) authenticated with access to the Foundry project
20
3. The **Azure AI User** role (or higher) on the Foundry project resource
21
22
Collect these values before proceeding:
23
24
| Value | How to get it |
25
|---|---|
26
| **Foundry project endpoint** | Azure Portal → AI Foundry project → Overview → Endpoint, or `az resource show` |
27
| **Subscription ID** | `az account show --query id -o tsv` |
28
| **Model deployment name** | The model name deployed in the Foundry project (e.g. `gpt-5-4`) |
29
30
## Manifest Format
31
32
The manifest is a JSON array where each entry defines one agent. Look for it at common paths: `infra/foundry-agents.json`, `foundry-agents.json`, or `.foundry/agents.json`. If none exists, scaffold one.
33
34
```json
35
[
36
{
37
"useCaseId": "alert-triage",
38
"description": "Short description of what this agent does.",
39
"baseInstruction": "You are an assistant that... <system prompt for the agent>"
40
}
41
]
42
```
43
44
### Field Reference
45
46
| Field | Required | Description |
47
|---|---|---|
48
| `useCaseId` | Yes | Kebab-case identifier; used to build the agent name (`{prefix}-{useCaseId}`) |
49
| `description` | Yes | Human-readable description stored as agent metadata |
50
| `baseInstruction` | Yes | System prompt / base instructions for the agent |
51
52
## Sync Script
53
54
### PowerShell (interactive / CI)
55
56
Create or locate the sync script. The canonical path is `infra/scripts/sync-foundry-agents.ps1` but adapt to the repo layout.
57
58
```powershell
59
param(
60
[Parameter(Mandatory)]
61
[string]$SubscriptionId,
62
63
[Parameter(Mandatory)]
64
[string]$ProjectEndpoint,
65
66
[string]$ManifestPath = (Join-Path $PSScriptRoot '..\foundry-agents.json'),
67
[string]$ModelName = 'gpt-5-4',
68
[string]$AgentNamePrefix = 'myproject',
69
[string]$ApiVersion = '2025-11-15-preview'
70
)
71
72
$ErrorActionPreference = 'Stop'
73
74
# Optional: append a common instruction suffix to every agent
75
$commonSuffix = ''
76
77
az account set --subscription $SubscriptionId | Out-Null
78
$accessToken = az account get-access-token --resource https://ai.azure.com/ --query accessToken -o tsv
79
if (-not $accessToken) { throw 'Failed to acquire Foundry access token.' }
80
81
$definitions = Get-Content -Raw -Path $ManifestPath | ConvertFrom-Json
82
$headers = @{ Authorization = "Bearer $accessToken" }
83
$results = @()
84
85
foreach ($def in $definitions) {
86
$agentName = "$AgentNamePrefix-$($def.useCaseId)"
87
$instructions = if ($commonSuffix) { "$($def.baseInstruction)`n`n$commonSuffix" } else { $def.baseInstruction }
88
$body = @{
89
definition = @{ kind = 'prompt'; model = $ModelName; instructions = $instructions }
90
description = $def.description
91
metadata = @{ useCaseId = $def.useCaseId; managedBy = 'foundry-agent-sync' }
92
} | ConvertTo-Json -Depth 8
93
94
$uri = "$($ProjectEndpoint.TrimEnd('/'))/agents/$agentName`?api-version=$ApiVersion"
95
$resp = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -ContentType 'application/json' -Body $body
96
$version = $resp.version ?? $resp.latest_version ?? $resp.id ?? 'unknown'
97
Write-Host "Synced $agentName ($version)"
98
$results += [pscustomobject]@{ name = $agentName; version = $version }
99
}
100
101
$results | Format-Table -AutoSize
102
```
103
104
### Bash (Bicep deployment script / CI)
105
106
For automated deployment via `Microsoft.Resources/deploymentScripts`, use a bash script that:
107
108
1. Authenticates with a managed identity: `az login --identity --username "$CLIENT_ID"`
109
2. Acquires a Foundry token: `az account get-access-token --resource https://ai.azure.com/`
110
3. Iterates definitions from the `FOUNDRY_AGENT_DEFINITIONS` environment variable (JSON string)
111
4. POSTs each agent to `{endpoint}/agents/{name}?api-version=2025-11-15-preview`
112
113
## Bicep Integration (optional)
114
115
To run the sync automatically during infrastructure deployment:
116
117
1. **Load the manifest** at compile time:
118
```bicep
119
var agentDefinitions = loadJsonContent('foundry-agents.json')
120
```
121
122
2. **Create a User-Assigned Managed Identity** with the **Azure AI User** role on the Foundry project.
123
124
3. **Create a `Microsoft.Resources/deploymentScripts`** resource (kind `AzureCLI`) that:
125
- Uses the managed identity
126
- Loads the bash sync script via `loadTextContent`
127
- Passes the project endpoint, definitions, and model as environment variables
128
129
Gate behind a `deployFoundryAgents` parameter so teams can opt in/out.
130
131
## Workflow
132
133
### Step 1 — Locate or scaffold the manifest
134
135
Search the repo for `foundry-agents.json`. If it doesn't exist, ask the user what agents they need and create the manifest.
136
137
### Step 2 — Locate or scaffold the sync script
138
139
Search for `sync-foundry-agents.ps1` or `foundry-agent-sync.sh`. If missing, create the PowerShell script using the template above, adapting:
140
- `$AgentNamePrefix` to match the project name
141
- `$ModelName` to the user's deployed model
142
- `$ManifestPath` to the actual manifest location
143
144
### Step 3 — Collect parameters
145
146
Ask the user for:
147
- Foundry project endpoint
148
- Subscription ID
149
- Model deployment name (default: `gpt-5-4`)
150
- Agent name prefix (default: repo name in kebab-case)
151
152
### Step 4 — Run the sync
153
154
Execute the PowerShell script with the collected parameters:
155
156
```powershell
157
.\infra\scripts\sync-foundry-agents.ps1 `
158
-SubscriptionId '<sub-id>' `
159
-ProjectEndpoint '<endpoint>' `
160
-ModelName '<model>' `
161
-AgentNamePrefix '<prefix>'
162
```
163
164
### Step 5 — Verify
165
166
Confirm synced agents by listing them:
167
168
```powershell
169
$token = az account get-access-token --resource https://ai.azure.com/ --query accessToken -o tsv
170
$endpoint = '<project-endpoint>'
171
Invoke-RestMethod -Uri "$endpoint/agents?api-version=2025-11-15-preview" `
172
-Headers @{ Authorization = "Bearer $token" }
173
```
174
175
## REST API Reference
176
177
| Operation | Method | URL |
178
|---|---|---|
179
| Create/update agent | POST | `{projectEndpoint}/agents/{agentName}?api-version=2025-11-15-preview` |
180
| List agents | GET | `{projectEndpoint}/agents?api-version=2025-11-15-preview` |
181
| Get agent | GET | `{projectEndpoint}/agents/{agentName}?api-version=2025-11-15-preview` |
182
| Delete agent | DELETE | `{projectEndpoint}/agents/{agentName}?api-version=2025-11-15-preview` |
183
184
### Create/Update Payload
185
186
```json
187
{
188
"definition": {
189
"kind": "prompt",
190
"model": "<deployed-model-name>",
191
"instructions": "<system prompt>"
192
},
193
"description": "<agent description>",
194
"metadata": {
195
"useCaseId": "<use-case-id>",
196
"managedBy": "foundry-agent-sync"
197
}
198
}
199
```
200
201
## Troubleshooting
202
203
| Symptom | Cause | Fix |
204
|---|---|---|
205
| `401 Unauthorized` | Token expired or wrong audience | Re-run `az account get-access-token --resource https://ai.azure.com/` |
206
| `403 Forbidden` | Missing Azure AI User role | Assign the role on the Foundry project scope |
207
| `404 Not Found` | Wrong project endpoint | Verify endpoint includes `/api/projects/{projectName}` |
208
| Model not found | Model not deployed in project | Deploy the model in AI Foundry portal first |
209
| Empty definitions | Manifest path wrong | Check `-ManifestPath` points to the JSON file |
210