Agents & OrchestrationSûr100100/100
Maui IA Tool Bindings (.NET)
Source-generate `Microsoft.Extensions.AI` tools for MAUI with `Microsoft.Maui.AI.Attributes`. USE FOR: `ExportAIFunction`, `AIToolSource`/`AIToolContext`, `Default.Tools`, DI-bound parameters, AOT-safe tools, `UseFunctionInvocation`. DO NOT USE FOR: Essentials.AI chat/embeddings or native bindings.
ou envoie-le directement à ton agent.
Installer dans ton projet
$ curl -fsSL https://arboristhree.xyz/cli/install-skill.mjs -o /tmp/arboris-install-skill.mjs && node /tmp/arboris-install-skill.mjs maui-ai-tool-bindings__dotnet-maui-labs__plugins-dotnet-maui-skills-6772562beb01.NET
dotnet/maui-labs
Contenu à copier
---
name: maui-ai-tool-bindings
description: >-
Source-generate `Microsoft.Extensions.AI` tools for MAUI with `Microsoft.Maui.AI.Attributes`. USE FOR: `ExportAIFunction`, `AIToolSource`/`AIToolContext`, `Default.Tools`, DI-bound parameters, AOT-safe tools, `UseFunctionInvocation`. DO NOT USE FOR: Essentials.AI chat/embeddings or native bindings.
metadata:
origin: .NET
---
# MAUI AI Tool Bindings
Use this skill when a MAUI app needs AI-callable tools backed by app services,
view models, or static utility methods. `Microsoft.Maui.AI.Attributes` generates
`Microsoft.Extensions.AI` tools at compile time to avoid reflection-heavy
invocation paths.
## Basic Workflow
1. Install the package:
```bash
dotnet add package Microsoft.Maui.AI.Attributes --prerelease
```
2. Annotate methods or property accessors:
```csharp
using System.ComponentModel;
using Microsoft.Maui.AI.Attributes;
public sealed class PlantCatalogService
{
[Description("Searches the plant catalog by name or category.")]
[ExportAIFunction("search_plants")]
public IReadOnlyList<PlantInfo> SearchPlants(
[Description("Optional filter text")] string? query = null)
{
return [];
}
}
```
3. Create a curated tool context:
```csharp
[AIToolSource(typeof(PlantCatalogService))]
public partial class GardenTools : AIToolContext
{
}
```
4. Register services normally in `MauiProgram.cs`:
```csharp
builder.Services.AddSingleton<PlantCatalogService>();
```
5. Pass generated tools into an `IChatClient`:
```csharp
var client = innerClient.AsBuilder()
.UseFunctionInvocation()
.ConfigureOptions(options =>
{
options.Tools ??= [];
foreach (var tool in GardenTools.Default.Tools)
options.Tools.Add(tool);
})
.Build(serviceProvider);
```
## Tool Context Choices
| Need | Pattern |
| --- | --- |
| Curated feature-specific tools | Explicit partial `AIToolContext` with `[AIToolSource]` |
| Small prototype exposing all exported tools | Assembly-wide `<AssemblyName>ToolContext.Default.Tools` |
| Sensitive mutation | `[ExportAIFunction(ApprovalRequired = true)]` |
| Static utility tool | Static `[ExportAIFunction]` method |
| Service-backed tool | Instance method on a DI-registered service |
Prefer explicit contexts for production features so tool names and scope stay
stable.
## DI Parameter Binding
The generator classifies parameters at compile time:
| Parameter | Binding |
| --- | --- |
| Plain `string`, `int`, records, enums | JSON argument in the tool schema |
| `CancellationToken` | Function invocation cancellation token |
| `IServiceProvider` | `AIFunctionArguments.Services` |
| `[FromServices] IMyService service` | Resolved from the provider, excluded from schema |
| `[FromKeyedServices("key")] IMyService service` | Resolved from keyed DI, excluded from schema |
For instance methods, the host service itself is resolved from the provider. If
the provider is missing, generated tools throw a clear `InvalidOperationException`
instead of returning fake success.
## Scope and Lifetime
The library does not create DI scopes. Keep the scope alive for as long as the
chat session can invoke tools, then dispose it when the session ends:
`AdditionalTools` on the invocation middleware injects tools into every request
automatically, which is idiomatic for a session-scoped tool set.
```csharp
private IServiceScope? _sessionScope;
private IChatClient? _sessionClient;
if (_sessionClient is IAsyncDisposable asyncDisposable)
await asyncDisposable.DisposeAsync();
else
_sessionClient?.Dispose();
_sessionScope?.Dispose();
_sessionScope = serviceScopeFactory.CreateScope(); // Inject IServiceScopeFactory.
_sessionClient = innerClient.AsBuilder()
.UseFunctionInvocation(configure: invocation =>
invocation.AdditionalTools = [.. GardenTools.Default.Tools])
.Build(_sessionScope.ServiceProvider);
// Also dispose _sessionClient and _sessionScope when the chat session or view model ends.
```
Use a per-chat-session scope when tools hold conversational state.
## AOT and Analyzer Guardrails
- Use declared methods on declared types. Lambdas, local functions, and dynamic
methods are not source-generated tools.
- Add `[Description]` to tools and user-visible parameters.
- Avoid generic methods, `ref`/`out`/`in` parameters, delegates, pointers, and
shapes that cannot round-trip through JSON.
- Materialize `IAsyncEnumerable<T>` results to arrays/lists if the consumer
expects JSON array output.
- Watch diagnostics such as `MAUIAI002`, `MAUIAI003`, and `MAUIAI004`.
## Validation Checklist
- Tool names are stable and safe for the assistant to call.
- Sensitive tools require approval.
- DI services used by tools are registered with the intended lifetime.
- `UseFunctionInvocation().Build(serviceProvider)` flows a provider to tool
invocations.
- The app builds so the generator emits the context and diagnostics.
- Tool output is deterministic enough for the app's AI UX.Colle ce Markdown dans ton agent ou utilise les boutons ci-dessus pour l’écrire dans ton projet.
Ce que fait Maui IA Tool Bindings (.NET)
Use declared methods on declared types. Lambdas, local functions, and dynamic
Add `[Description]` to tools and user-visible parameters.
Avoid generic methods, `ref`/`out`/`in` parameters, delegates, pointers, and
Materialize `IAsyncEnumerable<T>` results to arrays/lists if the consumer
Comment utiliser Maui IA Tool Bindings (.NET)
1
Copie le prompt
Un clic copie le prompt packagé (ou l'envoie à ton agent).
2
L'agent installe le skill
Il ajoute le SKILL.md et ses ressources à ton projet.
3
Activation automatique
Le skill s'active dès que le contexte correspond.
Déclencheurs pour Maui IA Tool Bindings (.NET)
Dis simplement à ton agent quelque chose comme :
Applique le skill maui-ai-tool-bindings__dotnet-maui-labs__plugins-dotnet-maui-skills-6772562beb01 à cette tâche
Utilise maui-ai-tool-bindings__dotnet-maui-labs__plugins-dotnet-maui-skills-6772562beb01 pour améliorer cette implémentation
Passe en revue ce sujet avec maui-ai-tool-bindings__dotnet-maui-labs__plugins-dotnet-maui-skills-6772562beb01
Skills liés à Maui IA Tool Bindings (.NET)
Acceleration (Microsoft)
Compare synthetic acceleration options and clearly separate scenario value from forecast commitments.Account Overview (Microsoft)
Create a synthetic Acme account overview and identify evidence that merits seller attention.Acroform Writer (Microsoft)
Use this skill whenever the user wants values written INTO an existing PDF form that lives in the connected SharePoint knowledge source — filling out, completing, populating, or submitting a fillable PDF (application, intake sheet, contract, government form) from data they supply, a spreadsheet row, or the conversation. Triggers include "fill out the job application form", "complete the intake form for [person]", "populate our standard NDA template", and "make this ready to send / non-editable" (flatten). The source form should be found via knowledge search; only ask the user to upload it if knowledge search turns up nothing plausible. different task), and do NOT use it on scanned/image-only PDFs that have no real fillable fields — those need OCR or manual overlay instead, which this skill explicitly detects and reports rather than silently failing.