Class: Pikuri::Agent::Control::StepLimit
- Inherits:
-
Object
- Object
- Pikuri::Agent::Control::StepLimit
- Defined in:
- lib/pikuri/agent/control/step_limit.rb
Overview
Caps the number of tool calls per Pikuri::Agent#run_loop invocation. ruby_llm has no built-in step budget; the Agent pokes #tick! on every before_tool_call callback and #reset! at the start of each turn. Once the counter exceeds the configured cap, #tick! raises Exceeded, the Agent catches it, and the step- exhaustion synthesizer rescues to salvage a partial answer.
Defined Under Namespace
Classes: Exceeded
Instance Attribute Summary collapse
-
#max ⇒ Integer
readonly
The configured cap.
-
#step ⇒ Integer
readonly
Current step count; exposed so callers can introspect it (and so tests can assert it).
Instance Method Summary collapse
-
#for_sub_agent(max_steps: @max) ⇒ StepLimit
Sub-agent variant: a fresh
StepLimitat the caller-suppliedmax_steps:, or — when the key is absent — at the receiver’s own cap. -
#initialize(max:) ⇒ StepLimit
constructor
A new instance of StepLimit.
-
#reset! ⇒ void
Reset the counter back to zero.
- #tick! ⇒ void
-
#to_s ⇒ String
Short config dump for Pikuri::Agent#to_s.
Constructor Details
#initialize(max:) ⇒ StepLimit
Returns a new instance of StepLimit.
35 36 37 38 39 40 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 35 def initialize(max:) raise ArgumentError, "max must be positive, got #{max}" if max <= 0 @max = max @step = 0 end |
Instance Attribute Details
#max ⇒ Integer (readonly)
Returns the configured cap.
30 31 32 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 30 def max @max end |
#step ⇒ Integer (readonly)
Returns current step count; exposed so callers can introspect it (and so tests can assert it).
70 71 72 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 70 def step @step end |
Instance Method Details
#for_sub_agent(max_steps: @max) ⇒ StepLimit
Sub-agent variant: a fresh StepLimit at the caller-supplied max_steps:, or — when the key is absent — at the receiver’s own cap. The mutable counter is per-chat, so the parent’s instance cannot govern a sub-agent’s chat; every sub-agent needs its own.
82 83 84 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 82 def for_sub_agent(max_steps: @max) self.class.new(max: max_steps) end |
#reset! ⇒ void
This method returns an undefined value.
Reset the counter back to zero. Called by Pikuri::Agent at the start of each turn (in Pikuri::Agent#run_loop before forwarding the user message to the chat) so the same instance can govern many turns across a long-running REPL. Mid-loop Interloper injections deliberately do not trigger a reset — those are additional context for the same turn, not a fresh one, and a chatty user could otherwise refresh the budget forever by injecting.
64 65 66 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 64 def reset! @step = 0 end |
#tick! ⇒ void
This method returns an undefined value.
Increment the tool-call counter; raise Exceeded once it crosses #max. Called by Pikuri::Agent from its before_tool_call wiring.
49 50 51 52 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 49 def tick! @step += 1 raise Exceeded, @max if @step > @max end |
#to_s ⇒ String
Returns short config dump for Pikuri::Agent#to_s.
87 88 89 |
# File 'lib/pikuri/agent/control/step_limit.rb', line 87 def to_s "StepLimit(max=#{@max})" end |