agentleFS
Azure-SamplesAzure-Samples/Apim-Samples/AGENTS.md

Apim-Samples

AGENTS.md100 starsChanged 17 months agoMITView on GitHub

This document provides AI agents with structured guidance for working with the Azure API Management (APIM) Samples repository. This repository provides resources to deploy Azure API Management infrastructures and experiment with APIM policies. It offers: All repository contributions should treat accessibility as a first-class quality requirement. Use these skills for specialized tasks. Skills are located in .github/skills/.

We split this AGENTS.md into the rules it gives an agent

33 rules. About 0 are common, 14 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All repository contributions should treat accessibility as a first-class quality requirement.

    line 15
  2. Distinctive:

    Use WCAG 2.0 AA as the default baseline for user-facing outputs, including documentation, web content, workbook/dashboard visuals, and …

    line 17
  3. Distinctive:

    Do not rely on color alone to convey meaning.

    line 18
  4. Very specific:

    Use these skills for specialized tasks.

    line 76
  5. Very specific:

    Use these custom agents for focused repository workflows.

    line 86
  6. Distinctive:

    When a task matches a skill's domain, read the skill file first:

    line 95
  7. Very specific:

    Prefer the custom agent: Use .github/agents/apim-sample-creator.agent.md for end-to-end sample creation.

    line 107
  8. Distinctive:

    Ask the user for the sample name if it is not provided.

    line 125
  9. Distinctive:

    Ask the user for supported infrastructures if they are not provided.

    line 126
  10. Distinctive:

    Keep sample display names consistent across README tables, the website, the slide deck, and compatibility artifacts.

    line 127
  11. Very specific:

    If a broadly useful improvement is discovered while creating a sample, suggest updating samples/_TEMPLATE so future samples inherit it.

    line 128
  12. Distinctive:

    Ensure an infrastructure is deployed (or will be created on first run)

    line 159
  13. Distinctive:

    Test via the verification cells

    line 168
  14. Distinctive:

    Keep educational configuration, scenario definitions, APIM concepts, expected outcomes, and assertions visible in the notebook.

    line 203
  15. Very specific:

    Start one-consumer behavior in samples/<sample>/<domain>_helpers.py.

    line 205
  16. Very specific:

    Add focused tests under tests/python/test_<sample>_helpers.py, then replace notebook mechanics with a scenario-readable call.

    line 208
  17. Very specific:

    Call configure_notebook_autoreload() after the first code cell's imports and declare each runtime module's reload_safe, reload_conditional, …

    line 209
  18. Very specific:

    When extracting notebook mechanics, start with a focused sample-local module.

    line 222
  19. Very specific:

    Use versioned modules (e.g., v1/api.bicep) for stability

    line 228
  20. Distinctive:

    Every package or GitHub Action release must complete an eight-day waiting period before use.

    line 236
  21. Very specific:

    Before a locked Python install, run python setup/verify_dependency_age.py --scope python, then uv sync --locked.

    line 239
  22. Very specific:

    Keep GitHub Actions pinned to 40-character commit SHAs with version comments and validate them with python setup/verify_dependency_age.py …

    line 242
  23. Distinctive:

    Do not introduce direct install or upgrade commands that bypass the lockfile, age verifier, or release exclusion.

    line 243
  24. Very specific:

    Follow Ruff configuration in pyproject.toml

    line 247
  25. Distinctive:

    Use type hints and docstrings

    line 248
  26. Very specific:

    Run ruff check before committing

    line 249
  27. Very specific:

    Follow bicepconfig.json linter rules

    line 254
  28. Very specific:

    Use @description for all parameters

    line 255
  29. Distinctive:

    Follow section structure: Parameters → Constants → Variables → Resources → Outputs

    line 257
  30. Very specific:

    Follow the standard cell structure from _TEMPLATE

    line 263
  31. Very specific:

    After any Markdown change, run npx --no-install markdownlint-cli2 "/*.md" "#/.venv/" "#/node_modules/" from the repository root and require …

    line 269
  32. Very specific:

    Place tests in tests/python/

    line 288
  33. Very specific:

    Use test_helpers.py for common test utilities

    line 291

≈ “Common” is an estimate: at least 1 in 5 of the 36,368 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Agent Instructions for APIM Samples

This document provides AI agents with structured guidance for working with the Azure API Management (APIM) Samples repository.

Repository Purpose

This repository provides resources to deploy Azure API Management infrastructures and experiment with APIM policies. It offers:

  • Infrastructures: Pre-built Azure architectures featuring APIM in various configurations
  • Samples: Real-world policy examples that can be deployed to any supported infrastructure
  • Shared Resources: Reusable Bicep modules, Python helpers, and policy templates

