Commit bc2258f
HostedToolSearchTool with DeferredTools in the type (#7471)
* Implement HostedToolSearchTool and SearchableAIFunctionDeclaration for tool search support
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Redesign: consolidate tool search into HostedToolSearchTool with DeferredTools/NonDeferredTools
- Redesign HostedToolSearchTool with DeferredTools/NonDeferredTools properties
- Remove SearchableAIFunctionDeclaration (no longer needed)
- Revert DelegatingAIFunctionDeclaration to internal
- Update OpenAI provider: use HostedToolSearchTool enable/disable logic for defer_loading
- Add ChatOptions parameter to AsOpenAIResponseTool extension method
- Use AOT-safe ModelReaderWriter.Read with OpenAIContext.Default
- Update API baselines and tests
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Address review feedback: fix O(N²), remove json baseline entry, refactor ToResponseTool signature
- Fix O(N²) by finding HostedToolSearchTool once before the tools loop
instead of scanning the list for each tool
- Remove HostedToolSearchTool from json baseline (experimental types
don't need entries)
- Refactor ToResponseTool(AITool, ...) to take HostedToolSearchTool?
directly instead of extracting from ChatOptions each time
- Remove FindToolSearchTool helper method (inlined into callers)
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Extract shared FindToolSearchTool helper to deduplicate lookup code
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Simplify ToResponseTool: add ChatOptions-only overload, make FindToolSearchTool private
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add unit tests for HostedToolSearchTool JSON serialization and integration test
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Revert to SearchableAIFunctionDeclaration design, remove DeferredTools/NonDeferredTools from HostedToolSearchTool
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/7a29d49e-c422-4fe7-81f4-366bd781b460
* Address review feedback: rename namespaceName to @namespace, add openai-dotnet#1053 comment, add DeferLoadingTools to HostedMcpServerTool
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/08f652ed-169c-43c3-a247-829ebd0b3e4f
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Update tests
* revert namespace param rename
* Remove Namespace from SearchableAIFunctionDeclaration and DeferLoadingTools from HostedMcpServerTool, add interaction tests
- Remove Namespace property and namespaceName parameter from SearchableAIFunctionDeclaration
- Remove DeferLoadingTools property from HostedMcpServerTool
- Update OpenAIResponsesChatClient to drop namespace patching and MCP defer_loading patching
- Update RemoteMCP_DeferLoadingTools integration test to use AsOpenAIResponseTool() + Patch.Set + AsAITool()
- Add tool_search_call/tool_search_output assertions to integration test
- Add SearchableAIFunctionDeclaration + ApprovalRequiredAIFunction interaction tests
- Add FunctionInvokingChatClient test for approval detection through searchable wrapper
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Remove [Experimental] from tool search types and add API baselines
Remove [Experimental(AIToolSearch)] attribute from DelegatingAIFunctionDeclaration,
SearchableAIFunctionDeclaration, and HostedToolSearchTool. Remove the AIToolSearch
diagnostic constant from DiagnosticIds. Add API baseline entries for all three types
in Microsoft.Extensions.AI.Abstractions.json. Clean up unused usings.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add integration tests for tool search edge cases
Add tests verifying that the OpenAI API returns HTTP 400 when
HostedToolSearchTool is used without any deferred tools:
- UseToolSearch_OnlyToolSearchNoFunctions
- UseToolSearch_WithNonDeferredFunctionsOnly
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add namespace support to SearchableAIFunctionDeclaration and namespace grouping in OpenAIResponsesChatClient
- Add Namespace property and namespaceName parameter to SearchableAIFunctionDeclaration
- Add namespaceName parameter to CreateToolSet for bulk namespace assignment
- Add namespace grouping logic in OpenAIResponsesChatClient tools loop
- Add ToNamespaceResponseTool helper using ModelReaderWriter for AOT-safe JSON
- Add namespace unit tests in SearchableAIFunctionDeclarationTests
- Add namespace VerbatimHttpHandler tests in OpenAIResponseClientTests
- Add UseToolSearch_WithNamespace integration test with tool_search assertions
- Add tool_search_call/tool_search_output assertions to existing integration test
- Update API baseline
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Feedback
* Remove Namespace from SearchableAIFunctionDeclaration and namespace grouping from OpenAI provider
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/a0e8d299-9f73-4db3-be63-674f590aa717
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Revert "Remove Namespace from SearchableAIFunctionDeclaration and namespace grouping from OpenAI provider"
This reverts commit 89d8df4.
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Fix CI: replace KeyValuePair deconstruction for net462/netstandard2.0 and restore @namespace param name
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/1783bbad-9689-4b08-bfcc-79988248c2ff
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Add DeferredTools/Namespace on HostedToolSearchTool, support MCP tools
- Replace per-tool SearchableAIFunctionDeclaration with collections-based
DeferredTools and Namespace properties on HostedToolSearchTool
- Support multiple HostedToolSearchTool instances with different/same
namespaces (same namespace merges, first-claims wins)
- Patch defer_loading on both FunctionTool and McpTool when claimed by
a HostedToolSearchTool
- Group deferred FunctionTool and McpTool into namespace containers
- Widen ToNamespaceResponseTool to accept any ResponseTool
- Add AsOpenAIResponseTool ChatOptions parameter for defer context
- Delete SearchableAIFunctionDeclaration and its tests
- Make DelegatingAIFunctionDeclaration internal (no external consumers)
- Add conversion, VerbatimHttpHandler, and integration tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Address tool-search reviewer feedback for docs and lookup performance
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/cc5b7c31-3c0f-448e-95c6-2474c2327715
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Refine HostedToolSearchTool docs to use deferrable tool wording
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/8f9ae606-8c21-4af0-b43d-74a2b463ed33
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Optimize tool-search lookup precomputation in OpenAI responses client
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/cc5b7c31-3c0f-448e-95c6-2474c2327715
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
* Add tests for non-deferrable tools with HostedToolSearchTool
Verify that tools like HostedCodeInterpreterTool are unaffected by
DeferredTools and namespace grouping: no defer_loading is patched
and the tool stays top-level in the request.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Bring back Experimental
* Address test feedback
* Drop ChatOptions parameter from AsOpenAIResponseTool(AITool)
The ChatOptions? parameter was added so the standalone extension method could honor HostedToolSearchTool.DeferredTools when converting an AITool outside the chat client. In practice, this introduces an O(N^2) hazard if called in a loop (each call rebuilds the ToolSearchLookup) and adds API surface for a niche escape-hatch scenario. The primary path (GetResponseAsync) shares a single lookup and is unaffected.
Future per-tool deferral mechanisms (e.g. a SearchableAITool decorator or a DeferLoading bool on AITool) would obsolete this parameter entirely.
Callers building ResponseTool lists manually can still set defer_loading via Patch.Set as needed.
Removes 11 conversion-level unit tests whose coverage is already provided end-to-end by VerbatimHttpHandler-based tests in OpenAIResponseClientTests.cs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 7723587 commit bc2258f
8 files changed
Lines changed: 1537 additions & 4 deletions
File tree
- src
- Libraries
- Microsoft.Extensions.AI.Abstractions
- Tools
- Microsoft.Extensions.AI.OpenAI
- test/Libraries
- Microsoft.Extensions.AI.Abstractions.Tests/Tools
- Microsoft.Extensions.AI.OpenAI.Tests
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2687 | 2687 | | |
2688 | 2688 | | |
2689 | 2689 | | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
2690 | 2722 | | |
2691 | 2723 | | |
2692 | 2724 | | |
| |||
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
Lines changed: 171 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
701 | 702 | | |
702 | 703 | | |
703 | 704 | | |
704 | | - | |
| 705 | + | |
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
708 | 709 | | |
709 | 710 | | |
710 | 711 | | |
711 | 712 | | |
712 | | - | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
713 | 725 | | |
714 | 726 | | |
715 | 727 | | |
| |||
821 | 833 | | |
822 | 834 | | |
823 | 835 | | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
824 | 841 | | |
825 | 842 | | |
826 | 843 | | |
| |||
843 | 860 | | |
844 | 861 | | |
845 | 862 | | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
846 | 891 | | |
847 | 892 | | |
848 | 893 | | |
| |||
926 | 971 | | |
927 | 972 | | |
928 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
929 | 977 | | |
930 | 978 | | |
931 | | - | |
| 979 | + | |
932 | 980 | | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
933 | 1001 | | |
934 | 1002 | | |
935 | 1003 | | |
936 | 1004 | | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
937 | 1013 | | |
938 | 1014 | | |
939 | 1015 | | |
| |||
969 | 1045 | | |
970 | 1046 | | |
971 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
972 | 1140 | | |
973 | 1141 | | |
974 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
0 commit comments