@@ -117,32 +117,10 @@ public async Task<NLWebResponse> ProcessRequestAsync(NLWebRequest request, Cance
117117 _logger . LogDebug ( "ProcessQueryAsync complete for QueryId={QueryId}" , queryId ) ;
118118
119119 // Check if tool execution is available and enabled
120- if ( _toolSelector != null && _toolExecutor != null && _options . ToolSelectionEnabled )
120+ var toolResponse = await HandleToolSelectionAsync ( request , queryId , cancellationToken ) ;
121+ if ( toolResponse != null )
121122 {
122- _logger . LogDebug ( "Tool execution enabled, checking if tool selection is needed for QueryId={QueryId}" , queryId ) ;
123-
124- if ( _toolSelector . ShouldSelectTool ( request ) )
125- {
126- _logger . LogDebug ( "Tool selection needed for QueryId={QueryId}" , queryId ) ;
127-
128- var selectedTool = await _toolSelector . SelectToolAsync ( request , cancellationToken ) ;
129- if ( ! string . IsNullOrEmpty ( selectedTool ) )
130- {
131- _logger . LogInformation ( "Tool '{Tool}' selected for QueryId={QueryId}, executing tool" , selectedTool , queryId ) ;
132-
133- try
134- {
135- var toolResponse = await _toolExecutor . ExecuteToolAsync ( request , selectedTool , cancellationToken ) ;
136- _logger . LogInformation ( "[END] Tool execution completed for QueryId={QueryId} with tool '{Tool}'" , queryId , selectedTool ) ;
137- return toolResponse ;
138- }
139- catch ( Exception toolEx )
140- {
141- _logger . LogError ( toolEx , "Tool execution failed for QueryId={QueryId} with tool '{Tool}', falling back to standard processing" , queryId , selectedTool ) ;
142- // Fall through to standard processing
143- }
144- }
145- }
123+ return toolResponse ;
146124 }
147125
148126 _logger . LogDebug ( "Using standard processing pipeline for QueryId={QueryId}" , queryId ) ;
0 commit comments