Class: Kward::ToolRegistry
- Inherits:
-
Object
- Object
- Kward::ToolRegistry
- Defined in:
- lib/kward/tools/registry.rb
Overview
Exposes local workspace, search, skill, and interaction tools to the model and dispatches approved tool calls into the active conversation.
Instance Attribute Summary collapse
-
#schemas ⇒ Array<Hash>
readonly
Tool schemas advertised to the model for the current frontend and config.
Instance Method Summary collapse
-
#dispatch(tool_call, conversation, cancellation: nil) ⇒ String
Executes a model-requested tool call and appends the result to the conversation transcript.
-
#initialize(workspace: Workspace.new, prompt: nil, web_search: WebSearch.new, code_search: CodeSearch.new, web_search_enabled: nil, skills: nil, ask_user_question_enabled: nil) ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
Constructor Details
#initialize(workspace: Workspace.new, prompt: nil, web_search: WebSearch.new, code_search: CodeSearch.new, web_search_enabled: nil, skills: nil, ask_user_question_enabled: nil) ⇒ ToolRegistry
Returns a new instance of ToolRegistry.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kward/tools/registry.rb', line 25 def initialize(workspace: Workspace.new, prompt: nil, web_search: WebSearch.new, code_search: CodeSearch.new, web_search_enabled: nil, skills: nil, ask_user_question_enabled: nil) @workspace = workspace @prompt = prompt @web_search = web_search @code_search = code_search @skills = skills @web_search_enabled = web_search_enabled @ask_user_question_enabled = ask_user_question_enabled @tools = build_tools.freeze @schemas = build_schema_tools.map(&:schema).freeze end |
Instance Attribute Details
#schemas ⇒ Array<Hash> (readonly)
Tool schemas advertised to the model for the current frontend and config.
23 24 25 |
# File 'lib/kward/tools/registry.rb', line 23 def schemas @schemas end |
Instance Method Details
#dispatch(tool_call, conversation, cancellation: nil) ⇒ String
Executes a model-requested tool call and appends the result to the conversation transcript.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kward/tools/registry.rb', line 43 def dispatch(tool_call, conversation, cancellation: nil) cancellation&.raise_if_cancelled! name = ToolCall.name(tool_call) args = ToolCall.arguments(tool_call) tool = @tools[name] content = if tool tool.call(args, conversation, cancellation: cancellation) else "Unknown tool: #{name}" end conversation.append_tool( tool_call_id: tool_call["id"] || tool_call[:id], name: name, content: content ) conversation.append_tool_execution(tool_call: tool_call, content: content) content end |