Skip to content
Introducing AI Conversations: Natural Language Interaction for Your Apps! Learn More

AI Tools

The AI conversation service supports Microsoft.Extensions.AI tools (AITool) that are automatically included in every chat request. This lets the AI call functions on the user’s behalf.

Any AITool registered in DI is automatically injected into the service and included in chat requests. This means that any library that registers AITool instances in your service collection will have those tools available to the AI — no extra wiring needed.

For example, if you add Shiny.DI’s generated AI tools, Shiny.DocumentDb’s AI tools, or Shiny.Mediator’s AI tools to your DI container, they are automatically picked up by the conversation service and made available to the AI model during chat.

// These tools are all automatically discovered and included in AI chat requests
// Shiny.DI source-generated tools
builder.Services.AddGeneratedAITools();
// Shiny.DocumentDb tools
builder.Services.AddDocumentStoreAITools(tools => { /* ... */ });
// Your own custom tools
builder.Services.AddSingleton<AITool>(sp =>
{
return AIFunctionFactory.Create((string city) =>
{
return $"The weather in {city} is sunny, 72°F.";
}, "GetWeather", "Gets the current weather for a city");
});

When you register an IMessageStore with addAiLookupTool: true (the default), a ChatLookupAITool is automatically registered:

opts.SetMessageStore<MyMessageStore>(addAiLookupTool: true);

This gives the AI the ability to search past conversations. Users can ask questions like:

  • “What did we discuss yesterday?”
  • “Find the conversation where we talked about deployment”
  • “What was the recipe you gave me last week?”

The tool exposes these search parameters to the AI:

ParameterTypeDescription
messageContainsstring?Text to search for in messages
fromDateDateTimeOffset?Start of date range
toDateDateTimeOffset?End of date range
limitint?Maximum results to return

You can register any number of custom tools. They’re standard Microsoft.Extensions.AI tools:

// Function-based tool
builder.Services.AddSingleton<AITool>(sp =>
AIFunctionFactory.Create(
async (string query, CancellationToken ct) =>
{
var db = sp.GetRequiredService<IDatabase>();
var results = await db.Search(query, ct);
return string.Join("\n", results);
},
"SearchDatabase",
"Searches the application database"
)
);