Class: DecisionAgent::Decision
- Inherits:
-
Object
- Object
- DecisionAgent::Decision
- Defined in:
- lib/decision_agent/decision.rb
Overview
Result of Agent#decide: the chosen decision, confidence, explanations, and audit data.
Instance Attribute Summary collapse
-
#audit_payload ⇒ Object
readonly
Returns the value of attribute audit_payload.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#decision ⇒ Object
readonly
Returns the value of attribute decision.
-
#evaluations ⇒ Object
readonly
Returns the value of attribute evaluations.
-
#explanations ⇒ Object
readonly
Returns the value of attribute explanations.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if other is a Decision with same decision, confidence, explanations, evaluations.
-
#because(verbose: false) ⇒ Array<String>
Returns array of condition descriptions that led to this decision.
-
#explainability(verbose: false) ⇒ Hash
Returns explainability data in machine-readable format.
-
#failed_conditions(verbose: false) ⇒ Array<String>
Returns array of condition descriptions that failed.
-
#initialize(decision:, confidence:, explanations:, evaluations:, audit_payload:) ⇒ Decision
constructor
A new instance of Decision.
-
#to_h ⇒ Hash
Returns the decision as a hash (explainability-shaped plus confidence, evaluations, audit).
Constructor Details
#initialize(decision:, confidence:, explanations:, evaluations:, audit_payload:) ⇒ Decision
Returns a new instance of Decision.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/decision_agent/decision.rb', line 8 def initialize(decision:, confidence:, explanations:, evaluations:, audit_payload:) validate_confidence!(confidence) @decision = decision.to_s.freeze @confidence = confidence.to_f @explanations = Array(explanations).map(&:freeze).freeze @evaluations = Array(evaluations).freeze @audit_payload = deep_freeze(audit_payload) freeze end |
Instance Attribute Details
#audit_payload ⇒ Object (readonly)
Returns the value of attribute audit_payload.
6 7 8 |
# File 'lib/decision_agent/decision.rb', line 6 def audit_payload @audit_payload end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
6 7 8 |
# File 'lib/decision_agent/decision.rb', line 6 def confidence @confidence end |
#decision ⇒ Object (readonly)
Returns the value of attribute decision.
6 7 8 |
# File 'lib/decision_agent/decision.rb', line 6 def decision @decision end |
#evaluations ⇒ Object (readonly)
Returns the value of attribute evaluations.
6 7 8 |
# File 'lib/decision_agent/decision.rb', line 6 def evaluations @evaluations end |
#explanations ⇒ Object (readonly)
Returns the value of attribute explanations.
6 7 8 |
# File 'lib/decision_agent/decision.rb', line 6 def explanations @explanations end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other is a Decision with same decision, confidence, explanations, evaluations.
136 137 138 139 140 141 142 |
# File 'lib/decision_agent/decision.rb', line 136 def ==(other) other.is_a?(Decision) && @decision == other.decision && (@confidence - other.confidence).abs < 0.0001 && @explanations == other.explanations && @evaluations == other.evaluations end |
#because(verbose: false) ⇒ Array<String>
Returns array of condition descriptions that led to this decision
23 24 25 |
# File 'lib/decision_agent/decision.rb', line 23 def because(verbose: false) all_explainability_results.flat_map { |er| er.because(verbose: verbose) } end |
#explainability(verbose: false) ⇒ Hash
Returns explainability data in machine-readable format
37 38 39 40 41 42 43 44 |
# File 'lib/decision_agent/decision.rb', line 37 def explainability(verbose: false) { decision: @decision, because: because(verbose: verbose), failed_conditions: failed_conditions(verbose: verbose), rule_traces: verbose ? all_explainability_results.map { |er| er.to_h(verbose: true) } : nil }.compact end |
#failed_conditions(verbose: false) ⇒ Array<String>
Returns array of condition descriptions that failed
30 31 32 |
# File 'lib/decision_agent/decision.rb', line 30 def failed_conditions(verbose: false) all_explainability_results.flat_map { |er| er.failed_conditions(verbose: verbose) } end |
#to_h ⇒ Hash
Returns the decision as a hash (explainability-shaped plus confidence, evaluations, audit).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/decision_agent/decision.rb', line 50 def to_h # Structure decision result as explainability by default # This makes explainability the primary format for decision results explainability_data = explainability(verbose: false) { # Explainability fields (primary structure) decision: explainability_data[:decision], because: explainability_data[:because], failed_conditions: explainability_data[:failed_conditions], # Additional metadata for completeness confidence: @confidence, explanations: @explanations, evaluations: @evaluations.map(&:to_h), audit_payload: @audit_payload, # Full explainability data (includes rule_traces in verbose mode) explainability: explainability_data } end |