Documentation
Table of Contents

Class IntentToolExtensions

Namespace
IntentSharp.Extensions.AI
Assembly
IntentSharp.Extensions.AI.dll

Exposes catalog intents as Microsoft.Extensions.AI Microsoft.Extensions.AI.AIFunction tools, so an Agent Framework agent (or any chat client with function invocation) can call verified, versioned behaviour by name:

var tools = runtime.AsAIFunctions();                       // every enabled intent of an IntentRuntime
var options = new ChatOptions { Tools = [.. tools] };

Each tool takes one input argument (text; a JSON object or text for intents with a compiled .NET result type), runs the intent, and returns JSON: {"success": true, "intent": ..., "value": ...} for a verified result or {"success": false, "intent": ..., "error": ...} otherwise. A tool never throws into the agent loop; only a cancellation the caller asked for propagates.

public static class IntentToolExtensions
Inheritance
object
IntentToolExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

Remarks

Tool names are the intent names with every character outside A-Z a-z 0-9 _ - replaced by _ (Orders.ClassifyUrgency becomes Orders_ClassifyUrgency), because OpenAI and Anthropic refuse dots in tool names. The original intent name is in Microsoft.Extensions.AI.AITool.AdditionalProperties under IntentNameProperty.

The description and the input form are taken from the definition when the tool is created; every call runs the definition that is current at that moment. Recreate the tools after a reload that changes descriptions or adds intents.

A tool answers an exception from the runner (an intent that was removed or disabled, a missing type registration) with success: false, so the agent loop never shows it to an operator. Pass a logger to see each one at Warning.

Fields

IntentNameProperty

The Microsoft.Extensions.AI.AITool.AdditionalProperties key that holds the intent name a tool runs.

MaxToolNameLength

The longest tool name OpenAI and Anthropic accept.

Methods

AsAIFunction(IntentRuntime, string, string?, ILogger?)

A tool that runs the named intent through RunAsync(string, object?, CancellationToken).

AsAIFunction(IIntentInvoker, string, string?, ILogger?)

A tool that runs the named intent.

AsAIFunctions(IntentRuntime)

One tool per enabled intent in the runtime's current catalog snapshot, ordered by intent name.

AsAIFunctions(IntentRuntime, ILogger?)

One tool per enabled intent in the runtime's current catalog snapshot, ordered by intent name, each logging to logger.

AsAIFunctions(IntentRuntime, ILogger?, params string[])

One tool per named intent, in the order given, each logging to logger. Every name must exist; two names may not map to the same tool name.

AsAIFunctions(IntentRuntime, params string[])

One tool per named intent, in the order given. Every name must exist; two names may not map to the same tool name.

AsAIFunctions(IIntentInvoker)

One tool per definition that EnabledDefinitions() returns, in that order.

AsAIFunctions(IIntentInvoker, ILogger?)

One tool per definition that EnabledDefinitions() returns, in that order, each logging to logger.

AsAIFunctions(IIntentInvoker, ILogger?, params string[])

One tool per named intent, in the order given, each logging to logger. Every name must exist; two names may not map to the same tool name.

AsAIFunctions(IIntentInvoker, params string[])

One tool per named intent, in the order given. Every name must exist; two names may not map to the same tool name.

ToToolName(string)

The tool name for an intent: every character outside A-Z a-z 0-9 _ - becomes _. Throws when the result is longer than MaxToolNameLength characters; names are never truncated silently.