Module: Legion::Extensions::Agentic::Learning::Catalyst::Runners::CognitiveCatalyst
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb
Instance Method Summary collapse
- #apply_catalyst(catalyst_id:, reaction_id:, engine: nil) ⇒ Object
- #attempt_reaction(reaction_id:, energy_input:, engine: nil) ⇒ Object
- #catalyst_status(engine: nil) ⇒ Object
- #create_catalyst(catalyst_type:, domain:, potency: nil, specificity: nil, engine: nil) ⇒ Object
- #create_reaction(reaction_type:, reactants:, activation_energy: nil, engine: nil) ⇒ Object
- #list_catalysts(engine: nil) ⇒ Object
- #recharge(catalyst_id:, amount:, engine: nil) ⇒ Object
Instance Method Details
#apply_catalyst(catalyst_id:, reaction_id:, engine: nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 52 def apply_catalyst(catalyst_id:, reaction_id:, engine: nil, **) e = engine || default_engine result = e.apply_catalyst(catalyst_id: catalyst_id, reaction_id: reaction_id) log.debug '[cognitive_catalyst] apply_catalyst ' \ "catalyst=#{catalyst_id[0..7]} reaction=#{reaction_id[0..7]} " \ "success=#{result[:success]}" result end |
#attempt_reaction(reaction_id:, energy_input:, engine: nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 61 def attempt_reaction(reaction_id:, energy_input:, engine: nil, **) e = engine || default_engine result = e.attempt_reaction(reaction_id: reaction_id, energy_input: energy_input) log.debug "[cognitive_catalyst] attempt_reaction id=#{reaction_id[0..7]} " \ "energy=#{energy_input} completed=#{result[:completed]}" result end |
#catalyst_status(engine: nil) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 84 def catalyst_status(engine: nil, **) e = engine || default_engine report = e.catalyst_report log.debug "[cognitive_catalyst] catalyst_status total=#{report[:total_catalysts]} " \ "reactions=#{report[:total_reactions]} rate=#{report[:catalyzed_rate].round(2)}" { success: true }.merge(report) end |
#create_catalyst(catalyst_type:, domain:, potency: nil, specificity: nil, engine: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 13 def create_catalyst(catalyst_type:, domain:, potency: nil, specificity: nil, engine: nil, **) e = engine || default_engine raise ArgumentError, "invalid catalyst_type: #{catalyst_type}" unless Helpers::Constants::CATALYST_TYPES.include?(catalyst_type.to_sym) opts = { catalyst_type: catalyst_type.to_sym, domain: domain } opts[:potency] = potency unless potency.nil? opts[:specificity] = specificity unless specificity.nil? catalyst = e.create_catalyst(**opts) log.debug "[cognitive_catalyst] create_catalyst id=#{catalyst.id[0..7]} " \ "type=#{catalyst_type} domain=#{domain} potency=#{catalyst.potency.round(2)}" { success: true, catalyst: catalyst.to_h } rescue ArgumentError => e log.warn "[cognitive_catalyst] create_catalyst failed: #{e.}" { success: false, reason: e. } end |
#create_reaction(reaction_type:, reactants:, activation_energy: nil, engine: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 33 def create_reaction(reaction_type:, reactants:, activation_energy: nil, engine: nil, **) e = engine || default_engine raise ArgumentError, "invalid reaction_type: #{reaction_type}" unless Helpers::Constants::REACTION_TYPES.include?(reaction_type.to_sym) opts = { reaction_type: reaction_type.to_sym, reactants: Array(reactants) } opts[:activation_energy] = activation_energy unless activation_energy.nil? reaction = e.create_reaction(**opts) log.debug "[cognitive_catalyst] create_reaction id=#{reaction.id[0..7]} " \ "type=#{reaction_type} reactants=#{reaction.reactants.size}" { success: true, reaction: reaction.to_h } rescue ArgumentError => e log.warn "[cognitive_catalyst] create_reaction failed: #{e.}" { success: false, reason: e. } end |
#list_catalysts(engine: nil) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 77 def list_catalysts(engine: nil, **) e = engine || default_engine catalysts = e.all_catalysts log.debug "[cognitive_catalyst] list_catalysts count=#{catalysts.size}" { success: true, catalysts: catalysts.map(&:to_h), count: catalysts.size } end |
#recharge(catalyst_id:, amount:, engine: nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/agentic/learning/catalyst/runners/cognitive_catalyst.rb', line 69 def recharge(catalyst_id:, amount:, engine: nil, **) e = engine || default_engine result = e.recharge_catalyst(catalyst_id: catalyst_id, amount: amount) log.debug "[cognitive_catalyst] recharge id=#{catalyst_id[0..7]} " \ "amount=#{amount} potency=#{result[:potency]&.round(2)}" result end |