Class: Legion::Extensions::Agentic::Self::RelationshipArc::Helpers::ArcEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::RelationshipArc::Helpers::ArcEngine
- Defined in:
- lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#current_chapter ⇒ Object
readonly
Returns the value of attribute current_chapter.
-
#milestones ⇒ Object
readonly
Returns the value of attribute milestones.
Instance Method Summary collapse
- #add_milestone(type:, description:, significance:) ⇒ Object
- #dirty? ⇒ Boolean
- #from_apollo(store:) ⇒ Object
-
#initialize(agent_id:) ⇒ ArcEngine
constructor
A new instance of ArcEngine.
- #mark_clean! ⇒ Object
- #relationship_health(attachment_strength: 0.0, reciprocity_balance: 0.5, communication_consistency: 0.5) ⇒ Object
- #to_apollo_entries ⇒ Object
- #to_h ⇒ Object
- #update_chapter!(bond_stage: :initial) ⇒ Object
Constructor Details
#initialize(agent_id:) ⇒ ArcEngine
Returns a new instance of ArcEngine.
15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 15 def initialize(agent_id:) @agent_id = agent_id @current_chapter = :formative @milestones = [] @dirty = false end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 10 def agent_id @agent_id end |
#current_chapter ⇒ Object (readonly)
Returns the value of attribute current_chapter.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 10 def current_chapter @current_chapter end |
#milestones ⇒ Object (readonly)
Returns the value of attribute milestones.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 10 def milestones @milestones end |
Instance Method Details
#add_milestone(type:, description:, significance:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 22 def add_milestone(type:, description:, significance:, **) ms = Milestone.new(type: type, description: description, significance: significance) @milestones << ms @milestones.shift while @milestones.size > Constants::MAX_MILESTONES @dirty = true ms end |
#dirty? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 47 def dirty? @dirty end |
#from_apollo(store:) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 62 def from_apollo(store:) result = store.query(text: 'relationship_arc', tags: Constants::TAG_PREFIX + [@agent_id]) return false unless result[:success] && result[:results]&.any? parsed = deserialize(result[:results].first[:content]) return false unless parsed @current_chapter = parsed[:current_chapter]&.to_sym || :formative @milestones = (parsed[:milestones] || []).map { |mh| Milestone.from_h(mh.transform_keys(&:to_sym)) } true rescue StandardError => e warn "[arc_engine] from_apollo error: #{e.}" false end |
#mark_clean! ⇒ Object
51 52 53 54 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 51 def mark_clean! @dirty = false self end |
#relationship_health(attachment_strength: 0.0, reciprocity_balance: 0.5, communication_consistency: 0.5) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 38 def relationship_health(attachment_strength: 0.0, reciprocity_balance: 0.5, communication_consistency: 0.5, **) w = Constants::HEALTH_WEIGHTS score = (.to_f * w[:attachment_strength]) + (reciprocity_balance.to_f * w[:reciprocity_balance]) + (communication_consistency.to_f * w[:communication_consistency]) @last_health = score.clamp(0.0, 1.0) end |
#to_apollo_entries ⇒ Object
56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 56 def to_apollo_entries = Constants::TAG_PREFIX.dup + [@agent_id] << 'partner' if partner?(@agent_id) [{ content: serialize(arc_state_hash), tags: }] end |
#to_h ⇒ Object
77 78 79 80 81 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 77 def to_h { agent_id: @agent_id, current_chapter: @current_chapter, milestones: @milestones.map(&:to_h), relationship_health: @last_health, milestone_count: @milestones.size } end |
#update_chapter!(bond_stage: :initial) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/self/relationship_arc/helpers/arc_engine.rb', line 30 def update_chapter!(bond_stage: :initial, **) new_chapter = derive_chapter(bond_stage) return if Constants::CHAPTERS.index(new_chapter) <= Constants::CHAPTERS.index(@current_chapter) @current_chapter = new_chapter @dirty = true end |