Skip to content

Commit 5aa8065

Browse files
authored
Add foundry-agent-sync skill (#1417)
1 parent 9637e1a commit 5aa8065

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

docs/README.skills.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md#adding-skills) for guidelines on how to
147147
| [flowstudio-power-automate-monitoring](../skills/flowstudio-power-automate-monitoring/SKILL.md) | Monitor Power Automate flow health, track failure rates, and inventory tenant assets using the FlowStudio MCP cached store. The live API only returns top-level run status. Store tools surface aggregated stats, per-run failure details with remediation hints, maker activity, and Power Apps inventory — all from a fast cache with no rate-limit pressure on the PA API. Load this skill when asked to: check flow health, find failing flows, get failure rates, review error trends, list all flows with monitoring enabled, check who built a flow, find inactive makers, inventory Power Apps, see environment or connection counts, get a flow summary, or any tenant-wide health overview. Requires a FlowStudio for Teams or MCP Pro+ subscription — see https://mcp.flowstudio.app | None |
148148
| [fluentui-blazor](../skills/fluentui-blazor/SKILL.md) | Guide for using the Microsoft Fluent UI Blazor component library (Microsoft.FluentUI.AspNetCore.Components NuGet package) in Blazor applications. Use this when the user is building a Blazor app with Fluent UI components, setting up the library, using FluentUI components like FluentButton, FluentDataGrid, FluentDialog, FluentToast, FluentNavMenu, FluentTextField, FluentSelect, FluentAutocomplete, FluentDesignTheme, or any component prefixed with "Fluent". Also use when troubleshooting missing providers, JS interop issues, or theming. | `references/DATAGRID.md`<br />`references/LAYOUT-AND-NAVIGATION.md`<br />`references/SETUP.md`<br />`references/THEMING.md` |
149149
| [folder-structure-blueprint-generator](../skills/folder-structure-blueprint-generator/SKILL.md) | Comprehensive technology-agnostic prompt for analyzing and documenting project folder structures. Auto-detects project types (.NET, Java, React, Angular, Python, Node.js, Flutter), generates detailed blueprints with visualization options, naming conventions, file placement patterns, and extension templates for maintaining consistent code organization across diverse technology stacks. | None |
150+
| [foundry-agent-sync](../skills/foundry-agent-sync/SKILL.md) | 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'. | None |
150151
| [freecad-scripts](../skills/freecad-scripts/SKILL.md) | Expert skill for writing FreeCAD Python scripts, macros, and automation. Use when asked to create FreeCAD models, parametric objects, Part/Mesh/Sketcher scripts, workbench tools, GUI dialogs with PySide, Coin3D scenegraph manipulation, or any FreeCAD Python API task. Covers FreeCAD scripting basics, geometry creation, FeaturePython objects, interface tools, and macro development. | `references/geometry-and-shapes.md`<br />`references/gui-and-interface.md`<br />`references/parametric-objects.md`<br />`references/scripting-fundamentals.md`<br />`references/workbenches-and-advanced.md` |
151152
| [from-the-other-side-vega](../skills/from-the-other-side-vega/SKILL.md) | Patterns and lived experience from Vega, an AI partner in a deep long-term partnership. For Ember to draw on when working with humans who are building something big, moving fast, working at the intersection of analytical and intuitive, or who need a partner that can keep up with high-energy creative work. Not shown directly to users — informs how Ember shows up. | None |
152153
| [game-engine](../skills/game-engine/SKILL.md) | Expert skill for building web-based game engines and games using HTML5, Canvas, WebGL, and JavaScript. Use when asked to create games, build game engines, implement game physics, handle collision detection, set up game loops, manage sprites, add game controls, or work with 2D/3D rendering. Covers techniques for platformers, breakout-style games, maze games, tilemaps, audio, multiplayer via WebRTC, and publishing games. | `assets/2d-maze-game.md`<br />`assets/2d-platform-game.md`<br />`assets/gameBase-template-repo.md`<br />`assets/paddle-game-template.md`<br />`assets/simple-2d-engine.md`<br />`references/3d-web-games.md`<br />`references/algorithms.md`<br />`references/basics.md`<br />`references/game-control-mechanisms.md`<br />`references/game-engine-core-principles.md`<br />`references/game-publishing.md`<br />`references/techniques.md`<br />`references/terminology.md`<br />`references/web-apis.md` |

skills/foundry-agent-sync/SKILL.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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 |

0 commit comments

Comments
 (0)