Class: Phronomy::GeneratorVerifier
- Inherits:
-
Object
- Object
- Phronomy::GeneratorVerifier
- Defined in:
- lib/phronomy/generator_verifier.rb
Overview
Implements the Generator-Verifier multi-agent coordination pattern (Anthropic blog, Pattern 1): a generator agent produces an answer while a verifier agent evaluates its quality.
All prompt construction and result parsing are provided by the caller, giving full control over the LLM dialogue. The generator and verifier agents are configurable, and the pipeline retries until confidence passes the threshold or max iterations are reached.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- DEFAULT_CONFIDENCE_THRESHOLD =
Default confidence threshold for trusting an answer.
0.7- DEFAULT_MAX_ITERATIONS =
Default maximum draft-review cycles before returning best effort.
3
Instance Method Summary collapse
-
#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
constructor
A new instance of GeneratorVerifier.
-
#invoke(input, config: {}) ⇒ Result
Run the generator-verifier pipeline.
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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/phronomy/generator_verifier.rb', line 116 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_graph = nil end |
Instance Method Details
#invoke(input, config: {}) ⇒ Result
Run the generator-verifier pipeline.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/phronomy/generator_verifier.rb', line 146 def invoke(input, config: {}) app = compiled_graph state = app.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 ) raise LowConfidenceError.new(result) if @raise_if_untrusted && !trusted result end |