Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds shell tool abstractions to Microsoft.Extensions.AI.Abstractions, enabling AI services to interact with shell commands through both hosted (service-executed) and local (client-executed) patterns. The implementation follows established patterns from similar features like image generation and code interpreter tools.
Changes:
- Added five new experimental types for shell tool interactions: HostedShellTool (marker for service-side execution), ShellTool (abstract base for client-side execution), ShellCallContent (represents shell call requests), ShellResultContent (represents execution results), and ShellCommandOutput (structured output data)
- Registered ShellCallContent and ShellResultContent for polymorphic JSON serialization in AIJsonUtilities
- Added AIShell experimental diagnostic ID to enable [Experimental] marking of all shell-related types
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/DiagnosticIds/DiagnosticIds.cs | Added AIShell experimental diagnostic ID |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs | Registered ShellCallContent and ShellResultContent for polymorphic serialization with type discriminators "shellCall" and "shellResult" |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/ShellTool.cs | Abstract base class for client-side shell execution, extends AIFunction with fixed name "local_shell" |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/HostedShellTool.cs | Marker tool for service-side shell execution with name "shell", extends AITool |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellResultContent.cs | Represents shell execution results, extends FunctionResultContent with Output and MaxOutputLength properties |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellCommandOutput.cs | Data class for single command output (stdout, stderr, exit code, timeout flag) |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellCallContent.cs | Represents shell call requests, extends FunctionCallContent with Commands, TimeoutMs, MaxOutputLength, and Status properties |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIContent.cs | Added commented JsonDerivedType entries for ShellCallContent and ShellResultContent (to be uncommented when no longer experimental) |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Tools/ShellToolTests.cs | Tests for ShellTool including constructor, properties, and InvokeAsync with ShellResultContent return |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Tools/HostedShellToolTests.cs | Tests for HostedShellTool constructor and AdditionalProperties handling |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ShellResultContentTests.cs | Comprehensive tests including properties, multiple outputs, and polymorphic serialization |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ShellCommandOutputTests.cs | Tests for ShellCommandOutput properties and serialization including timeout scenarios |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ShellCallContentTests.cs | Tests for ShellCallContent including constructor, properties, and polymorphic serialization |
|
Thanks, @dmytrostruk. We'll want to hold on this until OpenAI 2.9.0 is out and we can better validate the design with the shell tool support it exposes, implementing support for these types in Microsoft.Extensions.AI.OpenAI. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/ShellTool.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellCallContent.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellCommandOutput.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellResultContent.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/HostedShellTool.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/ShellTool.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ShellCallContent.cs
Show resolved
Hide resolved
|
@dmytrostruk please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
|
Addressed all comments, updated PR description to the latest state, waiting to update |
|
@stephentoub Should I agree to the policy agreement mentioned in the comments above or it's not required? |
| /// This tool does not itself implement shell command execution. It is a marker that can be used to inform a service | ||
| /// that the service is allowed to execute shell commands if the service is capable of doing so. |
There was a problem hiding this comment.
From the name HostedShellTool I understand that the inference service executes the shell command but the wording here is quite confusing 😄
Additionally, would you say inference services that don't support shell commands can use a code interpreter instead? Should that be documented here?
Added shell tool abstractions to
Microsoft.Extensions.AI.Abstractionsfor representing shell tool interactions with AI services.New types:
HostedShellTool : AITool— marker tool for hosted shell execution by a serviceShellCallContent : ToolCallContent— represents a shell tool call invocation by a hosted serviceShellResultContent : ToolResultContent— represents the result of a shell tool invocation by a hosted serviceShellCommandOutput : AIContent— structured output of a single command (stdout, stderr, exit code, timeout)Registered
ShellCallContentandShellResultContentfor polymorphic JSON serialization as derived types ofAIContent,ToolCallContent, andToolResultContent. All types are marked [Experimental].Microsoft Reviewers: Open in CodeFlow