Accessibility Baseline

All repository contributions should treat accessibility as a first-class quality requirement.

  • Use WCAG 2.0 AA as the default baseline for user-facing outputs, including documentation, web content, workbook/dashboard visuals, and presentation materials.
  • Do not rely on color alone to convey meaning; pair color cues with labels, text, icons, or structure.
  • Preserve or improve contrast and readability when editing existing assets.

Repository Structure

/
├── infrastructure/          # Azure infrastructure deployments
│   ├── afd-apim-pe/         # Azure Front Door + APIM with Private Endpoint
│   ├── apim-aca/            # APIM with Azure Container Apps
│   ├── appgw-apim/          # Application Gateway + APIM (VNet)
│   ├── appgw-apim-pe/       # Application Gateway + APIM with Private Endpoint
│   └── simple-apim/         # Basic APIM setup (fastest, lowest cost)
│
├── samples/                 # APIM policy samples
│   ├── _TEMPLATE/           # Template for creating new samples
│   ├── authX/               # Authentication and authorization
│   ├── authX-pro/           # Advanced auth with policy fragments
│   ├── azure-maps/          # Azure Maps integration
│   ├── aoai-v1-migration/   # Azure OpenAI v1 Migration on existing lab resources
│   ├── costing/             # APIM costing and showback
│   ├── dynamic-cors/        # Dynamic per-API CORS origin validation
│   ├── egress-control/      # Egress control via NVA routing
│   ├── general/             # Basic policy demonstrations
│   ├── inference-failover/  # AOAI model failover with LLM telemetry
│   ├── load-balancing/      # Backend pool load balancing
│   ├── oauth-3rd-party/     # OAuth 3rd-party (Spotify example)
│   └── secure-blob-access/  # Valet key pattern for blob storage
│
├── shared/                  # Reusable components
│   ├── apim-policies/       # Common APIM policy XML files
│   ├── bicep/modules/       # Versioned Bicep modules
│   ├── jupyter/             # Reusable Jupyter notebooks
│   └── python/              # Python helper modules
│
├── tests/                   # Unit tests for Python code
│   └── python/              # pytest-based tests
│
├── setup/                   # Environment setup scripts
├── assets/                  # Images and diagrams
└── .github/                 # CI/CD and Copilot instructions
    ├── agents/              # Custom agents for focused repository workflows
    ├── copilot-instructions.md
    └── skills/              # Agent skills for specialized tasks

Key Files in Each Sample/Infrastructure

FilePurpose
README.mdDocumentation, objectives, and configuration instructions
create.ipynbJupyter notebook for deploying the sample
main.bicepBicep template defining Azure resources
clean-up.ipynb(Infrastructure only) Teardown notebook
*.xmlAPIM policy files

Available Skills

Use these skills for specialized tasks. Skills are located in .github/skills/.

SkillWhen to Use
sample-creatorCreating new samples under samples/ following the _TEMPLATE structure
apim-bicepWriting Bicep templates for APIM resources (APIs, backends, policies, products)
apim-policiesCreating or modifying APIM XML policies (inbound/outbound, authentication, rate limiting)

Available Agents

Use these custom agents for focused repository workflows. Agents are located in .github/agents/.

AgentWhen to Use
APIM Sample CreatorAdding a new sample, gathering missing sample metadata, scaffolding from _TEMPLATE, and updating README, website, slide deck, and compatibility artifacts
APIM Sample PublisherFinalizing an implemented sample for review or release by synchronizing READMEs, website, SEO, slide deck, compatibility artifacts, and quality checks

How to Use Skills

When a task matches a skill's domain, read the skill file first:

.github/skills/<skill-name>/SKILL.md

Skills provide templates, patterns, and step-by-step workflows.

Creating New Samples

Quick Process

  1. Prefer the custom agent: Use .github/agents/apim-sample-creator.agent.md for end-to-end sample creation.
  2. Read the skill: Load .github/skills/sample-creator/SKILL.md
  3. Gather requirements: Sample name, description, supported infrastructures, learning objectives
  4. Create folder: samples/<sample-name>/ unless the user explicitly requests another location
  5. Create required files:
    • README.md - Follow the template structure
    • create.ipynb - Jupyter notebook with initialization, deployment, and verification cells
    • <domain>_helpers.py - Add a descriptive sample-local module when parsing, retries, sessions, persistence, command composition, or multi-step orchestration would otherwise live in notebook cells
    • main.bicep - Reference shared modules from shared/bicep/modules/; add sample-owned policy files under apim-policies/ and KQL queries under queries/ when needed
  6. Update repo surfaces:
    • Root README.md sample table
    • docs/index.html sample cards and JSON-LD list
    • assets/APIM-Samples-Slide-Deck.html when sample inventory or descriptions are shown
    • tests/Test-Matrix.md
    • Compatibility diagrams when supported infrastructures change visually

