Class: Octo::Tools::Base
- Inherits:
-
Object
- Object
- Octo::Tools::Base
- Defined in:
- lib/octo/tools/base.rb
Direct Known Subclasses
Browser, Edit, FileReader, Glob, Grep, InvokeSkill, ListTasks, RedoTask, RequestUserFeedback, Terminal, TodoManager, TrashManager, UndoTask, WebFetch, WebSearch, Write
Class Attribute Summary collapse
-
.tool_category ⇒ Object
Returns the value of attribute tool_category.
-
.tool_description ⇒ Object
Returns the value of attribute tool_description.
-
.tool_name ⇒ Object
Returns the value of attribute tool_name.
-
.tool_parameters ⇒ Object
Returns the value of attribute tool_parameters.
Instance Method Summary collapse
- #category ⇒ Object
- #description ⇒ Object
-
#execute(**_args) ⇒ Object
Execute the tool - must be implemented by subclasses.
-
#format_call(args) ⇒ String
Format tool call for display - can be overridden by subclasses.
-
#format_result(result) ⇒ String
Format tool result for display - can be overridden by subclasses.
-
#format_result_for_ui(result) ⇒ Hash?
Format tool result as a structured hash for rich UI rendering.
- #name ⇒ Object
- #parameters ⇒ Object
-
#to_function_definition ⇒ Object
Convert to OpenAI function calling format.
Class Attribute Details
.tool_category ⇒ Object
Returns the value of attribute tool_category.
7 8 9 |
# File 'lib/octo/tools/base.rb', line 7 def tool_category @tool_category end |
.tool_description ⇒ Object
Returns the value of attribute tool_description.
7 8 9 |
# File 'lib/octo/tools/base.rb', line 7 def tool_description @tool_description end |
.tool_name ⇒ Object
Returns the value of attribute tool_name.
7 8 9 |
# File 'lib/octo/tools/base.rb', line 7 def tool_name @tool_name end |
.tool_parameters ⇒ Object
Returns the value of attribute tool_parameters.
7 8 9 |
# File 'lib/octo/tools/base.rb', line 7 def tool_parameters @tool_parameters end |
Instance Method Details
#category ⇒ Object
22 23 24 |
# File 'lib/octo/tools/base.rb', line 22 def category self.class.tool_category || "general" end |
#description ⇒ Object
14 15 16 |
# File 'lib/octo/tools/base.rb', line 14 def description self.class.tool_description end |
#execute(**_args) ⇒ Object
Execute the tool - must be implemented by subclasses
27 28 29 |
# File 'lib/octo/tools/base.rb', line 27 def execute(**_args) raise NotImplementedError, "#{self.class.name} must implement #execute" end |
#format_call(args) ⇒ String
Format tool call for display - can be overridden by subclasses
50 51 52 |
# File 'lib/octo/tools/base.rb', line 50 def format_call(args) "#{name}(...)" end |
#format_result(result) ⇒ String
Format tool result for display - can be overridden by subclasses
57 58 59 60 61 62 63 64 65 |
# File 'lib/octo/tools/base.rb', line 57 def format_result(result) if result.is_a?(Hash) && result[:message] result[:message] elsif result.is_a?(String) result.length > 100 ? "#{result[0..100]}..." : result else "Done" end end |
#format_result_for_ui(result) ⇒ Hash?
Format tool result as a structured hash for rich UI rendering. When a tool implements this, the WebUI can render a beautiful card instead of a plain text blob.
Supported types and their schemas:
{ type: "file_read", path:, lines_read:, total_lines:,
truncated:, content_preview:, language: }
{ type: "file_list", path:, entries:[{name, is_dir}], total }
{ type: "search", pattern:, path:, matches:[{file, line_no, line, context?}],
total_matches, files_with_matches, truncated }
{ type: "terminal", command:, exit_code:, output_preview:,
output_truncated:, full_output_file? }
{ type: "web_fetch", url:, title?, content_preview: }
{ type: "web_search", query:, results:[{title, url, snippet}] }
{ type: "edit", path:, operation:, occurrences: }
{ type: "write", path:, is_new_file:, size_bytes: }
{ type: "todo", action:, todos:[{id, task, status}] }
{ type: "browser", action:, url?, title?, content_preview? }
{ type: "generic", title:, content:, status: "ok|error|warning" }
101 102 103 |
# File 'lib/octo/tools/base.rb', line 101 def format_result_for_ui(result) nil end |
#name ⇒ Object
10 11 12 |
# File 'lib/octo/tools/base.rb', line 10 def name self.class.tool_name end |
#parameters ⇒ Object
18 19 20 |
# File 'lib/octo/tools/base.rb', line 18 def parameters self.class.tool_parameters end |
#to_function_definition ⇒ Object
Convert to OpenAI function calling format
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/octo/tools/base.rb', line 106 def to_function_definition { type: "function", function: { name: name, description: description, parameters: parameters } } end |