Add AIFunctionNameAttribute and AIParameterNameAttribute#7610
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds two targeted experimental attributes to the Microsoft.Extensions.AI abstractions to let developers override AI-facing function and parameter identifiers, and updates both JSON schema generation and runtime argument binding to honor those overrides (including correct JSON Pointer escaping).
Changes:
- Introduces
[AIFunctionName](method-level) and[AIParameterName](parameter-level) experimental attributes (MEAI001) and updates API baselines. - Updates
AIFunctionFactoryname precedence and switches argument binding to use the effective (possibly overridden) parameter name. - Updates
AIJsonUtilities.CreateFunctionJsonSchemato emit overridden parameter property names, detect duplicates, and escape JSON Pointer segments; adds focused tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Tests/Functions/AIFunctionFactoryTest.cs | Adds tests for function-name precedence and runtime binding via [AIParameterName]. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs | Adds schema tests for [AIParameterName], duplicate detection, and JSON Pointer escaping. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Functions/AINameAttributesTests.cs | Adds constructor argument validation tests for the new attributes. |
| src/Shared/DiagnosticIds/DiagnosticIds.cs | Adds experiment IDs for the new attribute APIs. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Schema.Create.cs | Implements effective parameter naming, duplicate checks in schema, and JSON Pointer escaping. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json | Updates public API baseline entries for the new attribute types. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIParameterNameAttribute.cs | Adds the new parameter naming attribute (experimental). |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionNameAttribute.cs | Adds the new function naming attribute (experimental). |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactoryOptions.cs | Updates docs to mention [AIFunctionName] as a naming source. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs | Applies new name precedence and binds arguments using effective parameter names. |
…ion, test improvements
All feedback addressed in commit 69d2fef:
|
Adds test to verify that parameter name collision detection occurs even when one of the colliding parameters is excluded from schema generation via ExcludeFromSchema = true. This addresses reviewer feedback about potential silent de-duplication in this scenario.
Includes AIFunctionFactory_InheritedDescriptionAttributes_OnOverride test that validates inherited Description attributes on overridden methods, including parameter descriptions and return value descriptions. Covers both modern .NET and .NET Framework behavior differences.
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1500144&view=codecoverage-tab |
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1500672&view=codecoverage-tab |
Fixes #7477
This change addresses the naming override gap from #7477 while aligning with updated direction: ship two targeted attributes instead of a single general-purpose one. It enables explicit AI-facing names for methods and parameters without introducing class-level naming semantics.
API surface
AIFunctionNameAttribute(AttributeTargets.Method) for tool/function identifier overrides.AIParameterNameAttribute(AttributeTargets.Parameter) for schema/binding key overrides.MEAI001) and updates public API baselines.Function metadata resolution
AIFunctionFactoryname precedence to:[AIFunctionName],[DisplayName],DisplayNamebehavior as fallback.Parameter schema + invocation binding
[AIParameterName]for generated function JSON schema property names and required lists.Schema correctness for special names
$refJSON Pointer segments (RFC 6901), so names containing/or~remain valid.Coverage updates
Microsoft Reviewers: Open in CodeFlow