Skip to content

Conversation

@rogerbarreto
Copy link
Contributor

@rogerbarreto rogerbarreto commented Oct 24, 2025

This pull request adds support for converting a wider range of AI tool types into OpenAI ResponseTool instances, 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

  • Added a new extension method AsOpenAIResponseTool to the MicrosoftExtensionsAIResponsesExtensions class, allowing conversion from any AITool to an OpenAI ResponseTool, or returning null if unsupported.
  • Implemented the core conversion logic in OpenAIResponsesChatClient.ToResponseTool, supporting multiple tool types including AIFunctionDeclaration, HostedWebSearchTool, HostedFileSearchTool, HostedCodeInterpreterTool, and HostedMcpServerTool, with detailed handling for each type's properties and options.

Testing improvements

  • Added thorough unit tests for the new conversion method, covering all supported tool types, property mapping, edge cases (unknown tool types, null input), and ensuring correct output types and values.
  • Introduced a helper class UnknownAITool in the test suite to verify behavior when an unsupported tool type is passed to the conversion method.
Microsoft Reviewers: Open in CodeFlow

@rogerbarreto rogerbarreto requested a review from a team as a code owner October 24, 2025 14:33
Copilot AI review requested due to automatic review settings October 24, 2025 14:33
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 24, 2025
Copy link
Contributor

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 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 ToResponseTool to accept AITool base type and return nullable ResponseTool
  • Added new public extension method AsOpenAIResponseTool(AITool) to support broader tool conversion
  • Extracted tool conversion logic from ToOpenAIResponseCreationOptions into the refactored ToResponseTool method

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

…atClient.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
rogerbarreto and others added 3 commits October 24, 2025 16:00
…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>
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@stephentoub stephentoub merged commit 59b2c59 into dotnet:main Oct 24, 2025
6 checks passed
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Nov 1, 2025
…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>
jeffhandley pushed a commit that referenced this pull request Nov 2, 2025
* 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 was referenced Nov 13, 2025
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.

2 participants