Skip to content

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Aug 7, 2025

  • Adds AIFunctionDefinition as a base class for AIFunction, where AIFunction layers on invocability over the metadata exposed by the base.
  • Added AIFunctionFactory.CreateDefinition and AIFunction.AsDefinitionOnly for creating AIFunctionDefinitions that aren't invocable.
  • Updated FunctionInvokingChatClient to allow non-AIFunction call requests to pass through.
  • Added FunctionInvokingChatClient.TerminateOnUnknownCalls to control behavior when requests are made to unknown functions.

Closes #6688

Microsoft Reviewers: Open in CodeFlow

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Aug 7, 2025
Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Looks great! I think this is a perfectly clear distinction between definition/implementation.

Copy link
Contributor

@shyamnamboodiripad shyamnamboodiripad left a comment

Choose a reason for hiding this comment

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

Thanks much for adding! The only other thing that may be nice to include is a simple helper / API to construct definitions for non-invokable tools (such as server-side tools).

@stephentoub stephentoub force-pushed the splitaifunction branch 2 times, most recently from 7dfb1cf to c77ef04 Compare August 14, 2025 16:47
@stephentoub stephentoub marked this pull request as ready for review August 14, 2025 16:49
@Copilot Copilot AI review requested due to automatic review settings August 14, 2025 16:49
@stephentoub stephentoub requested review from a team as code owners August 14, 2025 16:49
@stephentoub stephentoub requested a review from jozkee August 14, 2025 16:49
Copy link
Contributor

@Copilot 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 splits AIFunction into a base class hierarchy by introducing AIFunctionDefinition as a new base class. The main purpose is to enable scenarios where function metadata is needed without invocability, allowing better separation of concerns between function definition and execution.

  • Introduces AIFunctionDefinition as a base class containing only metadata properties (Name, Description, JsonSchema, ReturnJsonSchema)
  • Updates AIFunction to inherit from AIFunctionDefinition while maintaining invocation capabilities
  • Adds support for non-invocable function definitions in FunctionInvokingChatClient with new TerminateOnUnknownCalls property

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionDefinition.cs New base class containing function metadata properties
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunction.cs Updated to inherit from AIFunctionDefinition and added AsDefinitionOnly() method
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs Added CreateDefinition method for creating non-invocable function definitions
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs Enhanced to handle non-invocable tools with new TerminateOnUnknownCalls property
Multiple OpenAI integration files Updated method signatures to accept AIFunctionDefinition instead of AIFunction
Test files Added comprehensive test coverage for new functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@shyamnamboodiripad shyamnamboodiripad left a comment

Choose a reason for hiding this comment

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

:shipit:

@stephentoub
Copy link
Member Author

@SteveSandersonMS, would you mind taking another look? In particular at the FICC logic changes. Thanks.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Other than misgivings about the choice of name, this is a good change.

Enable a representation that doesn't support invocation separate from one that does.
@stephentoub stephentoub merged commit e57e605 into dotnet:main Sep 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let not-found functions pass through FunctionInvokingChatClient
5 participants