@@ -41,7 +41,7 @@ public ChatTools(EmbeddingClient client = null)
4141 public ChatTools ( params Type [ ] tools ) : this ( ( EmbeddingClient ) null )
4242 {
4343 foreach ( var t in tools )
44- AddLocalTool ( t ) ;
44+ AddFunctionTool ( t ) ;
4545 }
4646
4747 /// <summary>
@@ -58,27 +58,27 @@ public ChatTools(params Type[] tools) : this((EmbeddingClient)null)
5858 /// Adds local tool implementations from the provided types.
5959 /// </summary>
6060 /// <param name="tools">Types containing static methods to be used as tools.</param>
61- public void AddLocalTools ( params Type [ ] tools )
61+ public void AddFunctionTools ( params Type [ ] tools )
6262 {
6363 foreach ( Type functionHolder in tools )
64- AddLocalTool ( functionHolder ) ;
64+ AddFunctionTool ( functionHolder ) ;
6565 }
6666
6767 /// <summary>
6868 /// Adds all public static methods from the specified type as tools.
6969 /// </summary>
7070 /// <param name="tool">The type containing tool methods.</param>
71- internal void AddLocalTool ( Type tool )
71+ internal void AddFunctionTool ( Type tool )
7272 {
7373#pragma warning disable IL2070
7474 foreach ( MethodInfo function in tool . GetMethods ( BindingFlags . Public | BindingFlags . Static ) )
7575 {
76- AddLocalTool ( function ) ;
76+ AddFunctionTool ( function ) ;
7777 }
7878#pragma warning restore IL2070
7979 }
8080
81- internal void AddLocalTool ( MethodInfo function )
81+ internal void AddFunctionTool ( MethodInfo function )
8282 {
8383 string name = function . Name ;
8484 var tool = ChatTool . CreateFunctionTool ( name , ToolsUtility . GetMethodDescription ( function ) , ToolsUtility . BuildParametersJson ( function . GetParameters ( ) ) ) ;
@@ -97,7 +97,7 @@ public async Task AddMcpToolsAsync(McpClient client)
9797 _mcpClientsByEndpoint [ client . Endpoint . AbsoluteUri ] = client ;
9898 await client . StartAsync ( ) . ConfigureAwait ( false ) ;
9999 BinaryData tools = await client . ListToolsAsync ( ) . ConfigureAwait ( false ) ;
100- await AddToolsAsync ( tools , client ) . ConfigureAwait ( false ) ;
100+ await AddMcpToolsAsync ( tools , client ) . ConfigureAwait ( false ) ;
101101 _mcpClients . Add ( client ) ;
102102 }
103103
@@ -112,7 +112,7 @@ public async Task AddMcpToolsAsync(Uri mcpEndpoint)
112112 await AddMcpToolsAsync ( client ) . ConfigureAwait ( false ) ;
113113 }
114114
115- private async Task AddToolsAsync ( BinaryData toolDefinitions , McpClient client )
115+ private async Task AddMcpToolsAsync ( BinaryData toolDefinitions , McpClient client )
116116 {
117117 List < ChatTool > toolsToVectorize = new ( ) ;
118118 var parsedTools = ToolsUtility . ParseMcpToolDefinitions ( toolDefinitions , client ) ;
@@ -158,7 +158,7 @@ private ChatTool ParseToolDefinition(BinaryData data)
158158 /// Converts the tools collection to chat completion options.
159159 /// </summary>
160160 /// <returns>A new ChatCompletionOptions containing all defined tools.</returns>
161- public ChatCompletionOptions CreateCompletionOptions ( )
161+ public ChatCompletionOptions ToChatCompletionOptions ( )
162162 {
163163 var options = new ChatCompletionOptions ( ) ;
164164 foreach ( var tool in _tools )
@@ -173,10 +173,10 @@ public ChatCompletionOptions CreateCompletionOptions()
173173 /// <param name="maxTools">The maximum number of tools to return. Default is 3.</param>
174174 /// <param name="minVectorDistance">The similarity threshold for including tools. Default is 0.29.</param>
175175 /// <returns>A new <see cref="ChatCompletionOptions"/> containing the most relevant tools.</returns>
176- public ChatCompletionOptions CreateCompletionOptions ( string prompt , int maxTools = 3 , float minVectorDistance = 0.29f )
176+ public ChatCompletionOptions CreateCompletionOptions ( string prompt , int maxTools = 5 , float minVectorDistance = 0.29f )
177177 {
178178 if ( ! CanFilterTools )
179- return CreateCompletionOptions ( ) ;
179+ return ToChatCompletionOptions ( ) ;
180180
181181 var completionOptions = new ChatCompletionOptions ( ) ;
182182 foreach ( var tool in FindRelatedTools ( false , prompt , maxTools , minVectorDistance ) . GetAwaiter ( ) . GetResult ( ) )
@@ -191,10 +191,10 @@ public ChatCompletionOptions CreateCompletionOptions(string prompt, int maxTools
191191 /// <param name="maxTools">The maximum number of tools to return. Default is 3.</param>
192192 /// <param name="minVectorDistance">The similarity threshold for including tools. Default is 0.29.</param>
193193 /// <returns>A new <see cref="ChatCompletionOptions"/> containing the most relevant tools.</returns>
194- public async Task < ChatCompletionOptions > CreateCompletionOptionsAsync ( string prompt , int maxTools = 3 , float minVectorDistance = 0.29f )
194+ public async Task < ChatCompletionOptions > ToChatCompletionOptions ( string prompt , int maxTools = 5 , float minVectorDistance = 0.29f )
195195 {
196196 if ( ! CanFilterTools )
197- return CreateCompletionOptions ( ) ;
197+ return ToChatCompletionOptions ( ) ;
198198
199199 var completionOptions = new ChatCompletionOptions ( ) ;
200200 foreach ( var tool in await FindRelatedTools ( true , prompt , maxTools , minVectorDistance ) . ConfigureAwait ( false ) )
@@ -223,12 +223,6 @@ await ToolsUtility.GetEmbeddingAsync(_client, prompt).ConfigureAwait(false) :
223223 }
224224 }
225225
226- /// <summary>
227- /// Implicitly converts ChatTools to <see cref="ChatCompletionOptions"/>.
228- /// </summary>
229- /// <param name="tools">The ChatTools instance to convert.</param>
230- public static implicit operator ChatCompletionOptions ( ChatTools tools ) => tools . CreateCompletionOptions ( ) ;
231-
232226 internal string CallLocal ( ChatToolCall call )
233227 {
234228 var arguments = new List < object > ( ) ;
@@ -260,6 +254,8 @@ internal async Task<string> CallMcpAsync(ChatToolCall call)
260254 var actualFunctionName = call . FunctionName . Substring ( index + ToolsUtility . McpToolSeparator . Length ) ;
261255#endif
262256 var result = await method ( actualFunctionName , call . FunctionArguments ) . ConfigureAwait ( false ) ;
257+ if ( result == null )
258+ throw new InvalidOperationException ( $ "MCP tool { call . FunctionName } returned null. Function tools should always return a value.") ;
263259 return result . ToString ( ) ;
264260 }
265261
0 commit comments