Class: Phronomy::GeneratorVerifier

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

Overview

Implements the Generator-Verifier multi-agent coordination pattern.

Agent completion is integrated through application-defined Workflow events; Workflow entry actions do not return or await Agent Tasks.

Defined Under Namespace

Classes: Result

Constant Summary collapse

DEFAULT_CONFIDENCE_THRESHOLD =
0.7
DEFAULT_MAX_ITERATIONS =
3

Instance Method Summary collapse

Constructor Details

#initialize(draft_agent:, review_agent:, draft_prompt_builder:, review_prompt_builder:, draft_result_parser: nil, review_result_parser: nil, confidence_threshold: DEFAULT_CONFIDENCE_THRESHOLD, max_iterations: DEFAULT_MAX_ITERATIONS, raise_if_untrusted: false) ⇒ GeneratorVerifier

Returns a new instance of GeneratorVerifier.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/phronomy/generator_verifier.rb', line 79

def initialize(
  draft_agent:,
  review_agent:,
  draft_prompt_builder:,
  review_prompt_builder:,
  draft_result_parser: nil,
  review_result_parser: nil,
  confidence_threshold: DEFAULT_CONFIDENCE_THRESHOLD,
  max_iterations: DEFAULT_MAX_ITERATIONS,
  raise_if_untrusted: false
)
  @draft_agent_class = draft_agent
  @review_agent_class = review_agent
  @draft_prompt_builder = draft_prompt_builder
  @review_prompt_builder = review_prompt_builder
  @draft_result_parser =
    draft_result_parser || method(:default_parse_draft)
  @review_result_parser =
    review_result_parser || method(:default_parse_review)
  @threshold = confidence_threshold.to_f
  @max_iterations = max_iterations.to_i
  @raise_if_untrusted = raise_if_untrusted
  @compiled_workflow = nil
end

Instance Method Details

#invoke(input, config: {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/phronomy/generator_verifier.rb', line 104

def invoke(input, config: {})
  state = compiled_workflow.invoke({input: input}, config: config)
  confidence = combined_confidence(state)
  trusted = confidence >= @threshold
  result = Result.new(
    output: state.output || state.draft.to_s,
    confidence: confidence,
    citations: state.citations,
    iterations: state.iteration,
    review_notes: state.review_notes,
    trusted: trusted
  )
  if @raise_if_untrusted && !trusted
    raise LowConfidenceError.new(result)
  end
  result
end