Module: Phronomy::Agent::Concerns::BeforeCompletion::ClassMethods

Defined in:
lib/phronomy/agent/concerns/before_completion.rb

Overview

Class-level DSL methods mixed into the including agent class.

Instance Method Summary collapse

Instance Method Details

#_before_completion#call?

Returns:

  • (#call, nil)


38
39
40
# File 'lib/phronomy/agent/concerns/before_completion.rb', line 38

def _before_completion
  @before_completion
end

#before_completion(callable = nil) ⇒ #call?

Sets or reads the class-level before_completion hook. The hook is called before every LLM request for instances of this class. Receives a BeforeCompletionContext; must return a Hash of params to merge into the LLM call, or nil to pass through unchanged.

Examples:

class MyAgent < Phronomy::Agent::Base
  before_completion ->(ctx) { { temperature: 0.2 } }
end

Parameters:

  • callable (#call, nil) (defaults to: nil)

    lambda/proc to register, or nil to clear

Returns:

  • (#call, nil)


29
30
31
32
33
34
35
# File 'lib/phronomy/agent/concerns/before_completion.rb', line 29

def before_completion(callable = nil)
  if callable.nil? && !block_given?
    @before_completion
  else
    @before_completion = callable
  end
end