File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
libs/langchain/src/agents/middlewareAgent/middleware Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -191,30 +191,41 @@ export function llmToolSelectorMiddleware(options: LLMToolSelectorOptions) {
191191 systemMessage += `\n\nNote: You have selected more tools than the maximum allowed. You can select up to ${ maxTools } tools.` ;
192192 attempts ++ ;
193193 } else if ( invalidTools . length === 0 ) {
194- break ; // Success
194+ /**
195+ * Success
196+ */
197+ break ;
195198 } else if ( attempts < maxRetries ) {
196- // Retry with feedback about invalid tools
199+ /**
200+ * Retry with feedback about invalid tools
201+ */
197202 systemMessage += `\n\nNote: The following tools are not available: ${ invalidTools . join (
198203 ", "
199204 ) } . Please select only from the available tools.`;
200205 attempts ++ ;
201206 } else {
202- // Filter out invalid tools on final attempt
207+ /**
208+ * Filter out invalid tools on final attempt
209+ */
203210 selectedToolNames = selectedToolNames . filter ( ( name ) =>
204211 validToolNames . includes ( name )
205212 ) ;
206213 break ;
207214 }
208- } catch ( error ) {
215+ } catch {
216+ /**
217+ * Fall back to using all tools
218+ */
209219 if ( attempts >= maxRetries ) {
210- console . warn ( "Tool selection failed, using all tools:" , error ) ;
211- return request ; // Fall back to using all tools
220+ return request ;
212221 }
213222 attempts ++ ;
214223 }
215224 }
216225
217- // Filter tools based on selection
226+ /**
227+ * Filter tools based on selection
228+ */
218229 const selectedTools = toolInfo
219230 . filter ( ( { name } ) => selectedToolNames . includes ( name ) )
220231 . map ( ( { name } ) => name ) ;
You can’t perform that action at this time.
0 commit comments