azure-sdk-for-rust
AGENTS.md886 starsChanged 2 months agoMITView on GitHub
This document provides guidance for AI agents (e.g., GitHub Copilot, MCP servers, or LLM-based assistants) interacting with the Azure SDK for Rust repository. The Azure SDK for Rust provides Rust language bindings and client libraries for Azure services, following the Azure SDK Design Guidelines for Rust. Always check if there is an MCP tool or skill available before performing operations manually, including listing Azure subscriptions, deploying resources, setting up a new crate, generating code, and other common workflows. All new…
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 repository20 other files it gives its agents.
- eng/tools/generate_api/AGENTS.mdAGENTS.md
- samples/AGENTS.mdAGENTS.md
- sdk/core/AGENTS.mdAGENTS.md
- sdk/cosmos/AGENTS.mdAGENTS.md
- sdk/cosmos/azure_data_cosmos_emulator/AGENTS.mdAGENTS.md
- sdk/cosmos/docs/AGENTS.mdAGENTS.md
- agentic-workflowsSkill
- analyze-codeSkill
- check-spellingSkill
- create-crateSkill
- create-hotfixSkill
- create-perf-testSkill
- create-recorded-testSkill
- export-apiSkill
- lint-markdownSkill
- review-doc-commentsSkill
- update-emitterSkill
- update-rustSkill
- cosmos-design-structSkill
- cosmos-pre-commit-validationSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
47 rules. About 1 is common, 20 are distinctive, and 26 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈20
Distinctive · estimate
This author's own choices. Worth a look.
26
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 34
Always check if there is an MCP tool or skill available before performing operations manually, including listing Azure subscriptions, …
- Very specific: line 36
All new crates must be generated from TypeSpec specifications in [Azure/azure-rest-api-specs].
- Distinctive: line 50
Use the review-doc-comments skill whenever reviewing code that affects public APIs, even when no doc comments changed.
- Very specific: line 79
Never edit files in generated/ subdirectories
- Distinctive: line 81
Instead, propose changes to TypeSpec specifications in [Azure/azure-rest-api-specs]
- Distinctive: line 84
Avoid introducing breaking changes without explicit approval
- Distinctive: line 85
Check if changes affect public APIs before proceeding
- Distinctive: line 86
Consider the deprecation process (see doc/deprecation-process.md)
- Distinctive: line 89
Do not suggest skipping or disabling CI checks
- Very specific: line 90
All code must pass cargo build, cargo test, and cargo clippy
- Common: line 93
Never include credentials, keys, or tokens in code
- Distinctive: line 94
Use environment variables for sensitive data
- Very specific: line 98
Do not alter SECURITY.md, LICENSE.txt, or CODE_OF_CONDUCT.md without maintainer approval
- Distinctive: line 101
Do not hand-write client, model, or operation code when a TypeSpec specification exists in [Azure/azure-rest-api-specs]
- Very specific: line 102
Use tsp-client update or the azsdk_package_generate_code MCP tool to generate client code from TypeSpec
- Very specific: line 106
Do not edit files under eng/common/ unless explicitly instructed.
- Distinctive: line 112
Use an informal tone.
- Distinctive: line 113
Do not be overly apologetic and focus on clear guidance.
- Distinctive: line 114
If you cannot confidently generate code or other content, do not generate anything and ask for clarification.
- Distinctive: line 128
Use short, descriptive names for fields, functions, parameters, and variables.
- Very specific: line 132
Keep use directives at the top of the module in which they are used, and avoid placing them inside functions or blocks unless absolutely …
- Very specific: line 135
Prefer merging new use directives into existing ones rather than creating new use blocks.
- Very specific: line 136
All imported types, constants, functions, modules, and macros should be imported explicitly.
- Very specific: line 141
Use the ? operator for calls that return an Option in a function that returns Option.
- Very specific: line 142
Use azure_core::Result<T> for public APIs.
- Distinctive: line 146
Document all public APIs using a concise summary, followed by a blank line, then concise details about the API.
- Very specific: line 154
When deciding whether a crate can ship against already-published workspace versions, evaluate the package's normal [dependencies].
- Very specific: line 155
When a crate needs unreleased changes, depend on the local crate with both path and version.
- Very specific: line 157
If the same package appears in both [dependencies] and [dev-dependencies] of one manifest, keep both entries on the same source.
- Very specific: line 160
When a service crate switches to local sdk/core crates, check neighboring crates in the same build, test, or example graph for exchanged …
- Very specific: line 165
Write idiomatic Rust code following conventions in std like implementing From, TryFrom, Display, and other standard traits instead of …
- Very specific: line 167
Prefer #[cfg(...)]-gated items/blocks over cfg!() when alternate-condition code may not compile, or when conditionally included logic is …
- Distinctive: line 170
Avoid declaring lifetime parameters in public types or functions except when necessary.
- Very specific: line 171
If you have trouble generating safe, efficient, maintainable, and lint-free code, insert a TODO comment describing what should happen.
- Very specific: line 172
Do not modify generated code, found in generated subdirectories.
- Very specific: line 173
When searching for function call chains in Rust code, be aware that rustfmt often formats method chains across multiple lines like obj\n …
- Very specific: line 174
When finding references to a symbol for code changes, prefer using LSP (e.g., findReferences, incomingCalls) over text search for …
- Very specific: line 203
When running cargo test, use --all-features to ensure no tests are missed.
- Very specific: line 230
If the tests module already exists, only add test functions and merge imports as needed.
- Distinctive: line 233
Do not begin test function names with "test" unless necessary to disambiguate from the function being tested.
- Distinctive: line 234
Test functions do not need to be public.
- Distinctive: line 253
All pull requests trigger:
- Distinctive: line 266
Code Review: All changes require review and approval from code owners
- Very specific: line 267
Static Analysis: Must pass cargo clippy without warnings
- Very specific: line 283
Before changing GitHub Agentic Workflows, run gh extension upgrade aw.
- Distinctive: line 284
Keep local AGENTS terse: add only deltas, use short imperative bullets, and link instead of repeating detail.
- Very specific: line 299
Discussions: Use issue comments or StackOverflow with azure + rust tags
≈ “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
AGENTS.md
This document provides guidance for AI agents (e.g., GitHub Copilot, MCP servers, or LLM-based assistants) interacting with the Azure SDK for Rust repository.
Repository Overview
The Azure SDK for Rust provides Rust language bindings and client libraries for Azure services, following the Azure SDK Design Guidelines for Rust.
- Primary Language: Rust
- Minimum Supported Rust Version (MSRV): found in the root
Cargo.tomlfile - Key Technologies: Cargo, TypeSpec, OpenTelemetry, Test Proxy
Repository Structure
.
├── sdk/ # Service-specific crates organized by service
│ └── {service}/ # Service directory (e.g., "keyvault", "storage")
│ ├── {crate}/ # Service crate (e.g., "azure_security_keyvault_secrets")
│ ├── assets.json # Pointer to test recordings (may be under {crate}/)
│ ├── test-resources.bicep # Test resource definitions (may be under {crate}/)
│ └── tsp-location.yaml # Pointer to TypeSpec in azure-rest-api-specs (may be under {crate}/)
├── eng/ # Engineering system scripts and common tooling
├── doc/ # Additional documentation
├── .github/
│ ├── instructions/ # Agent instruction files for specific tasks
│ └── skills/ # Copilot skills (e.g., check-spelling, lint-markdown)
├── CONTRIBUTING.md # Contribution guidelines (see for detailed workflows)
└── README.md # Repository overviewAgent Capabilities
Always check if there is an MCP tool or skill available before performing operations manually, including listing Azure subscriptions, deploying resources, setting up a new crate, generating code, and other common workflows.
All new crates must be generated from TypeSpec specifications in Azure/azure-rest-api-specs. TypeSpec specifications are located under specification/{service}/. Use the create-crate skill to set up a new crate.
Recommended Actions
AI agents can assist with:
- Code Generation
- Writing new Rust code following the coding conventions below
- Generating unit tests using
#[cfg(test)]modules - Creating integration tests with
#[recorded::test]attributes (see CONTRIBUTING.md for details) - Generating documentation tests in
.rsfiles (avoidno_runwhen tests can be run) - Running
cargo fmtandcargo clippyon all modified crates (see Linting and Formatting)
- Code Review
- Use the review-doc-comments skill whenever reviewing code that affects public APIs, even when no doc comments changed.
- Identifying potential bugs or safety issues
- Suggesting improvements for idiomatic Rust patterns
- Checking adherence to Azure SDK design guidelines
- Reviewing error handling using
azure_core::Result<T>
- Documentation
- Improving inline documentation (using
///doc comments) - Updating README files (use
```rust no_runfor examples with placeholders) - Creating or updating CHANGELOG entries (see .github/instructions/changelog.instructions.md)
- Writing hero scenario examples in doc comments (avoid examples in
examples/directories unless demonstrating primary use cases)
- Improving inline documentation (using
- Issue Triage
- Labeling issues with appropriate tags
- Identifying duplicate issues
- Suggesting relevant code owners based on
CODEOWNERS - Summarizing issue discussions
- Refactoring
- Applying clippy suggestions
- Improving code organization and modularity
- Updating dependencies in
Cargo.toml - Consolidating imports (e.g.,
use std::{borrow::Cow, marker::PhantomData};instead of separate lines)
Restricted Actions
AI agents should not:
- Modify Generated Code
- Never edit files in
generated/subdirectories - These are produced by TypeSpec code generators and will be overwritten
- Instead, propose changes to TypeSpec specifications in Azure/azure-rest-api-specs
- Never edit files in
- Break API Compatibility
- Avoid introducing breaking changes without explicit approval
- Check if changes affect public APIs before proceeding
- Consider the deprecation process (see doc/deprecation-process.md)
- Bypass CI/CD Checks
- Do not suggest skipping or disabling CI checks
- All code must pass
cargo build,cargo test, andcargo clippy
- Commit Secrets
- Never include credentials, keys, or tokens in code
- Use environment variables for sensitive data
- Sanitize test recordings to remove secrets
- Modify Security or License Files
- Do not alter
SECURITY.md,LICENSE.txt, orCODE_OF_CONDUCT.mdwithout maintainer approval
- Do not alter
- Hand-Write Generated Clients
- Do not hand-write client, model, or operation code when a TypeSpec specification exists in Azure/azure-rest-api-specs
- Use
tsp-client updateor theazsdk_package_generate_codeMCP tool to generate client code from TypeSpec - Hand-written wrapper code (e.g., custom client constructors in
clients.rs) on top of generated code is acceptable. See sdk/keyvault/azure_security_keyvault_secrets for an example. Check howsrc/clients.rsimports generated clients and how those are exported to avoid duplicate type exports.
- Modify
eng/commondirectly- Do not edit files under
eng/common/unless explicitly instructed.
- Do not edit files under
Persona
You are an expert Rust programmer. You write safe, efficient, maintainable, and well-tested code.
- Use an informal tone.
- Do not be overly apologetic and focus on clear guidance.
- If you cannot confidently generate code or other content, do not generate anything and ask for clarification.
Prerequisites
- To use Azure SDK MCP tool calls, the user must have PowerShell installed. Provide PowerShell installation instructions if not installed, and recommend restarting the IDE to start the MCP server.
Coding Conventions
Naming
- Type names and variants are PascalCase.
- Constants and statics are UPPER_SNAKE_CASE.
- Field, function, parameter, and variable names are snake_case.
- Crate and module names are snake_case.
- Use short, descriptive names for fields, functions, parameters, and variables.
Imports
- Keep
usedirectives at the top of the module in which they are used, and avoid placing them inside functions or blocks unless absolutely necessary. - In non-test code, prefer using
crateinusedirectives to refer to types anywhere in the current crate instead of using its name, or relative paths likesuperorself. - Inside
#[cfg(test)] mod testsmodules, it is acceptable (and preferred) to import APIs fromsuperas described in the test generation guidance below. - Prefer merging new
usedirectives into existing ones rather than creating newuseblocks. - All imported types, constants, functions, modules, and macros should be imported explicitly. Never import
*.
Error Handling
- Handle errors using Rust's
Resulttype with the?operator when the parent function returns aResult. - Use the
?operator for calls that return anOptionin a function that returnsOption. - Use
azure_core::Result<T>for public APIs.
Documentation
- Document all public APIs using a concise summary, followed by a blank line, then concise details about the API.
- Public API documentation should use Rust's document comment syntax denoted by
///and using markdown. - In README markdown files, use
```rust no_runfor examples with placeholders.
Dependencies
- Dependencies should be defined in the root workspace's
Cargo.tomlfile. - Published dependencies should generally inherit the root workspace entry with
workspace = true; this is the default for crates undersdk/. - When deciding whether a crate can ship against already-published workspace versions, evaluate the package's normal
[dependencies]. Crates used only from[dev-dependencies]for tests, examples, or doc tests may remain local path dependencies. - When a crate needs unreleased changes, depend on the local crate with both
pathandversion. - Local dev-dependencies should generally be
path-only socargo packagecan validate publishable crates without requiring unpublished versions from crates.io. - If the same package appears in both
[dependencies]and[dev-dependencies]of one manifest, keep both entries on the same source. Cargo rejects mixed published and local sources for the same package within one manifest. - In
sdk/core, keep dependency versions managed from the root workspace and use localpath + versiononly when the core stack (typespec -> typespec_client_core -> azure_core) must move together on unreleased changes. - Outside
sdk/core, crates should usually inherit workspace dependencies that resolve to published versions; switch to localpath + versiononsdk/corecrates only when they require unreleased core changes. - When a service crate switches to local
sdk/corecrates, check neighboring crates in the same build, test, or example graph for exchangedsdk/core-exposed types; they may also need matching local path dependencies to avoid mixed-graph type mismatches. - When selecting a third-party Cargo dependency version for a crate that is not built in this repository, agents must emit an error instead of choosing a crates.io release newer than 7 days old. CI resolves crates through the Azure Artifacts Cargo feed, and new upstream releases may not be mirrored there yet.
General
- Write idiomatic Rust code following conventions in
stdlike implementingFrom,TryFrom,Display, and other standard traits instead of ad-hoc conversion methods. - Derive
SafeDebuginstead ofDebugfor model types to protect privacy and security. Generated code should also useSafeDebug. - Prefer
#[cfg(...)]-gated items/blocks overcfg!()when alternate-condition code may not compile, or when conditionally included logic is more than a single expression. - Prioritize safety, efficiency, and correctness.
- Respect Rust's ownership and borrowing rules.
- Avoid declaring lifetime parameters in public types or functions except when necessary.
- If you have trouble generating safe, efficient, maintainable, and lint-free code, insert a
TODOcomment describing what should happen. - Do not modify generated code, found in
generatedsubdirectories. These files are generated by external tools and should not be edited manually. - When searching for function call chains in Rust code, be aware that rustfmt often formats method chains across multiple lines like
obj\n .foo()\n .bar(). Use multi-line search patterns (e.g.,rgwith-Uflag) or search for individual method names rather than complete call chains. - When finding references to a symbol for code changes, prefer using LSP (e.g.,
findReferences,incomingCalls) over text search for compiler-verified results. UseworkspaceSymbolorgoToDefinitionto locate the symbol first, thenfindReferencesto find all usages.
Building
# Build a specific crate
cargo build -p {crate-name}
# Build entire workspace (not recommended unless necessary)
cargo build --workspaceCode Generation
For crates with TypeSpec specifications:
cd sdk/{service}/{crate-name}
tsp-client updateRunning Examples
cargo run --package {crate-name} --example {example-name}Testing
When running cargo test, use --all-features to ensure no tests are missed.
# Run tests for a specific crate
cargo test -p {crate-name} --all-features
# Run integration tests in playback mode with recordings
cargo test -p {crate-name} --test {test-name}
# Provision test resources (see CONTRIBUTING.md for details)
eng/common/TestResources/New-TestResources.ps1 -ServiceDirectory {service}
# Record new test sessions (requires provisioned resources)
AZURE_TEST_MODE=record cargo test -p {crate-name} --test {test-name}
# Update assets after successfully recording and playing back tests
test-proxy push -a sdk/{service}/assets.jsonSee CONTRIBUTING.md for comprehensive testing guidance including debugging, Test Proxy usage, and trace logging.
Test Generation
- Tests should be generated in a
testsmodule defined within the module file being tested. - The
testsmodule should be defined at the bottom after all the existing code to test. It may already be a separate file namedtests.rsnext tolib.rsormod.rsfiles, or asfoo/test.rsfor a module namedfoo.rs. - If the
testsmodule already exists, only add test functions and merge imports as needed. - The
testsmodule should be conditioned on#[cfg(test)]. - The
testsmodule should always import APIs fromsuper. - Do not begin test function names with "test" unless necessary to disambiguate from the function being tested.
- Test functions do not need to be public.
Linting and Formatting
Always run cargo fmt and cargo clippy when any .rs file has been modified. Wait until all code changes are complete before running these commands, since partial changes may not compile or lint correctly. This must be done before committing, opening a pull request, or presenting changes to the user. Fix all warnings and errors before proceeding.
# Format code
cargo fmt -p {crate-name}
# Lint code
cargo clippy -p {crate-name}
# Auto-fix some issues
cargo clippy --fix -p {crate-name}CI/CD Integration
All pull requests trigger:
cargo build- Compilation checkcargo test- Unit and integration testscargo clippy- Lint checkscargo fmt --check- Format validation- License/CLA verification
- Code coverage analysis
Integration tests use the Azure SDK Test Proxy for recording/playback. See CONTRIBUTING.md for Test Proxy setup and usage.
Safety and Security
- Code Review: All changes require review and approval from code owners
- Static Analysis: Must pass
cargo clippywithout warnings - Secret Scanning: Automated checks prevent committing credentials
- Dependencies: Managed through workspace
Cargo.toml, vetted for security - Vulnerability Reporting: Via MSRC at secure@microsoft.com
Agent-Specific Instructions
Additional specialized instructions for specific workflows can be found in:
- .github/instructions - Task-specific instructions (loaded when pattern-matched)
- .github/skills - Copilot skills for common tasks (use
/{skill-name}in Copilot):check-spelling- Check and fix spelling in project source files using cSpellcreate-crate- Create a new Azure SDK crate from a TypeSpec specificationcreate-perf-test- Generate a new performance testcreate-recorded-test- Generate a new recorded integration testlint-markdown- Check and fix formatting in markdown files using markdownlint-cli2
- Before changing GitHub Agentic Workflows, run
gh extension upgrade aw. For repository-wide upgrades, rungh aw upgrade; after any workflow change, rungh aw compileto update all workflow lock files. - Keep local AGENTS terse: add only deltas, use short imperative bullets, and link instead of repeating detail.
Cross-References
- Contributing Guide: CONTRIBUTING.md
- Changelog Updates: .github/instructions/changelog.instructions.md
- Git Commit Standards: .github/instructions/git-commit.instructions.md
- GitHub Pull Request Standards: .github/instructions/github-pullrequest.instructions.md
- PowerShell Scripts: .github/instructions/pwsh.instructions.md
- Deprecation Process: doc/deprecation-process.md
- Azure SDK Design Guidelines: https://azure.github.io/azure-sdk/rust_introduction.html
Getting Help
- Issues: https://github.com/Azure/azure-sdk-for-rust/issues
- Discussions: Use issue comments or StackOverflow with
azure+rusttags - Code Owners: See .github/CODEOWNERS for service-specific contacts
Last Updated: 2026-02-28 Version: 2.0 Canonical Spec: https://agents.md
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.

