Module: LittleGhost::Agent::ToolLoop
- Included in:
- LittleGhost::Agent
- Defined in:
- lib/little_ghost/agent/tool_loop.rb
Overview
Stop an agent from repeating a tool call that cannot make progress. Detection follows identical tool names, arguments, result status, and result content within one invocation.
class CustomerSupportAgent < LittleGhost::Agent
detect_tool_loops warning_at: 3, terminate_at: 5,
except: AccountRefreshTool
end
If a support model makes the same ineffective lookup three times, its third result includes a warning to change approach. A fourth repeat carries the final warning, and a fifth stops the run with ToolLoopError.
Detection is inactive until detect_tool_loops is declared. Exclusions may
be tool classes, instances, names, or symbols. State is isolated per active
invocation and guarded for concurrent tool batches; unfinished subagent
waits do not count as repeated progress failures.
Only identical normalized arguments and results advance the counter. A changed result resets that sequence, while a terminating repeat prevents the duplicate tool body from running again.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- WARNING =
:nodoc:
"Repeated tool call detected. Change the approach or arguments before calling this tool again."- FINAL_WARNING =
:nodoc:
"Final repeated tool call warning. Calling this tool again with identical arguments and result will stop the run."- TRACKED_INVOCATION_LIMIT =
:nodoc:
1_000
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
34 35 36 37 |
# File 'lib/little_ghost/agent/tool_loop.rb', line 34 def self.included(base) # :nodoc: base.extend(ClassMethods) base.class_attribute :tool_loop_configuration_value end |