Class: ToolDecorator
- Inherits:
-
Object
- Object
- ToolDecorator
- Defined in:
- app/decorators/tool_decorator.rb
Overview
Base class for server-side tool response decoration. Transforms raw tool results into LLM-optimized formats before they enter the event stream.
This is a separate decorator type from EventDecorator: EventDecorator formats events for clients (TUI/web), while ToolDecorator formats tool responses for the LLM. They sit at different points in the pipeline:
Tool executes → ToolDecorator transforms → event stream → EventDecorator renders
Subclasses implement #call to transform a tool’s raw result into an LLM-friendly string. Each tool can have its own ToolDecorator subclass (e.g. WebGetToolDecorator) registered in DECORATOR_MAP.
Direct Known Subclasses
Constant Summary collapse
- DECORATOR_MAP =
{ "web_get" => "WebGetToolDecorator" }.freeze
Class Method Summary collapse
-
.call(tool_name, result) ⇒ String, Hash
Factory: dispatches to the tool-specific decorator or passes through.
Instance Method Summary collapse
-
#call(result) ⇒ String
Subclasses override to transform the raw tool result.
Class Method Details
.call(tool_name, result) ⇒ String, Hash
Factory: dispatches to the tool-specific decorator or passes through.
29 30 31 32 33 34 35 36 |
# File 'app/decorators/tool_decorator.rb', line 29 def self.call(tool_name, result) return result if result.is_a?(Hash) && result.key?(:error) klass_name = DECORATOR_MAP[tool_name] return result unless klass_name klass_name.constantize.new.call(result) end |
Instance Method Details
#call(result) ⇒ String
Subclasses override to transform the raw tool result.
42 43 44 |
# File 'app/decorators/tool_decorator.rb', line 42 def call(result) raise NotImplementedError, "#{self.class} must implement #call" end |