Class: Phronomy::Agent::BeforeCompletionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/agent/before_completion_context.rb

Overview

Passed to every before_completion hook callable. Provides read access to the agent, assembled messages, and invocation config. Hooks may inspect these and return a Hash of params to merge into the LLM request.

Examples:

Reading context inside a hook

Phronomy.configure do |cfg|
  cfg.before_completion = lambda do |ctx|
    Rails.logger.info "LLM request: model=#{ctx.params[:model]}"
    { temperature: 0.2 }
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent:, messages:, config:, params: {}) ⇒ BeforeCompletionContext

Returns a new instance of BeforeCompletionContext.

Parameters:

  • agent (Phronomy::Agent::Base)
  • messages (Array)
  • config (Hash)
  • params (Hash) (defaults to: {})

    initial params (model, temperature already set on chat)



38
39
40
41
42
43
# File 'lib/phronomy/agent/before_completion_context.rb', line 38

def initialize(agent:, messages:, config:, params: {})
  @agent = agent
  @messages = messages.dup.freeze
  @config = config
  @params = params.dup.freeze
end

Instance Attribute Details

#agentPhronomy::Agent::Base (readonly)

The agent instance making the LLM call.



19
20
21
# File 'lib/phronomy/agent/before_completion_context.rb', line 19

def agent
  @agent
end

#configHash (readonly)

Runtime config hash passed to invoke/stream (e.g. thread_id, memory).

Returns:

  • (Hash)


27
28
29
# File 'lib/phronomy/agent/before_completion_context.rb', line 27

def config
  @config
end

#messagesArray (readonly)

Messages currently assembled for this invocation (read-only snapshot).

Returns:

  • (Array)


23
24
25
# File 'lib/phronomy/agent/before_completion_context.rb', line 23

def messages
  @messages
end

#paramsHash (readonly)

Current LLM params being built (model, temperature, etc.). Read-only; return a Hash from the hook to merge overrides.

Returns:

  • (Hash)


32
33
34
# File 'lib/phronomy/agent/before_completion_context.rb', line 32

def params
  @params
end