Class: Insika::Tools::ToolSearch
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Insika::Tools::ToolSearch
- Defined in:
- lib/insika/tools/tool_search.rb
Overview
Level 2 of TOOLS progressive disclosure (analog of LoadSkill):
searches the deferred catalog and PROMOTES the relevant ones into the live chat via
chat.with_tools (verified to propagate on the next round of the same ask
in ruby_llm 1.16). require "ruby_llm" stays in THIS file (it inherits from
RubyLLM::Tool) — it does not enter lib/insika.rb; the Executor loads it lazily in
configure_chat (like LoadSkill).
Instance Method Summary collapse
- #execute(query:) ⇒ Object
-
#initialize(catalog, deferred_allowed, chat, tool_registry:, event_stream:, checkpoint_store:, state:) ⇒ ToolSearch
constructor
A new instance of ToolSearch.
-
#name ⇒ Object
RubyLLM::Tool#name derives from self.class.name — for a nested class (Insika::Tools::ToolSearch) it produces "insika--tools--tool_search", not "tool_search".
Constructor Details
#initialize(catalog, deferred_allowed, chat, tool_registry:, event_stream:, checkpoint_store:, state:) ⇒ ToolSearch
Returns a new instance of ToolSearch.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/insika/tools/tool_search.rb', line 23 def initialize(catalog, deferred_allowed, chat, tool_registry:, event_stream:, checkpoint_store:, state:) @catalog = catalog @deferred_allowed = Array(deferred_allowed).map(&:to_s) @chat = chat @tool_registry = tool_registry @event_stream = event_stream @checkpoint_store = checkpoint_store @state = state @promoted = [] # names already promoted IN THIS chat — idempotency super() end |
Instance Method Details
#execute(query:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/insika/tools/tool_search.rb', line 36 def execute(query:) matches = @catalog.search(query, within: @deferred_allowed) emit_tool_search(query, matches.map(&:name)) if matches.empty? return { matched: [], message: "no tool found for '#{query}'" } end new_matches = matches.reject { |m| @promoted.include?(m.name) } promote(new_matches) unless new_matches.empty? { matched: matches.map { |m| describe(m) } } end |
#name ⇒ Object
RubyLLM::Tool#name derives from self.class.name — for a nested class (Insika::Tools::ToolSearch) it produces "insika--tools--tool_search", not "tool_search". Explicit override: the name the model calls must match the catalog/docs/tests.
21 |
# File 'lib/insika/tools/tool_search.rb', line 21 def name = "tool_search" |