Sample Addition Requirements

  • Ask the user for the sample name if it is not provided.
  • Ask the user for supported infrastructures if they are not provided.
  • Keep sample display names consistent across README tables, the website, the slide deck, and compatibility artifacts.
  • If a broadly useful improvement is discovered while creating a sample, suggest updating samples/_TEMPLATE so future samples inherit it.

Publishing a Sample

Use .github/agents/apim-sample-publisher.agent.md after sample implementation is ready for a final quality pass. The publisher agent checks the working-tree diff, synchronizes README, website, SEO metadata and structured data, slideshow, matrix, and compatibility-diagram surfaces, runs the applicable linting and unit tests, exports the presentation, and reports any manual or live-Azure verification that remains.

Sample Naming Conventions

  • Folder: kebab-case (e.g., oauth-validation, rate-limiting)
  • API prefix: Short, unique, with trailing hyphen (e.g., oauth-, rl-)
  • Policy files: Descriptive, kebab-case, and stored under samples/<sample-name>/apim-policies/ (e.g., token-validation.xml)
  • Query files: Descriptive, kebab-case, and stored under samples/<sample-name>/queries/ (e.g., request-summary.kql)
  • Workbook files: Azure Monitor Workbook JSON files use the <name>.workbook.json suffix (e.g., costing.workbook.json). One workbook per file, stored in the sample folder, loaded into Bicep via loadJsonContent('<name>.workbook.json'), and pushed back to Azure via a sample-local update-workbook.ps1. See the Azure Monitor Workbook File Convention section in .github/copilot-instructions.md.
  • Admin APIs: Samples needing admin/operational endpoints use path {api_prefix}admin with subscriptionRequired=True and kebab-case operation paths (e.g., /load-cache)

Infrastructure Constants

Available in Python via from apimtypes import INFRASTRUCTURE:

ConstantDescription
INFRASTRUCTURE.AFD_APIM_PEAzure Front Door + APIM with Private Endpoint
INFRASTRUCTURE.APIM_ACAAPIM with Azure Container Apps
INFRASTRUCTURE.APPGW_APIMApplication Gateway + APIM (VNet injection)
INFRASTRUCTURE.APPGW_APIM_PEApplication Gateway + APIM with Private Endpoint
INFRASTRUCTURE.SIMPLE_APIMBasic APIM setup

Working with Existing Samples

Running a Sample

  1. Ensure an infrastructure is deployed (or will be created on first run)
  2. Open samples/<sample-name>/create.ipynb
  3. Adjust USER CONFIGURATION section if needed
  4. Execute all cells

Modifying Policies

  1. Edit the *.xml policy file in the sample's apim-policies/ folder
  2. Re-run the deployment cell in create.ipynb
  3. Test via the verification cells

Existing root-level policy files may remain until their sample is migrated. Policy helpers should resolve apim-policies/ first and the sample root second as a temporary fallback. After moving policy XML or KQL files, verify every notebook, helper, Bicep, test, script, and documentation reference, including path-resolution tests for canonical locations, fallback behavior, explicit paths, auto-detection, and missing files.

Adding APIs to a Sample

In create.ipynb, define APIs using:

from apimtypes import API, GET_APIOperation, POST_APIOperation

# Create operations
get_op = GET_APIOperation('Description of the operation')
post_op = POST_APIOperation('Description', policyXml = '<policy-xml>')

# Create API
api = API(
    '<name>',               # API name (resource identifier)
    '<Display Name>',       # Human-readable display name
    '<path>',               # URL path segment (often same value as name)
    '<Description>',        # API description
    operations = [get_op, post_op],
    tags = ['tag1', 'tag2']
)

# Add to apis array
apis = [api]

Python Modules

The Python helper strategy is the authoritative guide for notebook boundaries, helper ownership, supporting-class design, state, lifecycles, promotion criteria, and testing.

Apply this sequence whenever creating or refactoring a notebook:

  1. Keep educational configuration, scenario definitions, APIM concepts, expected outcomes, and assertions visible in the notebook.
  2. Extract incidental mechanics behind explicit inputs and typed outputs.
  3. Start one-consumer behavior in samples/<sample>/<domain>_helpers.py; promote only after a second active consumer needs the same stable contract.
  4. Compose existing NotebookHelper, ApimRequests, ApimTesting, and azure_resources boundaries without adding forwarding wrappers.
  5. Make the helper own deterministic cleanup for sessions, files, and temporary resources, and inject remote or timing boundaries for tests.
  6. Add focused tests under tests/python/test_<sample>_helpers.py, then replace notebook mechanics with a scenario-readable call.
  7. Call configure_notebook_autoreload() after the first code cell's imports and declare each runtime module's reload_safe, reload_conditional, or reload_unsafe classification in its opening docstring. Follow the helper strategy for limitations; do not use broad autoreload or unconditional reloads.

