Commit Graph

1 Commits

Author SHA1 Message Date
mist
e249fa4557 Tools: match keyword hints on word boundaries
`get_tools_for_query` force-includes whole tool families when the query
mentions an intent keyword, but matched with a raw substring test
(`kw in ql`). Short hints therefore fired inside unrelated words, bloating
the tool set with irrelevant tools:

  - "fix" matched "prefix"      -> document tools
  - "line" matched "deadline"/"online" -> document tools
  - "serve" matched "observe"/"reserve" -> cookbook serve tools
  - "reply" matched "replying"  -> all email tools
  - "unread" matched "unreadable" -> all email tools

Match each keyword on word boundaries instead
(`re.search(rf"\b{re.escape(kw)}\b", ql)`), the same fix already applied to
the keyword matcher in topic_analyzer.py. Genuine intent keywords
("reply to this email", "edit the document", "serve the model") still match.

This only removes substring-inside-a-word matches; it does not change whole
-word matches (so e.g. an unrelated whole word like "tell" is a separate
keyword-choice question, left untouched here).

Checks: python -m pytest tests/test_tool_index_keyword_boundaries.py (4 passed;
3 of them fail on the pre-fix substring code), python -m py_compile
src/tool_index.py, git diff --check.
2026-06-02 20:32:20 +09:00