Module: Legion::Extensions::Agentic::Inference::Debugging::Runners::CognitiveDebugging
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb
Instance Method Summary collapse
- #active_errors ⇒ Object
- #apply_correction(correction_id:) ⇒ Object
- #correction_success_rate ⇒ Object
- #debugging_report ⇒ Object
- #detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection: 0.5) ⇒ Object
- #errors_by_phase ⇒ Object
- #errors_by_type ⇒ Object
- #measure_correction(correction_id:, effectiveness:) ⇒ Object
- #most_common_error_type ⇒ Object
- #most_effective_strategy ⇒ Object
- #propose_correction(error_id:, strategy:, description:) ⇒ Object
- #resolve_error(error_id:) ⇒ Object
- #resolved_errors ⇒ Object
- #snapshot ⇒ Object
- #trace_error(error_id:, steps:, root_cause:, confidence: 0.5) ⇒ Object
Instance Method Details
#active_errors ⇒ Object
111 112 113 114 115 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 111 def active_errors(**) errors = engine.active_errors log.debug "[cognitive_debugging] active_errors: count=#{errors.size}" { success: true, errors: errors.map(&:to_h), count: errors.size } end |
#apply_correction(correction_id:) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 73 def apply_correction(correction_id:, **) correction = engine.apply_correction(correction_id: correction_id) if correction log.info "[cognitive_debugging] correction applied: id=#{correction_id[0..7]}" { success: true, correction_id: correction_id, applied: true } else log.debug "[cognitive_debugging] apply_correction: id=#{correction_id[0..7]} not found" { success: false, error: :not_found } end end |
#correction_success_rate ⇒ Object
147 148 149 150 151 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 147 def correction_success_rate(**) rate = engine.correction_success_rate log.debug "[cognitive_debugging] correction_success_rate: rate=#{rate}" { success: true, rate: rate } end |
#debugging_report ⇒ Object
153 154 155 156 157 158 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 153 def debugging_report(**) report = engine.debugging_report log.info "[cognitive_debugging] debugging_report: total_errors=#{report[:total_errors]} " \ "active=#{report[:active_errors]}" { success: true, report: report } end |
#detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection: 0.5) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 13 def detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection: 0.5, **) unless Helpers::Constants::ERROR_TYPES.include?(error_type) log.debug "[cognitive_debugging] detect_error: invalid error_type=#{error_type}" return { success: false, error: :invalid_error_type, valid: Helpers::Constants::ERROR_TYPES } end err = engine.detect_error( error_type: error_type, description: description, severity: severity, source_phase: source_phase, confidence_at_detection: confidence_at_detection ) if err log.info "[cognitive_debugging] error detected: id=#{err.id[0..7]} type=#{error_type} " \ "phase=#{source_phase} severity=#{err.severity_label}" { success: true, error_id: err.id, error_type: error_type, severity_label: err.severity_label } else log.warn '[cognitive_debugging] detect_error: engine returned nil (cap reached?)' { success: false, error: :cap_reached } end end |
#errors_by_phase ⇒ Object
129 130 131 132 133 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 129 def errors_by_phase(**) tally = engine.errors_by_phase log.debug "[cognitive_debugging] errors_by_phase: phases=#{tally.keys.join(',')}" { success: true, tally: tally } end |
#errors_by_type ⇒ Object
123 124 125 126 127 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 123 def errors_by_type(**) tally = engine.errors_by_type log.debug "[cognitive_debugging] errors_by_type: types=#{tally.keys.join(',')}" { success: true, tally: tally } end |
#measure_correction(correction_id:, effectiveness:) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 85 def measure_correction(correction_id:, effectiveness:, **) correction = engine.measure_correction(correction_id: correction_id, effectiveness: effectiveness) if correction log.info "[cognitive_debugging] correction measured: id=#{correction_id[0..7]} " \ "effectiveness=#{correction.effectiveness} effective=#{correction.effective?}" { success: true, correction_id: correction_id, effectiveness: correction.effectiveness, effective: correction.effective? } else log.debug "[cognitive_debugging] measure_correction: id=#{correction_id[0..7]} not found" { success: false, error: :not_found } end end |
#most_common_error_type ⇒ Object
135 136 137 138 139 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 135 def most_common_error_type(**) type = engine.most_common_error_type log.debug "[cognitive_debugging] most_common_error_type: type=#{type}" { success: true, error_type: type } end |
#most_effective_strategy ⇒ Object
141 142 143 144 145 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 141 def most_effective_strategy(**) strategy = engine.most_effective_strategy log.debug "[cognitive_debugging] most_effective_strategy: strategy=#{strategy}" { success: true, strategy: strategy } end |
#propose_correction(error_id:, strategy:, description:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 55 def propose_correction(error_id:, strategy:, description:, **) unless Helpers::Constants::CORRECTION_STRATEGIES.include?(strategy) log.debug "[cognitive_debugging] propose_correction: invalid strategy=#{strategy}" return { success: false, error: :invalid_strategy, valid: Helpers::Constants::CORRECTION_STRATEGIES } end correction = engine.propose_correction(error_id: error_id, strategy: strategy, description: description) if correction log.info "[cognitive_debugging] correction proposed: error_id=#{error_id[0..7]} " \ "correction_id=#{correction.id[0..7]} strategy=#{strategy}" { success: true, correction_id: correction.id, strategy: strategy } else log.debug "[cognitive_debugging] propose_correction: error_id=#{error_id[0..7]} not found" { success: false, error: :not_found } end end |
#resolve_error(error_id:) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 99 def resolve_error(error_id:, **) err = engine.resolve_error(error_id: error_id) if err log.info "[cognitive_debugging] error resolved: id=#{error_id[0..7]}" { success: true, error_id: error_id, resolved: true } else log.debug "[cognitive_debugging] resolve_error: id=#{error_id[0..7]} not found" { success: false, error: :not_found } end end |
#resolved_errors ⇒ Object
117 118 119 120 121 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 117 def resolved_errors(**) errors = engine.resolved_errors log.debug "[cognitive_debugging] resolved_errors: count=#{errors.size}" { success: true, errors: errors.map(&:to_h), count: errors.size } end |
#snapshot ⇒ Object
160 161 162 163 164 165 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 160 def snapshot(**) data = engine.to_h log.debug "[cognitive_debugging] snapshot: errors=#{data[:errors].size} " \ "traces=#{data[:traces].size} corrections=#{data[:corrections].size}" { success: true, snapshot: data } end |
#trace_error(error_id:, steps:, root_cause:, confidence: 0.5) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb', line 37 def trace_error(error_id:, steps:, root_cause:, confidence: 0.5, **) trace = engine.trace_error( error_id: error_id, steps: steps, root_cause: root_cause, confidence: confidence ) if trace log.info "[cognitive_debugging] error traced: error_id=#{error_id[0..7]} " \ "trace_id=#{trace.id[0..7]} depth=#{trace.depth} root_cause=#{root_cause}" { success: true, trace_id: trace.id, depth: trace.depth, root_cause: root_cause } else log.debug "[cognitive_debugging] trace_error: error_id=#{error_id[0..7]} not found or cap" { success: false, error: :not_found_or_cap } end end |