Skip to content

Conversation

@gewarren
Copy link
Contributor

@gewarren gewarren commented Nov 18, 2025

@gewarren gewarren requested a review from a team as a code owner November 18, 2025 00:49
Copilot AI review requested due to automatic review settings November 18, 2025 00:49
@dotnetrepoman dotnetrepoman bot added this to the November 2025 milestone Nov 18, 2025
Copilot finished reviewing on behalf of gewarren November 18, 2025 00:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new how-to article about accessing data in AI functions and reorganizes the AI documentation TOC. The changes update existing quickstart examples to use API keys instead of DefaultAzureCredential, upgrade to .NET 10 and newer package versions, and introduce examples showing how to access contextual data within AI function delegates.

Key changes:

  • New how-to article explaining data access patterns in AI functions using AIFunctionArguments and AdditionalProperties
  • TOC restructuring to group function calling and text-to-image content more logically
  • Updates to existing function calling examples with authentication and code comment improvements

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
docs/ai/toc.yml Adds new "Call functions" section and reorganizes "Text to image" section for better structure
docs/ai/quickstarts/use-function-calling.md Updates date, improves grammar, fixes snippet reference case, removes Semantic Kernel note, adds link to new article
docs/ai/quickstarts/snippets/function-calling/openai/Program.cs Updates function description text for consistency
docs/ai/quickstarts/snippets/function-calling/azure-openai/Program.cs Switches from DefaultAzureCredential to API key authentication, updates code comments and formatting
docs/ai/quickstarts/snippets/function-calling/azure-openai/FunctionCallingAI.csproj Upgrades to .NET 10 and Microsoft.Extensions.AI 10.0.0
docs/ai/quickstarts/includes/semantic-kernel.md Removes entire file (Semantic Kernel reference note)
docs/ai/quickstarts/includes/create-ai-service.md Adds API key configuration to user secrets setup
docs/ai/how-to/snippets/access-data/Project.csproj New project file for access-data examples targeting .NET 10
docs/ai/how-to/snippets/access-data/Program.cs New minimal program entry point for running access-data examples
docs/ai/how-to/snippets/access-data/ArgumentsExample.cs New code examples demonstrating AIFunctionArguments and AdditionalProperties usage patterns
docs/ai/how-to/access-data-in-functions.md New how-to article explaining data access mechanisms in AI functions

@gewarren
Copy link
Contributor Author

@verdie-g Do you want to take a look?

@gewarren gewarren requested a review from stephentoub November 18, 2025 01:18

## Pass data

You can associate data with the function at the time it's created, either via closure or via <xref:Microsoft.Extensions.AI.ChatOptions.AdditionalProperties>. If you're creating your own function, you can populate `AdditionalProperties` however you want. If you use <xref:Microsoft.Extensions.AI.AIFunctionFactory> to create the function, you can populate data using <xref:Microsoft.Extensions.AI.AIFunctionFactoryOptions.AdditionalProperties?displayProperty=nameWithType>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also of course capture any references to data as part of the delegate provided to AIFunctionFactory, i.e. bake in whatever you want to reference as part of the AIFunction itself.

(It's probably also worth highlighting somewhere that AIFunction is just a base class; AIFunctionFactory.Create is one producer of AIFunctions, but anyone can derive from it and implement their own. DelegatingAIFunction provides an easy way to wrap an existing AIFunction and layer in additional functionality, including capturing additional data to be used.)

- <xref:Microsoft.Extensions.AI.AIFunctionArguments.Context>: An arbitrary `IDictionary<object, object>` for passing additional ambient data into the function.
- <xref:Microsoft.Extensions.AI.AIFunctionArguments.Services>: An <xref:System.IServiceProvider> that lets the `AIFunction` resolve arbitrary state from a [dependency injection (DI)](../../core/extensions/dependency-injection.md) container.

If you want to access either the `AIFunctionArguments` or the `IServiceProvider` from within your <xref:Microsoft.Extensions.AI.AIFunctionFactory.Create*?displayProperty=nameWithType> delegate, create a parameter typed as `IServiceProvider` or `AIFunctionArguments`. That parameter will be bound to the relevant data from the `AIFunctionArguments` passed to `AIFunction.InvokeAsync()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention here as well that CancellationToken is also special-cased: if the AIFunctionFactory.Create delegate/lambda has a CancellationToken parameter, it'll be bound to the CT that was passed to InvokeAsync.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you address the open conversations, this LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document how to pass data to AIFunction delegates

4 participants