-
Notifications
You must be signed in to change notification settings - Fork 667
.NET: ADR: Supporting user approvals #209
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
Closed
Closed
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
c73282b
ADR: Supporting user approvals
westey-m 9e3b98b
Add more context.
westey-m a9a6a97
Add further justification
westey-m 61063c0
Add decision drivers.
westey-m 3a0dabf
Update with Copilot Suggestion
westey-m 786374c
Merge branch 'main' into userapproval-adr
westey-m eace4e7
Update adr with feedback.
westey-m 4076ed3
Adding another generalized option for all user input.
westey-m 23b4fe5
Merge branch 'main' into userapproval-adr
westey-m 12817f1
Add another base class based UserInput option
westey-m 84e2855
Remove TextContent inheritance.
westey-m 632635c
Change Schema and Strucutured input data types to JsonElement
westey-m 461c8ef
Rename JsonSchema to Schema
westey-m 7de1787
Merge branch 'main' into userapproval-adr
westey-m aa3c14e
Merge branch 'main' into userapproval-adr
crickman ab04590
Address some feedback.
westey-m aba7dc6
Merge branch 'main' into userapproval-adr
westey-m 89ff266
Merge branch 'main' into userapproval-adr
crickman 629204e
Add base user input request and response types with FunctionApproval …
westey-m 3783074
Merge branch 'main' into userapproval-adr
crickman d3a9319
Merge branch 'main' into userapproval-adr
westey-m 74d1f5d
Add POC ApprovalGeneratingChatClient
westey-m 3c40615
Merge branch 'main' into userapproval-adr
crickman c068247
Add pre-FunctionInvokingChatClient ApprovalGeneratingChatClient POC
westey-m d8626a4
Merge branch 'userapproval-adr' of https://github.com/westey-m/agent-…
westey-m 45254f3
Merge branch 'main' into userapproval-adr
westey-m 3300dce
Merge branch 'main' into userapproval-adr
westey-m c8e42de
Fix namespaces
westey-m 97352a0
Add combined FICC with approvals
westey-m 2c39648
Bug fix.
westey-m 5293568
Add MCP and ApprovalRequiredAIFunction POC
westey-m c5bedd0
Bug fixes
westey-m edcad34
Address PR Feedback.
westey-m 0a61294
Add AIFunctionApprovalContext with some small efficiency improvements.
westey-m 436c490
Remove unecessary helpers that are only used in one place.
westey-m 0d5fcbf
Replace dictionary with array and lazy initialize.
westey-m 8beb0f6
Improve sample code
westey-m 9fbd0a7
Make user input id required and rename it to be more general.
westey-m 302d43d
Merge branch 'main' into userapproval-adr
westey-m 8ad466b
Upgrade packages to resolve conflicts.
westey-m 049c9d3
Move some code into methods to simply main GetResponse.
westey-m 39ef6bd
Adding approvals support to streaming
westey-m 14d4773
Address PR comments.
westey-m b288fed
Change approval response type and naming
westey-m fc0bf74
Remove commented out validation checks that won't work for server sid…
westey-m d1939ad
Remove original metadata and read metadata from approval request mess…
westey-m 6d8b20e
Small code refactoring and clarifying comments.
westey-m 2bc90af
Remove failed POCs
westey-m d12cdf8
Update ADR with latest changes
westey-m 3420337
Explain case when pre FICC AGCC fails
westey-m 6a6f9dd
Add support for mcp servers over http.
westey-m f05bf90
Merge branch 'main' into userapproval-adr
westey-m 3105941
Addressing PR comments.
westey-m 26eb742
Address PR comments
westey-m 0adf519
Merge branch 'main' into userapproval-adr
westey-m b2a4915
Merge latest updates from main
westey-m 5e52c11
Add FICC unit tests and fix bugs.
westey-m b1289e3
Add additional unit test.
westey-m 0b4405e
Refactor ConvertToFunctionCallContentMessages to avoid unecessary all…
westey-m 545c231
Refactor preinvocation logic to share between streaming and non-strea…
westey-m e6aeebb
Move some approval generation code to a separate method to simplify m…
westey-m a1b2973
More refactoring, additional unit tests and bug fixes.
westey-m 906ad2f
Remove comments delineating additions.
westey-m 4c59b25
Merge latest changes from main
westey-m 66b904e
Fixing some typos.
westey-m d3dd02e
Merge branch 'main' into userapproval-adr
westey-m 21680be
Address PR comments.
westey-m a712408
Address PR comments.
westey-m c1da46b
Address PR feedback.
westey-m 091f754
Fix bug for server side threads.
westey-m 7518b70
Address PR comments
westey-m a349c79
Merge from main
westey-m 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
61 changes: 61 additions & 0 deletions
61
dotnet/src/Microsoft.Extensions.AI.Agents.Abstractions/MEAI/HostedMcpServerTool.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,61 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Represents a hosted MCP server tool that can be specified to an AI service. | ||
| /// </summary> | ||
| public class HostedMcpServerTool : AITool | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="HostedMcpServerTool"/> class. | ||
| /// </summary> | ||
| /// <param name="serverName">The name of the remote MCP server.</param> | ||
| /// <param name="url">The URL of the remote MCP server.</param> | ||
| public HostedMcpServerTool(string serverName, Uri url) | ||
rogerbarreto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| ServerName = Throw.IfNullOrWhitespace(serverName); | ||
| Url = Throw.IfNull(url); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the remote MCP server that is used to identify it. | ||
| /// </summary> | ||
| public string ServerName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the URL of the remote MCP server. | ||
| /// </summary> | ||
| public Uri Url { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the description of the remote MCP server, used to provide more context to the AI service. | ||
| /// </summary> | ||
| public string? ServerDescription { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the list of tools allowed to be used by the AI service. | ||
| /// </summary> | ||
| public IList<string>? AllowedTools { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the approval mode that indicates when the AI service should require user approval for tool calls to the remote MCP server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// You can set this property to <see cref="HostedMcpServerToolApprovalMode.AlwaysRequire"/> to require approval for all tool calls, | ||
| /// or to <see cref="HostedMcpServerToolApprovalMode.NeverRequire"/> to never require approval. | ||
| /// </remarks> | ||
| public HostedMcpServerToolApprovalMode? ApprovalMode { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the HTTP headers that the AI service should use when making tool calls to the remote MCP server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This property is useful for specifying the authentication header or other headers required by the MCP server. | ||
| /// </remarks> | ||
| public IDictionary<string, string>? Headers { get; set; } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
...ft.Extensions.AI.Agents.Abstractions/MEAI/HostedMcpServerToolAlwaysRequireApprovalMode.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,14 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Indicates that approval is always required for tool calls to a hosted MCP server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Use <see cref="HostedMcpServerToolApprovalMode.AlwaysRequire"/> to get an instance of <see cref="HostedMcpServerToolAlwaysRequireApprovalMode"/>. | ||
| /// </remarks> | ||
| [DebuggerDisplay(nameof(AlwaysRequire))] | ||
| public sealed class HostedMcpServerToolAlwaysRequireApprovalMode : HostedMcpServerToolApprovalMode; |
40 changes: 40 additions & 0 deletions
40
...t/src/Microsoft.Extensions.AI.Agents.Abstractions/MEAI/HostedMcpServerToolApprovalMode.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,40 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Describes how approval is required for tool calls to a hosted MCP server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The predefined values <see cref="AlwaysRequire" />, and <see cref="NeverRequire"/> are provided to specify handling for all tools. | ||
| /// To specify approval behavior for individual tool names, use <see cref="RequireSpecific(IList{string}, IList{string})"/>. | ||
| /// </remarks> | ||
| #pragma warning disable CA1052 // Static holder types should be Static or NotInheritable | ||
| public class HostedMcpServerToolApprovalMode | ||
| #pragma warning restore CA1052 | ||
| { | ||
| /// <summary> | ||
| /// Gets a predefined <see cref="HostedMcpServerToolApprovalMode"/> indicating that all tool calls to a hosted MCP server always require approval. | ||
| /// </summary> | ||
| public static HostedMcpServerToolAlwaysRequireApprovalMode AlwaysRequire { get; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// Gets a predefined <see cref="HostedMcpServerToolApprovalMode"/> indicating that all tool calls to a hosted MCP server never require approval. | ||
| /// </summary> | ||
| public static HostedMcpServerToolNeverRequireApprovalMode NeverRequire { get; } = new(); | ||
|
|
||
| private protected HostedMcpServerToolApprovalMode() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Instantiates a <see cref="HostedMcpServerToolApprovalMode"/> that specifies approval behavior for individual tool names. | ||
| /// </summary> | ||
| /// <param name="alwaysRequireApprovalToolNames">The list of tools names that always require approval.</param> | ||
| /// <param name="neverRequireApprovalToolNames">The list of tools names that never require approval.</param> | ||
| /// <returns>An instance of <see cref="HostedMcpServerToolRequireSpecificApprovalMode"/> for the specified tool names.</returns> | ||
| public static HostedMcpServerToolRequireSpecificApprovalMode RequireSpecific(IList<string>? alwaysRequireApprovalToolNames, IList<string>? neverRequireApprovalToolNames) | ||
| => new(alwaysRequireApprovalToolNames, neverRequireApprovalToolNames); | ||
| } |
14 changes: 14 additions & 0 deletions
14
...ft.Extensions.AI.Agents.Abstractions/MEAI/HostedMcpServerToolNeverRequireApprovalMode .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,14 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Indicates that approval is never required for tool calls to a hosted MCP server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Use <see cref="HostedMcpServerToolApprovalMode.NeverRequire"/> to get an instance of <see cref="HostedMcpServerToolNeverRequireApprovalMode"/>. | ||
| /// </remarks> | ||
| [DebuggerDisplay(nameof(NeverRequire))] | ||
| public sealed class HostedMcpServerToolNeverRequireApprovalMode : HostedMcpServerToolApprovalMode; |
32 changes: 32 additions & 0 deletions
32
...Extensions.AI.Agents.Abstractions/MEAI/HostedMcpServerToolRequireSpecificApprovalMode .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,32 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Represents a mode where approval behavior is specified for individual tool names. | ||
| /// </summary> | ||
| public sealed class HostedMcpServerToolRequireSpecificApprovalMode : HostedMcpServerToolApprovalMode | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="HostedMcpServerToolRequireSpecificApprovalMode"/> class that specifies approval behavior for individual tool names. | ||
| /// </summary> | ||
| /// <param name="alwaysRequireApprovalToolNames">The list of tools names that always require approval.</param> | ||
| /// <param name="neverRequireApprovalToolNames">The list of tools names that never require approval.</param> | ||
| public HostedMcpServerToolRequireSpecificApprovalMode(IList<string>? alwaysRequireApprovalToolNames, IList<string>? neverRequireApprovalToolNames) | ||
| { | ||
| AlwaysRequireApprovalToolNames = alwaysRequireApprovalToolNames; | ||
| NeverRequireApprovalToolNames = neverRequireApprovalToolNames; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the list of tool names that always require approval. | ||
| /// </summary> | ||
| public IList<string>? AlwaysRequireApprovalToolNames { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the list of tool names that never require approval. | ||
| /// </summary> | ||
| public IList<string>? NeverRequireApprovalToolNames { get; set; } | ||
| } |
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.