Key modules in shared/python/:

ModulePurpose
utils.pyNotebookHelper, policy loading, endpoint helpers
apimtypes.pyType definitions (API, INFRASTRUCTURE, APIM_SKU)
azure_resources.pyAzure CLI wrappers for resource management
console.pyFormatted console output (print_ok, print_error)
apimrequests.pyHTTP request helpers for testing APIs
apimtesting.pyTest framework for sample verification

When extracting notebook mechanics, start with a focused sample-local module. Promote it to shared/python/ only after a second real consumer establishes a stable cross-sample contract.

Bicep Modules

Shared modules in shared/bicep/modules/:

  • Use versioned modules (e.g., v1/api.bicep) for stability
  • Reference with relative paths: ../../shared/bicep/modules/apim/v1/api.bicep
  • See apim-bicep skill for APIM-specific patterns

Code Quality Requirements

Dependency Supply-Chain Safety

  • Every package or GitHub Action release must complete an eight-day waiting period before use.
  • MockAPI container images from simonkurtzmsft/mockapi are exempt from the eight-day waiting period. Keep an exact version tag and immutable digest; package and GitHub Actions waiting periods remain unchanged.
  • Preserve tool.uv.exclude-newer = "8 days" and Dependabot cooldowns for all configured ecosystems.
  • Before a locked Python install, run python setup/verify_dependency_age.py --scope python, then uv sync --locked.
  • Generate uv.lock against canonical public PyPI only by running python setup/sync_dependencies.py --upgrade. Never commit private mirror URLs, proxy configuration, credentials, or internal endpoints. Do not manually remove the registry and artifact URLs required by uv's lock schema.
  • If the lock's direct artifact URLs are inaccessible, export the frozen lock without index settings and install the temporary names, versions, markers, and hashes through the approved mirror with uv pip sync --no-config --require-hashes --strict. Use this fallback only after the age verifier succeeds, and never commit the temporary export.
  • Keep GitHub Actions pinned to 40-character commit SHAs with version comments and validate them with python setup/verify_dependency_age.py --scope github-actions.
  • Do not introduce direct install or upgrade commands that bypass the lockfile, age verifier, or release exclusion.

Python

  • Follow Ruff configuration in pyproject.toml
  • Use type hints and docstrings
  • Run ruff check before committing
  • Tests in tests/python/ with pytest

Bicep

  • Follow bicepconfig.json linter rules
  • Use @description for all parameters
  • Include Microsoft Learn template reference links above resources
  • Follow section structure: Parameters → Constants → Variables → Resources → Outputs

Jupyter Notebooks

  • Clear all cell outputs before committing
  • Set index = 1 in the first code cell
  • Follow the standard cell structure from _TEMPLATE

Markdown

  • Generate Markdown, including repository instructions, skills, and agents, against .markdownlint.json and .github/markdown.instructions.md.
  • Preserve semantic heading, list, table, and code-block structure instead of flattening content to satisfy lint rules.
  • After any Markdown change, run npx --no-install markdownlint-cli2 "**/*.md" "#**/.venv/**" "#**/node_modules/**" from the repository root and require zero violations.

Testing

Running Tests

# Via Developer CLI
./start.ps1  # Windows
./start.sh   # macOS/Linux
# Select "Tests" menu

# Or directly
pytest tests/python/
ruff check shared/python/

Writing Tests

  • Place tests in tests/python/
  • Mock Azure CLI interactions (no live Azure access in tests)
  • Target 95%+ code coverage
  • Use test_helpers.py for common test utilities

Common Tasks Reference

TaskSkill to UseKey Files
Create a new samplesample-creatorsamples/_TEMPLATE/*
Write APIM policiesapim-policiesshared/apim-policies/*.xml
Create Bicep templatesapim-bicepshared/bicep/modules/

Additional Resources

  • Troubleshooting: See TROUBLESHOOTING.md for common issues
  • Contributing: See CONTRIBUTING.md for contribution guidelines
  • Python instructions: .github/python.instructions.md
  • Bicep instructions: .github/bicep.instructions.md
  • JSON instructions: .github/json.instructions.md

Download now (ZIP)

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 28,693 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 repository4 other files it gives its agents.

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.