Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/create/references/use-skills-in-hosted-agent.md
1# Use Skills in a Hosted Agent23How to consume Foundry **skills** (reusable behavioral guidelines) from hosted agent code. Two approaches:451. **Direct download** โ agent downloads skill ZIPs at startup via the Skills API, wires `SkillsProvider` (Python) or `AgentSkillsProvider` (C#).62. **Via Toolbox MCP** โ agent connects to a toolbox MCP endpoint that exposes skills as resources, wires `AgentSkillsProviderBuilder.UseMcpSkills` (C#) or `MCPStreamableHTTPTool` (Python).78> ๐ For skill resource CRUD (`azd ai skill create/update/list/download/delete`), see [skill-management.md](skill-management.md).9>10> ๐ For attaching skills to a toolbox (`azd ai toolbox skill add/remove/list`) and the raw MCP protocol, see [skill-toolbox.md](skill-toolbox.md).1112## How progressive disclosure works1314The Agent Framework SDK injects skill names/descriptions into the system prompt (~100 tokens each) and synthesizes a `load_skill` tool. When the model determines a skill is relevant, it calls `load_skill(name)` to retrieve the full body on demand โ keeping context usage low.1516## Choosing an approach1718| | Direct Download | Via Toolbox MCP |19|--|---|---|20| How | Downloads ZIPs at startup, builds provider from local files | Connects to toolbox MCP; SDK reads `resources/list` โ `load_skill` |21| Provider | `SkillsProvider.from_paths()` / `AgentSkillsProvider(dir)` | `MCPStreamableHTTPTool` / `AgentSkillsProviderBuilder.UseMcpSkills()` |22| Skill updates | Redeploy agent | Consumer endpoint picks up new version automatically |23| Header | `Foundry-Features: Skills=V1Preview` | `Foundry-Features: Toolboxes=V1Preview` |24| When to use | No toolbox; need explicit version control | Already have a toolbox; want dynamic updates |2526---2728## Approach 1: Direct Download2930Downloads skill ZIPs at startup, extracts to disk, builds provider. The SDK synthesizes `load_skill` for the model.3132### Env vars3334| Variable | Purpose |35|----------|---------|36| `FOUNDRY_PROJECT_ENDPOINT` | Project endpoint for SDK calls |37| `AZURE_AI_MODEL_DEPLOYMENT_NAME` | Model deployment for the agent |38| `SKILL_NAMES` | Comma-separated skill names to download |3940### Python4142The sample downloads each skill via `project.beta.skills.download()`, extracts the ZIP (with zip-slip guard), and attaches a `SkillsProvider` to the agent as a `context_providers` entry.4344**Key classes:** `SkillsProvider.from_paths()`, `AIProjectClient` (with `allow_preview=True`).4546Full working sample: [12-foundry-skills (Python)](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/python/hosted-agents/agent-framework/responses/12-foundry-skills)4748### C#4950The sample uses `AgentAdministrationClient` (with `FoundryFeaturesPolicy` for the `Skills=V1Preview` header) to download skills via `ProjectAgentSkills.DownloadSkillAsync()`, extracts ZIPs, and attaches an `AgentSkillsProvider` via `AIContextProviders`.5152**Key classes:** `AgentSkillsProvider`, `ProjectAgentSkills`, `AgentAdministrationClient`.5354Full working sample: [agent-skills (C#)](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/csharp/hosted-agents/agent-framework/agent-skills)5556---5758## Approach 2: Via Toolbox MCP5960Skills attached to a toolbox are discovered dynamically via `resources/list` and wrapped into `load_skill`. See [skill-toolbox.md](skill-toolbox.md) for MCP protocol details.6162### Env vars6364| Variable | Purpose |65|----------|---------|66| `FOUNDRY_PROJECT_ENDPOINT` | Project endpoint for SDK calls |67| `AZURE_AI_MODEL_DEPLOYMENT_NAME` | Model deployment for the agent |68| `TOOLBOX_ENDPOINT` | Full toolbox MCP endpoint URL (Python preferred) |69| `TOOLBOX_NAME` | Toolbox name โ SDK constructs endpoint (C# preferred) |7071### C#7273The sample creates an `McpClient` pointing at the toolbox endpoint, then builds a skills provider via `AgentSkillsProviderBuilder().UseMcpSkills(mcpClient).Build()`. The framework handles the advertise โ load โ read lifecycle automatically.7475**Key classes:** `AgentSkillsProviderBuilder`, `McpClient`, `BearerTokenHandler`.7677Full working sample: [foundry-toolbox-mcp-skills (C#)](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills)7879---8081## Deployment8283### Provision skills8485Skills must exist in the **same project** the deployed agent connects to:8687```bash88azd ai skill create support-style --file ./skills/support-style/ --force89azd ai skill create escalation-policy --file ./skills/escalation-policy/ --force90```9192### Direct download approach9394```bash95azd env set SKILL_NAMES "support-style,escalation-policy"96```9798`agent.yaml`:99100```yaml101environment_variables:102- name: SKILL_NAMES103value: ${SKILL_NAMES}104```105106### Toolbox approach107108```bash109# Create toolbox with skills attached110cat > tools.yaml <<'EOF'111description: Agent toolbox with skills and tools112skills:113- name: support-style114- name: escalation-policy115tools:116- type: web_search117name: web118EOF119azd ai toolbox create agent-tools --from-file tools.yaml120121# Wire endpoint env var122ENDPOINT=$(azd ai toolbox show agent-tools -o json | jq -r .endpoint)123azd env set TOOLBOX_ENDPOINT "$ENDPOINT"124```125126`agent.yaml`:127128```yaml129environment_variables:130- name: TOOLBOX_ENDPOINT131value: ${TOOLBOX_ENDPOINT}132```133134Then `azd deploy`.135136### RBAC137138The deployed agent's managed identity needs **Foundry User** on the project:139140```bash141az role assignment create \142--assignee <managed-identity-object-id> \143--role "Foundry User" \144--scope /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.CognitiveServices/accounts/<account>/projects/<project>145```146147## Verify end-to-end148149```bash150azd ai agent run151azd ai agent invoke --local "Hi, can I return my tent within 30 days?"152```153154## Samples155156| Language | Approach | Sample |157|----------|----------|--------|158| Python | Direct download | [12-foundry-skills](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/python/hosted-agents/agent-framework/responses/12-foundry-skills) |159| Python | Via Toolbox | [04-foundry-toolbox](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/python/hosted-agents/agent-framework/responses/04-foundry-toolbox) |160| C# | Direct download | [agent-skills](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/csharp/hosted-agents/agent-framework/agent-skills) |161| C# | Via Toolbox MCP | [foundry-toolbox-mcp-skills](https://github.com/microsoft-foundry/foundry-samples/tree/main/samples/csharp/hosted-agents/agent-framework/foundry-toolbox-mcp-skills) |162163## Troubleshooting164165| Symptom | Likely cause | Fix |166|---------|------------|-----|167| `SKILL.md not found` after download | ZIP doesn't contain `SKILL.md` at root | Create skill from directory with `SKILL.md` at root |168| `403` on skill download | Identity missing RBAC | Grant **Foundry User** on project scope |169| Agent ignores skills | Descriptions don't match user queries | Improve `description` in SKILL.md front matter |170| Skills load but agent doesn't follow | Instructions vague or conflicting | Refine skill body; add canary token to verify loading |171| `asyncio.TimeoutError` (Python) | Slow network or large packages | Increase bootstrap timeout (default 60s) |172| `allow_preview` error (Python) | SDK client missing preview flag | `AIProjectClient(allow_preview=True)` |173| HTTP 500 on skill download (C#) | Missing feature header | Add `FoundryFeaturesPolicy` for `Skills=V1Preview` |174| `SKILL_NAMES` not in deployed agent | Env var missing from `agent.yaml` | Add to `environment_variables[]`, redeploy |175| MCP timeout (Toolbox) | Auth token expired or wrong scope | Use `https://ai.azure.com/.default`; refresh per request |176| Skills not discovered from toolbox | New version not published | `azd ai toolbox publish <toolbox> <version>` |177| `Invalid skill name 'xxx:download'` | SDK bug in beta.2 | Use CLI or `agent-framework-foundry` wrapper |178