Module: Phronomy::Agent::Concerns::Filterable Private

Included in:
Base
Defined in:
lib/phronomy/agent/concerns/filterable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Adds input, output, and tool-result filter support to an agent.

Filters transform (or block) values at three call sites:

  • input — the raw user input string, before the LLM is called
  • output — the final LLM output string, before it is returned
  • tool result — the return value of each tool call

Each filter in the chain receives the value returned by the previous one. A FilterBlockError raised inside any filter propagates to the caller.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/phronomy/agent/concerns/filterable.rb', line 19

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#add_input_filter(filter) ⇒ self

Registers an input filter on this instance. Accepts either a Filter::Base instance or a subclass; when a class is given it is instantiated with +.new+. Runs in addition to any class-level input filters.

Parameters:

Returns:

  • (self)


95
96
97
98
99
# File 'lib/phronomy/agent/concerns/filterable.rb', line 95

def add_input_filter(filter)
  @_instance_input_filters ||= []
  @_instance_input_filters << _resolve_filter(filter)
  self
end

#add_output_filter(filter) ⇒ self

Registers an output filter on this instance. Accepts either a Filter::Base instance or a subclass; when a class is given it is instantiated with +.new+. Runs in addition to any class-level output filters.

Parameters:

Returns:

  • (self)


108
109
110
111
112
# File 'lib/phronomy/agent/concerns/filterable.rb', line 108

def add_output_filter(filter)
  @_instance_output_filters ||= []
  @_instance_output_filters << _resolve_filter(filter)
  self
end

#add_tool_result_filter(filter) ⇒ self #add_tool_result_filter(tool_class, filter) ⇒ self

Registers a tool result filter on this instance.

When called with two arguments, the filter is scoped to the given tool class only. When called with one argument, it applies to all tools. Accepts either a Filter::Base instance or a subclass; when a class is given it is instantiated with +.new+.

Overloads:

Returns:

  • (self)


128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/phronomy/agent/concerns/filterable.rb', line 128

def add_tool_result_filter(tool_class_or_filter, filter = nil)
  if filter.nil?
    # Single-argument form: apply to all tools.
    @_instance_tool_result_filters ||= []
    @_instance_tool_result_filters << _resolve_filter(tool_class_or_filter)
  else
    # Two-argument form: scoped to one tool class.
    @_scoped_tool_result_filters ||= {}
    (@_scoped_tool_result_filters[tool_class_or_filter] ||= []) << _resolve_filter(filter)
  end
  self
end