Class: HTM::Models::Robot
- Inherits:
-
Object
- Object
- HTM::Models::Robot
- Defined in:
- lib/htm/models/robot.rb
Overview
Robot model - represents an LLM agent using the HTM system
Robots can share memories through the many-to-many relationship with nodes. When a robot is deleted, only the robot_nodes links are removed; shared nodes remain in the database for other robots.
Class Method Summary collapse
-
.find_or_create_by_name(robot_name) ⇒ Robot
Find or create a robot by name.
Instance Method Summary collapse
-
#before_create ⇒ Object
Hooks.
-
#memory_summary ⇒ Hash
Get a summary of this robot’s memory state.
-
#node_count ⇒ Integer
Get the total number of nodes associated with this robot.
-
#nodes_with_metadata(limit = 10) ⇒ Array<Hash>
Get nodes with their remember metadata for this robot.
-
#recent_nodes(limit = 10) ⇒ Array<Node>
Get the most recent nodes for this robot.
-
#validate ⇒ Object
Validations.
Class Method Details
.find_or_create_by_name(robot_name) ⇒ Robot
Find or create a robot by name
52 53 54 |
# File 'lib/htm/models/robot.rb', line 52 def self.find_or_create_by_name(robot_name) find_or_create(name: robot_name) end |
Instance Method Details
#before_create ⇒ Object
Hooks
40 41 42 43 |
# File 'lib/htm/models/robot.rb', line 40 def before_create self.created_at ||= Time.now super end |
#memory_summary ⇒ Hash
Get a summary of this robot’s memory state
103 104 105 106 107 108 109 |
# File 'lib/htm/models/robot.rb', line 103 def memory_summary { total_nodes: nodes_dataset.count, in_working_memory: robot_nodes_dataset.where(working_memory: true).count, with_embeddings: nodes_dataset.exclude(embedding: nil).count } end |
#node_count ⇒ Integer
Get the total number of nodes associated with this robot
62 63 64 |
# File 'lib/htm/models/robot.rb', line 62 def node_count nodes_dataset.count end |
#nodes_with_metadata(limit = 10) ⇒ Array<Hash>
Get nodes with their remember metadata for this robot
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/htm/models/robot.rb', line 80 def (limit = 10) robot_nodes_dataset .eager(:node) .order(Sequel.desc(:last_remembered_at)) .limit(limit) .all .map do |rn| { node: rn.node, remember_count: rn.remember_count, first_remembered_at: rn.first_remembered_at, last_remembered_at: rn.last_remembered_at } end end |
#recent_nodes(limit = 10) ⇒ Array<Node>
Get the most recent nodes for this robot
71 72 73 |
# File 'lib/htm/models/robot.rb', line 71 def recent_nodes(limit = 10) nodes_dataset.order(Sequel.desc(:created_at)).limit(limit).all end |
#validate ⇒ Object
Validations
23 24 25 26 |
# File 'lib/htm/models/robot.rb', line 23 def validate super validates_presence :name end |