Class: RubynCode::Hooks::GoalHook
- Inherits:
-
Object
- Object
- RubynCode::Hooks::GoalHook
- Defined in:
- lib/rubyn_code/hooks/goal_hook.rb
Overview
A Stop hook that keeps the agent working until a session goal is met.
When active, firing the :stop event asks an evaluator whether the goal condition is satisfied. If it is, the hook deactivates itself (the goal “auto-clears”) and allows the agent to stop. If not, it returns a block decision whose reason is re-injected into the conversation, nudging the agent to keep working.
A max-attempts safety valve prevents an unsatisfiable goal from looping forever — after MAX_ATTEMPTS consecutive blocks the hook gives up and lets the agent stop.
Constant Summary collapse
- DEFAULT_MAX_ATTEMPTS =
12
Instance Attribute Summary collapse
-
#condition ⇒ String
readonly
The goal condition.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#call(conversation: nil, **_kwargs) ⇒ Hash?
Fired on the :stop event by Hooks::Runner.
-
#clear! ⇒ void
Cancel the goal early (e.g. ‘/goal clear`).
-
#initialize(condition:, evaluator: nil, max_attempts: DEFAULT_MAX_ATTEMPTS) ⇒ GoalHook
constructor
A new instance of GoalHook.
Constructor Details
#initialize(condition:, evaluator: nil, max_attempts: DEFAULT_MAX_ATTEMPTS) ⇒ GoalHook
Returns a new instance of GoalHook.
25 26 27 28 29 30 31 |
# File 'lib/rubyn_code/hooks/goal_hook.rb', line 25 def initialize(condition:, evaluator: nil, max_attempts: DEFAULT_MAX_ATTEMPTS) @condition = condition @evaluator = evaluator @max_attempts = max_attempts @attempts = 0 @active = true end |
Instance Attribute Details
#condition ⇒ String (readonly)
Returns the goal condition.
20 21 22 |
# File 'lib/rubyn_code/hooks/goal_hook.rb', line 20 def condition @condition end |
Instance Method Details
#active? ⇒ Boolean
34 |
# File 'lib/rubyn_code/hooks/goal_hook.rb', line 34 def active? = @active |
#call(conversation: nil, **_kwargs) ⇒ Hash?
Fired on the :stop event by Hooks::Runner.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubyn_code/hooks/goal_hook.rb', line 46 def call(conversation: nil, **_kwargs) return nil unless @active if goal_met?(conversation) @active = false return nil end @attempts += 1 if @attempts >= @max_attempts @active = false RubynCode::Debug.warn("Goal abandoned after #{@max_attempts} attempts: #{@condition}") return nil end { block: true, reason: reminder } end |
#clear! ⇒ void
This method returns an undefined value.
Cancel the goal early (e.g. ‘/goal clear`).
38 39 40 |
# File 'lib/rubyn_code/hooks/goal_hook.rb', line 38 def clear! @active = false end |