Class: Rubino::Security::DoomLoopDetector
- Inherits:
-
Object
- Object
- Rubino::Security::DoomLoopDetector
- Defined in:
- lib/rubino/security/doom_loop_detector.rb
Overview
Detects when the agent enters a doom loop - repeatedly calling the same tool with identical arguments without progress.
Constant Summary collapse
- DEFAULT_THRESHOLD =
3
Instance Method Summary collapse
-
#initialize(threshold: DEFAULT_THRESHOLD) ⇒ DoomLoopDetector
constructor
A new instance of DoomLoopDetector.
-
#record(tool_name:, arguments:) ⇒ Object
Records a tool call and returns true if a doom loop is detected.
-
#reset! ⇒ Object
Resets the detector (e.g., when user provides new input).
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD) ⇒ DoomLoopDetector
Returns a new instance of DoomLoopDetector.
10 11 12 13 |
# File 'lib/rubino/security/doom_loop_detector.rb', line 10 def initialize(threshold: DEFAULT_THRESHOLD) @threshold = threshold @history = [] end |
Instance Method Details
#record(tool_name:, arguments:) ⇒ Object
Records a tool call and returns true if a doom loop is detected
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubino/security/doom_loop_detector.rb', line 16 def record(tool_name:, arguments:) signature = generate_signature(tool_name, arguments) @history << signature # Check if the last N calls are identical if @history.size >= @threshold recent = @history.last(@threshold) return true if recent.uniq.size == 1 end false end |
#reset! ⇒ Object
Resets the detector (e.g., when user provides new input)
30 31 32 |
# File 'lib/rubino/security/doom_loop_detector.rb', line 30 def reset! @history.clear end |