Module: LittleGhost::Agent::ToolLoop::ClassMethods
- Defined in:
- lib/little_ghost/agent/tool_loop.rb
Overview
Exposes tool-loop detection declarations on agent classes. These methods become inheritable DSL entries when the capability is included.
Instance Method Summary collapse
-
#detect_tool_loops(warning_at: 3, terminate_at: 5, except: []) ⇒ Object
Enables repeated tool-call detection.
-
#tool_loop_configuration ⇒ Object
:nodoc:.
Instance Method Details
#detect_tool_loops(warning_at: 3, terminate_at: 5, except: []) ⇒ Object
Enables repeated tool-call detection.
warning_at defaults to 3 identical calls and terminate_at defaults
to 5. except accepts tool classes, instances, names, or symbols.
Raises ArgumentError unless warning_at is at least 2 and
terminate_at is greater than warning_at.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/little_ghost/agent/tool_loop.rb', line 49 def detect_tool_loops(warning_at: 3, terminate_at: 5, except: []) warning_at = Integer(warning_at) terminate_at = Integer(terminate_at) raise ArgumentError, "warning_at must be at least 2" if warning_at < 2 raise ArgumentError, "terminate_at must be greater than warning_at" if terminate_at <= warning_at self.tool_loop_configuration_value = { warning_at:, terminate_at:, except: Array(except).map { |tool| tool_name(tool) } } after_initialize :initialize_tool_loop before_invocation :reset_tool_loop after_invocation :clear_tool_loop before_model :check_for_terminated_tool_loop before_tool :track_tool_call after_tool :detect_repeated_tool_call, prepend: true end |
#tool_loop_configuration ⇒ Object
:nodoc:
68 |
# File 'lib/little_ghost/agent/tool_loop.rb', line 68 def tool_loop_configuration = tool_loop_configuration_value # :nodoc: |