module LittleGhost::Agent::ToolLoop::ClassMethods
Exposes tool-loop detection declarations on agent classes. These methods become inheritable DSL entries when the capability is included.
Public Instance Methods
# 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
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.