fix(core): return all tools when search_tools limit is 0

SO
2d ago
+104-4

Fixes an issue where calling search_tools(query, limit=0) returned an empty list [] instead of returning all matching tools without limit.

Problem

The ToolSearchStrategy interface specifies that limit=0 means "no limit / return all tools". However,TagAndDescriptionWordMatchStrategy used direct Python list slicing sorted_tools[:limit]. In Python, [:0] slices to an empty list [], causing queries with limit=0 to return zero results.

Solution

  • Updated TagAndDescriptionWordMatchStrategy.search_tools to return all tools when limit == 0: sorted_tools[:limit] if limit > 0 else sorted_tools
  • Updated docstrings in TagAndDescriptionWordMatchStrategy and UtcpClientImplementation to explicitly document limit: 0 for no limit.
  • Added unit tests in core/tests/implementations/test_tag_search.py verifying limit=0, limit > 0, limit < 0, scoring weights,and tag filtering.

Tests

  • 5 new unit tests in core/tests/implementations/test_tag_search.py (all passing).

Summary by cubic

Fixes search_tools(query, limit=0) so it returns all matching tools instead of an empty list, matching the ToolSearchStrategy contract where 0 means no limit.

  • TagAndDescriptionWordMatchStrategy no longer slices to an empty list when limit is 0.
  • Docstrings in TagAndDescriptionWordMatchStrategy and UtcpClientImplementation now document 0 as no limit.
  • Adds unit tests covering limit=0, positive limits, negative limits (raises error), scoring, and tag filtering.