Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Summary

Adds documentation for four mechanisms to pass contextual data to AIFunction delegates, addressing information gap identified in dotnet/extensions#6804.

Fixes #48469

Changes

  • AIFunctionArguments parameter: Access arguments dictionary, Context for loosely-typed data, and Services for DI
  • IServiceProvider parameter: Direct DI integration with automatic binding from AIFunctionArguments.Services
  • FunctionInvokingChatClient.CurrentContext: Static property providing invocation metadata (function details, call ID, chat history)
  • Custom parameter binding: ConfigureParameterBinding callback for advanced scenarios like sourcing parameters from Context instead of arguments

Code Example

// Bind userId from Context instead of AI model arguments
var options = new AIFunctionFactoryOptions
{
    ConfigureParameterBinding = (ParameterInfo parameter) =>
    {
        if (parameter.Name == "userId")
        {
            return new AIFunctionFactoryOptions.ParameterBindingOptions
            {
                BindParameter = (paramInfo, args) => 
                    args.Context.TryGetValue("userId", out var value) ? value : null
            };
        }
        return default;
    }
};

AIFunction function = AIFunctionFactory.Create(
    method: (string location, string userId) => $"Weather for {userId} in {location}",
    options: options);

All code examples compile against current Microsoft.Extensions.AI API.

Original prompt

This section details on the original issue you should resolve

<issue_title>Document how to pass data to AIFunction delegates</issue_title>
<issue_description>### Type of issue

Missing information

Description

In dotnet/extensions#6804, Stephen shares a lot of details about how to access data from an AIFunction delegate. It would be great to document all that:

  • Access AIFunctionArguments
  • Access to IServiceProvider
  • FunctionInvokingChatClient.CurrentContext
  • Custom binding using AIFunctionFactoryOptions.ConfigureParameterBinding

Page URL

https://learn.microsoft.com/en-us/dotnet/ai/quickstarts/use-function-calling

Content source URL

https://github.com/dotnet/docs/blob/main/docs/ai/quickstarts/use-function-calling.md

Document Version Independent Id

7228f348-6649-a87d-bae5-4a70817c03bb

Platform Id

5a517f05-b64b-c471-b99d-72253c213be1

Article author

@gewarren

Metadata

  • ID: 27e2bbca-36b0-3883-11f7-321c044ee29a
  • PlatformId: 5a517f05-b64b-c471-b99d-72253c213be1
  • Service: dotnet
  • Sub-service: intelligent-apps

Related Issues</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/ai/quickstarts/use-function-calling.md CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code how to extend the model using Tools.

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Document how to pass data to AIFunction delegates Document data passing mechanisms for AIFunction delegates Nov 14, 2025
Copilot AI requested a review from gewarren November 14, 2025 01:25
Copilot finished work on behalf of gewarren November 14, 2025 01:25
@gewarren gewarren marked this pull request as ready for review November 14, 2025 01:53
@gewarren gewarren requested a review from a team as a code owner November 14, 2025 01:53
Copilot AI review requested due to automatic review settings November 14, 2025 01:53
Copilot finished reviewing on behalf of gewarren November 14, 2025 01:58
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 comprehensive documentation on data passing mechanisms for AI function delegates in response to issue #48469, addressing an information gap in the function calling quickstart guide.

  • Documents four mechanisms to pass contextual data to AI function delegates
  • Adds code examples demonstrating AIFunctionArguments, IServiceProvider, CurrentContext, and custom parameter binding
  • Updates the date from March 2025 to November 2025

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
docs/ai/quickstarts/use-function-calling.md Adds a new "Pass data to AI functions" section with four subsections documenting different data passing mechanisms (AIFunctionArguments, IServiceProvider, CurrentContext, and custom parameter binding)
docs/ai/quickstarts/snippets/function-calling/openai/AdvancedDataPassing.cs Adds new code example file with four snippets demonstrating each data passing mechanism, plus supporting executable code and type definitions
Comments suppressed due to low confidence (1)

docs/ai/quickstarts/use-function-calling.md:8

  • According to the .NET documentation guidelines for Markdown files, this file should include an ai-usage frontmatter key/value pair to disclose that it was created with the assistance of AI. Add the following to the frontmatter:
ai-usage: ai-assisted
---
title: Quickstart - Extend OpenAI using Tools and execute a local Function with .NET
description: Create a simple chat app using OpenAI and extend the model to execute a local function.
ms.date: 11/13/2025
ms.topic: quickstart
zone_pivot_groups: openai-library
# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code how to extend the model using Tools.
---

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

2 participants