Foundry-Agent-Solution-Templates / apim-hosted-agent
AGENTS.md5 starsChanged 2 months agoMITView on GitHub
This project is a Microsoft Foundry hosted agent fronted by Azure API Management (APIM). Preserve the governed request paths: callers enter through the APIM agent API, the hosted agent reaches its model through the APIM model API, and MCP tools are exposed through APIM tool APIs. This project was built with the microsoft-foundry skill. Before working on or answering questions about Foundry agents, read the microsoft-foundry skill first. - azure.yaml — azd orchestration for the Foundry project, toolbox, hosted agent,…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 47
Keep services.project.deployments in each azure.yaml aligned with modelDeploymentName in infra/apim.parameters.json and …
- Distinctive: line 50
Keep the hosted agent's model endpoint on the project-compatible APIM path.
- Distinctive: line 51
Do not bypass APIM with a direct Foundry endpoint.
- Very specific: line 52
Do not declare custom environment variables with the AGENT_* or FOUNDRY_* prefixes.
- Distinctive: line 57
Keep the model API restricted to the hosted-agent managed identity.
- Very specific: line 58
Keep caller authorization in Foundry RBAC.
- Very specific: line 61
Keep MCP connections declared in infra/foundry.bicep and infra-terraform/foundry.tf.
- Distinctive: line 67
Treat APIM named values as administrator-facing policy configuration.
- Distinctive: line 70
Do not bypass the configured authentication, identity checks, rate limits, token limits, Content Safety, or GitHub/Google user/tool …
- Very specific: line 76
Run commands from apim-hosted-agent:
- Distinctive: line 82
When GitHub or Google OAuth MCP is enabled, retrieve its exported redirect URL after provisioning and register it with the corresponding …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Coding Agent Instructions
This project is a Microsoft Foundry hosted agent fronted by Azure API Management (APIM). Preserve the governed request paths: callers enter through the APIM agent API, the hosted agent reaches its model through the APIM model API, and MCP tools are exposed through APIM tool APIs.
This project was built with the microsoft-foundry skill. Before working on or answering questions about Foundry agents, read the microsoft-foundry skill first.
Key files
azure.yaml— azd orchestration for the Foundry project, toolbox, hosted agent, infrastructure layers, environment variables, and deployment hookssrc/main.py— Agent Framework setup, APIM-backedFoundryChatClient, and Foundry Toolbox integrationsrc/end_user_identity.py— hashes Foundry's trusted platform user identity and forwards it only to the APIM model API for per-user token enforcementinfra/apim.bicep— APIM service, shared configuration, and module orchestrationinfra/modules/apim-agent.bicep— hosted-agent ingress APIinfra/modules/apim-model.bicep— hosted-agent model gateway, portal Product, and resource linksinfra/modules/apim-tool-*.bicep— governed Microsoft Learn and optional GitHub/Google MCP gatewaysinfra/foundry.bicep— Foundry project RBAC and Bicep-owned MCP connectionsinfra/*.parameters.json— azd parameter mappings for the Bicep layersazure-terraform.yaml— alternate azd manifest; rename it toazure.yamlwhen developing or deploying with Terraforminfra-terraform/— Terraform translation of both Bicep infrastructure layersinfra-terraform/policies/— Terraform-owned copies of the APIM policy XML; keep them aligned withinfra/policies/infra/policies/— APIM authentication, rate-limit, token-limit, Content Safety, OAuth, and tool-governance policiesscripts/— postprovision link synchronization and postdeploy hosted-agent identity bindingdocs/apim-policies.md— policy behavior, counter keys, trust boundaries, and configuration referencedocs/google/— all manual Google MCP setup, OAuth, deployment, consent, testing, and disablement instructionsdocs/cost.md— cost components, estimate inputs, and cost guardrails
Preserve these invariants
- Bicep and Terraform are parallel azd provisioning paths. Keep their resources, policies, parameters, outputs, and deployment behavior aligned.
- Keep
services.project.deploymentsin eachazure.yamlaligned withmodelDeploymentNameininfra/apim.parameters.jsonandmodel_deployment_nameininfra-terraform/main.tfvars.json. - Keep the hosted agent's model endpoint on the project-compatible APIM path. Do not bypass APIM with a direct Foundry endpoint.
- Do not declare custom environment variables with the
AGENT_*orFOUNDRY_*prefixes. The hosted-agent platform reserves and injects them. - Derive per-user model quota keys only from Foundry's platform-provided
user_id_key. Do not trust a caller-supplied identity header or log the raw platform user identifier. - Keep the model API restricted to the hosted-agent managed identity.
- Keep caller authorization in Foundry RBAC. APIM currently validates and
forwards the
https://ai.azure.com/bearer token; it does not replace downstream Foundry authorization. - Keep MCP connections declared in
infra/foundry.bicepandinfra-terraform/foundry.tf. GitHub is optional and must remain disabled when both OAuth settings are absent. - Google MCP is an explicit opt-in. Keep it disabled unless the enable flag, endpoint, client ID, client secret, and manual toolbox entry are all present. The sample intentionally has no imperative Google cleanup script.
- Treat APIM named values as administrator-facing policy configuration. Persistent default changes belong in both IaC implementations because reprovisioning overwrites manual named-value edits.
- Do not bypass the configured authentication, identity checks, rate limits, token limits, Content Safety, or GitHub/Google user/tool controls to make a test pass.
Development workflow
Run commands from apim-hosted-agent:
azd provision --no-promptWhen GitHub or Google OAuth MCP is enabled, retrieve its exported redirect URL after provisioning and register it with the corresponding OAuth application before deploying:
azd env get-value GITHUB_OAUTH_REDIRECT_URL
azd env get-value GOOGLE_OAUTH_REDIRECT_URL
azd deploy --no-promptSkip redirect values for integrations that are disabled. Test deployed traffic
through https://<apim-name>.azure-api.net/agent/responses with a bearer token
for https://ai.azure.com/. Follow docs/google/README.md for every manual
Google MCP step.
Microsoft Foundry Skill
Install the Microsoft Foundry Skill for guided deployment, evaluation, and troubleshooting workflows.
Direct install (preferred, works with any coding agent):
npx skills add https://github.com/microsoft/azure-skills --skill microsoft-foundryOr install the Azure Skills Plugin:
- Copilot CLI:
/plugin marketplace add microsoft/azure-skillsthen/plugin install azure@azure-skills - Claude Code:
/plugin install azure@claude-plugins-official
Then ask naturally, e.g. Use the Microsoft Foundry Skill to deploy this agent.
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

