-
Notifications
You must be signed in to change notification settings - Fork 827
Add function approvals support #6745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stephentoub
merged 1 commit into
dotnet:main
from
westey-m:add-approvals-to-functioninvokingchatclient
Sep 5, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalRequestContent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents a request for user approval of a function call. | ||
/// </summary> | ||
[Experimental("MEAI001")] | ||
public sealed class FunctionApprovalRequestContent : UserInputRequestContent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FunctionApprovalRequestContent"/> class. | ||
/// </summary> | ||
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param> | ||
/// <param name="functionCall">The function call that requires user approval.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception> | ||
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception> | ||
public FunctionApprovalRequestContent(string id, FunctionCallContent functionCall) | ||
: base(id) | ||
{ | ||
FunctionCall = Throw.IfNull(functionCall); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the function call that pre-invoke approval is required for. | ||
/// </summary> | ||
public FunctionCallContent FunctionCall { get; } | ||
|
||
/// <summary> | ||
/// Creates a <see cref="FunctionApprovalResponseContent"/> to indicate whether the function call is approved or rejected based on the value of <paramref name="approved"/>. | ||
/// </summary> | ||
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param> | ||
/// <returns>The <see cref="FunctionApprovalResponseContent"/> representing the approval response.</returns> | ||
public FunctionApprovalResponseContent CreateResponse(bool approved) => new(Id, approved, FunctionCall); | ||
} |
41 changes: 41 additions & 0 deletions
41
...ibraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalResponseContent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents a response to a function approval request. | ||
/// </summary> | ||
[Experimental("MEAI001")] | ||
public sealed class FunctionApprovalResponseContent : UserInputResponseContent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FunctionApprovalResponseContent"/> class. | ||
/// </summary> | ||
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param> | ||
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param> | ||
/// <param name="functionCall">The function call that requires user approval.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception> | ||
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception> | ||
public FunctionApprovalResponseContent(string id, bool approved, FunctionCallContent functionCall) | ||
: base(id) | ||
{ | ||
Approved = approved; | ||
FunctionCall = Throw.IfNull(functionCall); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the user approved the request. | ||
/// </summary> | ||
public bool Approved { get; } | ||
|
||
/// <summary> | ||
/// Gets the function call for which approval was requested. | ||
/// </summary> | ||
public FunctionCallContent FunctionCall { get; } | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UserInputRequestContent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents a request for user input. | ||
/// </summary> | ||
[Experimental("MEAI001")] | ||
public class UserInputRequestContent : AIContent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UserInputRequestContent"/> class. | ||
/// </summary> | ||
/// <param name="id">The ID that uniquely identifies the user input request/response pair.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception> | ||
protected UserInputRequestContent(string id) | ||
{ | ||
Id = Throw.IfNullOrWhitespace(id); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the ID that uniquely identifies the user input request/response pair. | ||
/// </summary> | ||
public string Id { get; } | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UserInputResponseContent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents the response to a request for user input. | ||
/// </summary> | ||
[Experimental("MEAI001")] | ||
public class UserInputResponseContent : AIContent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UserInputResponseContent"/> class. | ||
/// </summary> | ||
/// <param name="id">The ID that uniquely identifies the user input request/response pair.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception> | ||
protected UserInputResponseContent(string id) | ||
{ | ||
Id = Throw.IfNullOrWhitespace(id); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the ID that uniquely identifies the user input request/response pair. | ||
/// </summary> | ||
public string Id { get; } | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/ApprovalRequiredAIFunction.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents an <see cref="AIFunction"/> that can be described to an AI service and invoked, but for which | ||
/// the invoker should obtain user approval before the function is actually invoked. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class simply augments an <see cref="AIFunction"/> with an indication that approval is required before invocation. | ||
/// It does not enforce the requirement for user approval; it is the responsibility of the invoker to obtain that approval before invoking the function. | ||
/// </remarks> | ||
[Experimental("MEAI001")] | ||
public sealed class ApprovalRequiredAIFunction : DelegatingAIFunction | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ApprovalRequiredAIFunction"/> class. | ||
/// </summary> | ||
/// <param name="innerFunction">The <see cref="AIFunction"/> represented by this instance.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="innerFunction"/> is <see langword="null"/>.</exception> | ||
public ApprovalRequiredAIFunction(AIFunction innerFunction) | ||
: base(innerFunction) | ||
{ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.