@@ -306,7 +306,7 @@ def search_tools(
306306 query : str ,
307307 * ,
308308 connector : str | None = None ,
309- top_k : int = 10 ,
309+ top_k : int | None = None ,
310310 min_score : float = 0.0 ,
311311 account_ids : list [str ] | None = None ,
312312 fallback_to_local : bool = True ,
@@ -321,7 +321,7 @@ def search_tools(
321321 query: Natural language description of needed functionality
322322 (e.g., "create employee", "send a message")
323323 connector: Optional provider/connector filter (e.g., "bamboohr", "slack")
324- top_k: Maximum number of tools to return (default: 10)
324+ top_k: Maximum number of tools to return. If None, uses the backend default.
325325 min_score: Minimum similarity score threshold 0-1 (default: 0.0)
326326 account_ids: Optional account IDs (uses set_accounts() if not provided)
327327 fallback_to_local: If True, fall back to local BM25+TF-IDF search on API failure
@@ -372,11 +372,11 @@ def search_tools(
372372 ]
373373
374374 # Step 3b: If not enough results, make per-connector calls for missing connectors
375- if len (filtered_results ) < top_k and not connector :
375+ if not connector and ( top_k is None or len (filtered_results ) < top_k ) :
376376 found_connectors = {r .connector_key .lower () for r in filtered_results }
377377 missing_connectors = available_connectors - found_connectors
378378 for missing in missing_connectors :
379- if len (filtered_results ) >= top_k :
379+ if top_k is not None and len (filtered_results ) >= top_k :
380380 break
381381 try :
382382 extra = self .semantic_client .search (query = query , connector = missing , top_k = top_k )
@@ -385,7 +385,7 @@ def search_tools(
385385 fr .action_name for fr in filtered_results
386386 }:
387387 filtered_results .append (r )
388- if len (filtered_results ) >= top_k :
388+ if top_k is not None and len (filtered_results ) >= top_k :
389389 break
390390 except SemanticSearchError :
391391 continue
@@ -401,7 +401,7 @@ def search_tools(
401401 if norm not in seen_names :
402402 seen_names .add (norm )
403403 deduped .append (r )
404- filtered_results = deduped [:top_k ]
404+ filtered_results = deduped [:top_k ] if top_k is not None else deduped
405405
406406 if not filtered_results :
407407 return Tools ([])
@@ -425,10 +425,11 @@ def search_tools(
425425 search_tool = utility .get_tool ("tool_search" )
426426
427427 if search_tool :
428+ fallback_limit = top_k * 3 if top_k is not None else 100
428429 result = search_tool .execute (
429430 {
430431 "query" : query ,
431- "limit" : top_k * 3 , # Over-fetch to account for connector filtering
432+ "limit" : fallback_limit ,
432433 "minScore" : min_score ,
433434 }
434435 )
@@ -441,7 +442,7 @@ def search_tools(
441442 for name in matched_names
442443 if name in tool_map and name .split ("_" )[0 ].lower () in filter_connectors
443444 ]
444- return Tools (matched_tools [:top_k ])
445+ return Tools (matched_tools [:top_k ] if top_k is not None else matched_tools )
445446
446447 return all_tools
447448
@@ -451,7 +452,7 @@ def search_action_names(
451452 * ,
452453 connector : str | None = None ,
453454 account_ids : list [str ] | None = None ,
454- top_k : int = 10 ,
455+ top_k : int | None = None ,
455456 min_score : float = 0.0 ,
456457 ) -> list [SemanticSearchResult ]:
457458 """Search for action names without fetching tools.
@@ -465,15 +466,15 @@ def search_action_names(
465466 account_ids: Optional account IDs to scope results to connectors
466467 available in those accounts (uses set_accounts() if not provided).
467468 When provided, results are filtered to only matching connectors.
468- top_k: Maximum number of results (default: 10)
469+ top_k: Maximum number of results. If None, uses the backend default.
469470 min_score: Minimum similarity score threshold 0-1 (default: 0.0)
470471
471472 Returns:
472473 List of SemanticSearchResult with action names, scores, and metadata
473474
474475 Examples:
475476 # Lightweight: inspect results before fetching
476- results = toolset.search_action_names("manage employees", top_k=10 )
477+ results = toolset.search_action_names("manage employees")
477478 for r in results:
478479 print(f"{r.action_name}: {r.similarity_score:.2f}")
479480
@@ -501,7 +502,7 @@ def search_action_names(
501502 response = self .semantic_client .search (
502503 query = query ,
503504 connector = connector ,
504- top_k = None if available_connectors else top_k ,
505+ top_k = top_k ,
505506 )
506507 except SemanticSearchError as e :
507508 logger .warning ("Semantic search failed: %s" , e )
@@ -516,11 +517,11 @@ def search_action_names(
516517 results = [r for r in results if r .connector_key .lower () in connector_set ]
517518
518519 # If not enough results, make per-connector calls for missing connectors
519- if len (results ) < top_k and not connector :
520+ if not connector and ( top_k is None or len (results ) < top_k ) :
520521 found_connectors = {r .connector_key .lower () for r in results }
521522 missing_connectors = connector_set - found_connectors
522523 for missing in missing_connectors :
523- if len (results ) >= top_k :
524+ if top_k is not None and len (results ) >= top_k :
524525 break
525526 try :
526527 extra = self .semantic_client .search (query = query , connector = missing , top_k = top_k )
@@ -529,7 +530,7 @@ def search_action_names(
529530 er .action_name for er in results
530531 }:
531532 results .append (r )
532- if len (results ) >= top_k :
533+ if top_k is not None and len (results ) >= top_k :
533534 break
534535 except SemanticSearchError :
535536 continue
@@ -553,7 +554,7 @@ def search_action_names(
553554 description = r .description ,
554555 )
555556 )
556- return normalized [:top_k ]
557+ return normalized [:top_k ] if top_k is not None else normalized
557558
558559 def _filter_by_provider (self , tool_name : str , providers : list [str ]) -> bool :
559560 """Check if a tool name matches any of the provider filters
0 commit comments