-
Notifications
You must be signed in to change notification settings - Fork 841
Add AITool -> OpenAI.Responses.ResponseTool conversion utility #6958
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
Conversation
There was a problem hiding this 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 a new extension method AsOpenAIResponseTool that converts any AITool to an OpenAI ResponseTool, expanding support beyond just AIFunctionDeclaration to include web search, file search, code interpreter, and MCP server tools.
Key Changes:
- Refactored
ToResponseToolto acceptAIToolbase type and return nullableResponseTool - Added new public extension method
AsOpenAIResponseTool(AITool)to support broader tool conversion - Extracted tool conversion logic from
ToOpenAIResponseCreationOptionsinto the refactoredToResponseToolmethod
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs |
Added new AsOpenAIResponseTool(AITool) extension method |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs |
Refactored ToResponseTool to handle multiple tool types and return nullable ResponseTool, extracted conversion logic from options method |
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs |
Added comprehensive test coverage for all supported tool types, edge cases, and introduced helper class for unsupported tool testing |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs
Outdated
Show resolved
Hide resolved
…atClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
…nsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
…atClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
…atClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs
Outdated
Show resolved
Hide resolved
…nsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
stephentoub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
…t#6958) * Add utility for ResponseTool * Adding UT for Utility * Update internals to utility * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update test to use the AITool extension directly * Improve UT * Add MCP missing UT * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Add utility for ResponseTool * Adding UT for Utility * Update internals to utility * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update test to use the AITool extension directly * Improve UT * Add MCP missing UT * Update src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
This pull request adds support for converting a wider range of AI tool types into OpenAI
ResponseToolinstances, improving interoperability and extensibility. The main update is the introduction of a new conversion method and its comprehensive test coverage, ensuring correct behavior for all supported tool types and edge cases.Conversion method enhancements
AsOpenAIResponseToolto theMicrosoftExtensionsAIResponsesExtensionsclass, allowing conversion from anyAIToolto an OpenAIResponseTool, or returningnullif unsupported.OpenAIResponsesChatClient.ToResponseTool, supporting multiple tool types includingAIFunctionDeclaration,HostedWebSearchTool,HostedFileSearchTool,HostedCodeInterpreterTool, andHostedMcpServerTool, with detailed handling for each type's properties and options.Testing improvements
UnknownAIToolin the test suite to verify behavior when an unsupported tool type is passed to the conversion method.Microsoft Reviewers: Open in CodeFlow