htm 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +269 -79
- data/db/migrate/00003_create_file_sources.rb +5 -0
- data/db/migrate/00004_create_nodes.rb +17 -0
- data/db/migrate/00005_create_tags.rb +7 -0
- data/db/migrate/00006_create_node_tags.rb +2 -0
- data/db/migrate/00007_create_robot_nodes.rb +7 -0
- data/db/schema.sql +41 -29
- data/docs/api/yard/HTM/Configuration.md +54 -0
- data/docs/api/yard/HTM/Database.md +13 -10
- data/docs/api/yard/HTM/EmbeddingService.md +5 -1
- data/docs/api/yard/HTM/LongTermMemory.md +18 -277
- data/docs/api/yard/HTM/PropositionError.md +18 -0
- data/docs/api/yard/HTM/PropositionService.md +66 -0
- data/docs/api/yard/HTM/QueryCache.md +88 -0
- data/docs/api/yard/HTM/RobotGroup.md +481 -0
- data/docs/api/yard/HTM/SqlBuilder.md +108 -0
- data/docs/api/yard/HTM/TagService.md +4 -0
- data/docs/api/yard/HTM/Telemetry/NullInstrument.md +13 -0
- data/docs/api/yard/HTM/Telemetry/NullMeter.md +15 -0
- data/docs/api/yard/HTM/Telemetry.md +109 -0
- data/docs/api/yard/HTM/WorkingMemoryChannel.md +176 -0
- data/docs/api/yard/HTM.md +11 -23
- data/docs/api/yard/index.csv +102 -25
- data/docs/api/yard-reference.md +8 -0
- data/docs/assets/images/multi-provider-failover.svg +51 -0
- data/docs/assets/images/robot-group-architecture.svg +65 -0
- data/docs/database/README.md +3 -3
- data/docs/database/public.file_sources.svg +29 -21
- data/docs/database/public.node_tags.md +2 -0
- data/docs/database/public.node_tags.svg +53 -41
- data/docs/database/public.nodes.md +2 -0
- data/docs/database/public.nodes.svg +52 -40
- data/docs/database/public.robot_nodes.md +2 -0
- data/docs/database/public.robot_nodes.svg +30 -22
- data/docs/database/public.robots.svg +16 -12
- data/docs/database/public.tags.md +3 -0
- data/docs/database/public.tags.svg +41 -33
- data/docs/database/schema.json +66 -0
- data/docs/database/schema.svg +60 -48
- data/docs/development/index.md +13 -0
- data/docs/development/rake-tasks.md +1068 -0
- data/docs/getting-started/quick-start.md +144 -155
- data/docs/guides/adding-memories.md +2 -3
- data/docs/guides/context-assembly.md +185 -184
- data/docs/guides/getting-started.md +154 -148
- data/docs/guides/index.md +7 -0
- data/docs/guides/long-term-memory.md +60 -92
- data/docs/guides/mcp-server.md +617 -0
- data/docs/guides/multi-robot.md +249 -345
- data/docs/guides/recalling-memories.md +153 -163
- data/docs/guides/robot-groups.md +604 -0
- data/docs/guides/search-strategies.md +61 -58
- data/docs/guides/working-memory.md +103 -136
- data/docs/index.md +30 -26
- data/examples/robot_groups/robot_worker.rb +1 -2
- data/examples/robot_groups/same_process.rb +1 -4
- data/lib/htm/robot_group.rb +721 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/working_memory_channel.rb +250 -0
- data/lib/htm.rb +2 -0
- data/mkdocs.yml +2 -0
- metadata +18 -9
- data/db/migrate/00009_add_working_memory_to_robot_nodes.rb +0 -12
- data/db/migrate/00010_add_soft_delete_to_associations.rb +0 -29
- data/db/migrate/00011_add_performance_indexes.rb +0 -21
- data/db/migrate/00012_add_tags_trigram_index.rb +0 -18
- data/db/migrate/00013_enable_lz4_compression.rb +0 -43
- data/examples/robot_groups/lib/robot_group.rb +0 -419
- data/examples/robot_groups/lib/working_memory_channel.rb +0 -140
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Class: HTM::PropositionService
|
|
2
|
+
**Inherits:** Object
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Proposition Service - Extracts atomic factual propositions from text
|
|
6
|
+
|
|
7
|
+
This service breaks complex text into simple, self-contained factual
|
|
8
|
+
statements that can be stored as independent memory nodes. Each proposition:
|
|
9
|
+
* Expresses a single fact
|
|
10
|
+
* Is understandable without context
|
|
11
|
+
* Uses full names, not pronouns
|
|
12
|
+
* Includes relevant dates/qualifiers
|
|
13
|
+
* Contains one subject-predicate relationship
|
|
14
|
+
|
|
15
|
+
The actual LLM call is delegated to HTM.configuration.proposition_extractor
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
**`@example`**
|
|
19
|
+
```ruby
|
|
20
|
+
propositions = HTM::PropositionService.extract(
|
|
21
|
+
"In 1969, Neil Armstrong became the first person to walk on the Moon during Apollo 11."
|
|
22
|
+
)
|
|
23
|
+
# => ["Neil Armstrong was an astronaut.",
|
|
24
|
+
# "Neil Armstrong walked on the Moon in 1969.",
|
|
25
|
+
# "Neil Armstrong was the first person to walk on the Moon.",
|
|
26
|
+
# "Neil Armstrong walked on the Moon during the Apollo 11 mission.",
|
|
27
|
+
# "The Apollo 11 mission occurred in 1969."]
|
|
28
|
+
```
|
|
29
|
+
# Class Methods
|
|
30
|
+
## circuit_breaker() {: #method-c-circuit_breaker }
|
|
31
|
+
Get or create the circuit breaker for proposition service
|
|
32
|
+
**`@return`** [HTM::CircuitBreaker] The circuit breaker instance
|
|
33
|
+
|
|
34
|
+
## extract(content ) {: #method-c-extract }
|
|
35
|
+
Extract propositions from text content
|
|
36
|
+
**`@param`** [String] Text to analyze
|
|
37
|
+
|
|
38
|
+
**`@raise`** [CircuitBreakerOpenError] If circuit breaker is open
|
|
39
|
+
|
|
40
|
+
**`@raise`** [PropositionError] If extraction fails
|
|
41
|
+
|
|
42
|
+
**`@return`** [Array<String>] Array of atomic propositions
|
|
43
|
+
|
|
44
|
+
## parse_propositions(raw_propositions ) {: #method-c-parse_propositions }
|
|
45
|
+
Parse proposition response (handles string or array input)
|
|
46
|
+
**`@param`** [String, Array] Raw response from extractor
|
|
47
|
+
|
|
48
|
+
**`@return`** [Array<String>] Parsed proposition strings
|
|
49
|
+
|
|
50
|
+
## reset_circuit_breaker!() {: #method-c-reset_circuit_breaker! }
|
|
51
|
+
Reset the circuit breaker (useful for testing)
|
|
52
|
+
**`@return`** [void]
|
|
53
|
+
|
|
54
|
+
## valid_proposition?(proposition ) {: #method-c-valid_proposition? }
|
|
55
|
+
Validate single proposition
|
|
56
|
+
**`@param`** [String] Proposition to validate
|
|
57
|
+
|
|
58
|
+
**`@return`** [Boolean] True if valid
|
|
59
|
+
|
|
60
|
+
## validate_and_filter_propositions(propositions ) {: #method-c-validate_and_filter_propositions }
|
|
61
|
+
Validate and filter propositions
|
|
62
|
+
**`@param`** [Array<String>] Parsed propositions
|
|
63
|
+
|
|
64
|
+
**`@return`** [Array<String>] Valid propositions only
|
|
65
|
+
|
|
66
|
+
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Class: HTM::QueryCache
|
|
2
|
+
**Inherits:** Object
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Thread-safe query result cache with TTL and statistics
|
|
6
|
+
|
|
7
|
+
Provides LRU caching for expensive query results with:
|
|
8
|
+
* Configurable size and TTL
|
|
9
|
+
* Thread-safe statistics tracking
|
|
10
|
+
* Fast cache key generation (using Ruby's built-in hash)
|
|
11
|
+
* Selective cache invalidation by method type
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
**`@example`**
|
|
15
|
+
```ruby
|
|
16
|
+
cache = HTM::QueryCache.new(size: 1000, ttl: 300)
|
|
17
|
+
```
|
|
18
|
+
**`@example`**
|
|
19
|
+
```ruby
|
|
20
|
+
result = cache.fetch(:search, timeframe, query, limit) do
|
|
21
|
+
expensive_search_operation
|
|
22
|
+
end
|
|
23
|
+
```
|
|
24
|
+
**`@example`**
|
|
25
|
+
```ruby
|
|
26
|
+
cache.stats
|
|
27
|
+
# => { hits: 42, misses: 10, hit_rate: 80.77, size: 52 }
|
|
28
|
+
```
|
|
29
|
+
**`@example`**
|
|
30
|
+
```ruby
|
|
31
|
+
cache.invalidate_methods!(:search, :hybrid) # Only invalidate search-related entries
|
|
32
|
+
```
|
|
33
|
+
# Attributes
|
|
34
|
+
## enabled[RW] {: #attribute-i-enabled }
|
|
35
|
+
Returns the value of attribute enabled.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Instance Methods
|
|
39
|
+
## clear!() {: #method-i-clear! }
|
|
40
|
+
Clear all cached entries
|
|
41
|
+
|
|
42
|
+
**`@return`** [void]
|
|
43
|
+
|
|
44
|
+
## enabled?() {: #method-i-enabled? }
|
|
45
|
+
Check if cache is enabled
|
|
46
|
+
|
|
47
|
+
**`@return`** [Boolean]
|
|
48
|
+
|
|
49
|
+
## fetch(method, *args, &block) {: #method-i-fetch }
|
|
50
|
+
Fetch a value from cache or execute block
|
|
51
|
+
|
|
52
|
+
**`@param`** [Symbol] Method name for cache key
|
|
53
|
+
|
|
54
|
+
**`@param`** [Array] Arguments for cache key
|
|
55
|
+
|
|
56
|
+
**`@return`** [Object] Cached or computed value
|
|
57
|
+
|
|
58
|
+
**`@yield`** [] Block that computes the value if not cached
|
|
59
|
+
|
|
60
|
+
## initialize(size:1000, ttl:300) {: #method-i-initialize }
|
|
61
|
+
Initialize a new query cache
|
|
62
|
+
|
|
63
|
+
**`@param`** [Integer] Maximum number of entries (default: 1000, use 0 to disable)
|
|
64
|
+
|
|
65
|
+
**`@param`** [Integer] Time-to-live in seconds (default: 300)
|
|
66
|
+
|
|
67
|
+
**`@return`** [QueryCache] a new instance of QueryCache
|
|
68
|
+
|
|
69
|
+
## invalidate!() {: #method-i-invalidate! }
|
|
70
|
+
Invalidate cache (alias for clear!)
|
|
71
|
+
|
|
72
|
+
**`@return`** [void]
|
|
73
|
+
|
|
74
|
+
## invalidate_methods!(*methods) {: #method-i-invalidate_methods! }
|
|
75
|
+
Invalidate cache entries for specific methods only
|
|
76
|
+
|
|
77
|
+
More efficient than full invalidation when only certain types of cached data
|
|
78
|
+
need to be refreshed.
|
|
79
|
+
|
|
80
|
+
**`@param`** [Array<Symbol>] Method names to invalidate
|
|
81
|
+
|
|
82
|
+
**`@return`** [Integer] Number of entries invalidated
|
|
83
|
+
|
|
84
|
+
## stats() {: #method-i-stats }
|
|
85
|
+
Get cache statistics
|
|
86
|
+
|
|
87
|
+
**`@return`** [Hash, nil] Statistics hash or nil if disabled
|
|
88
|
+
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
# Class: HTM::RobotGroup
|
|
2
|
+
**Inherits:** Object
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Coordinates multiple robots with shared working memory and automatic failover.
|
|
6
|
+
|
|
7
|
+
RobotGroup provides application-level coordination for multiple HTM robots,
|
|
8
|
+
enabling them to share a common working memory context. Key capabilities
|
|
9
|
+
include:
|
|
10
|
+
|
|
11
|
+
* **Shared Working Memory**: All group members have access to the same
|
|
12
|
+
context
|
|
13
|
+
* **Active/Passive Roles**: Active robots participate in conversations;
|
|
14
|
+
passive robots maintain synchronized context for instant failover
|
|
15
|
+
* **Real-time Sync**: PostgreSQL LISTEN/NOTIFY enables immediate
|
|
16
|
+
synchronization
|
|
17
|
+
* **Failover**: When an active robot fails, a passive robot takes over
|
|
18
|
+
instantly
|
|
19
|
+
* **Dynamic Scaling**: Add or remove robots at runtime
|
|
20
|
+
|
|
21
|
+
**`@see`** [] Low-level pub/sub mechanism
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
**`@example`**
|
|
25
|
+
```ruby
|
|
26
|
+
group = HTM::RobotGroup.new(
|
|
27
|
+
name: 'customer-support',
|
|
28
|
+
active: ['primary-agent'],
|
|
29
|
+
passive: ['standby-agent'],
|
|
30
|
+
max_tokens: 8000
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Add shared context
|
|
34
|
+
group.remember('Customer prefers email communication.')
|
|
35
|
+
group.remember('Open ticket #789 regarding billing issue.')
|
|
36
|
+
|
|
37
|
+
# Query shared memory
|
|
38
|
+
results = group.recall('billing', limit: 5)
|
|
39
|
+
|
|
40
|
+
# Simulate failover
|
|
41
|
+
group.failover! # Promotes standby to active
|
|
42
|
+
|
|
43
|
+
# Cleanup
|
|
44
|
+
group.shutdown
|
|
45
|
+
```
|
|
46
|
+
# Attributes
|
|
47
|
+
## channel[RW] {: #attribute-i-channel }
|
|
48
|
+
The pub/sub channel used for real-time synchronization
|
|
49
|
+
|
|
50
|
+
**`@return`** [HTM::WorkingMemoryChannel]
|
|
51
|
+
|
|
52
|
+
## max_tokens[RW] {: #attribute-i-max_tokens }
|
|
53
|
+
Maximum token budget for working memory
|
|
54
|
+
|
|
55
|
+
**`@return`** [Integer]
|
|
56
|
+
|
|
57
|
+
## name[RW] {: #attribute-i-name }
|
|
58
|
+
Name of the robot group
|
|
59
|
+
|
|
60
|
+
**`@return`** [String]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# Instance Methods
|
|
64
|
+
## active?(robot_name) {: #method-i-active? }
|
|
65
|
+
Checks if a robot is an active member of this group.
|
|
66
|
+
|
|
67
|
+
**`@param`** [String] Name of the robot to check
|
|
68
|
+
|
|
69
|
+
**`@return`** [Boolean] true if the robot is an active member
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
**`@example`**
|
|
73
|
+
```ruby
|
|
74
|
+
group.active?('primary-agent') # => true
|
|
75
|
+
```
|
|
76
|
+
## active_robot_names() {: #method-i-active_robot_names }
|
|
77
|
+
Returns names of all active robots.
|
|
78
|
+
|
|
79
|
+
**`@return`** [Array<String>] Array of active robot names
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
**`@example`**
|
|
83
|
+
```ruby
|
|
84
|
+
group.active_robot_names # => ['primary-agent', 'secondary-agent']
|
|
85
|
+
```
|
|
86
|
+
## add_active(robot_name) {: #method-i-add_active }
|
|
87
|
+
Adds a robot as an active member of the group.
|
|
88
|
+
|
|
89
|
+
Active robots can add memories and respond to queries. The new robot is
|
|
90
|
+
automatically synchronized with existing shared working memory.
|
|
91
|
+
|
|
92
|
+
**`@param`** [String] Unique name for the robot
|
|
93
|
+
|
|
94
|
+
**`@raise`** [ArgumentError] if robot_name is already a member
|
|
95
|
+
|
|
96
|
+
**`@return`** [Integer] The robot's database ID
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
**`@example`**
|
|
100
|
+
```ruby
|
|
101
|
+
robot_id = group.add_active('new-agent')
|
|
102
|
+
puts "Added robot with ID: #{robot_id}"
|
|
103
|
+
```
|
|
104
|
+
## add_passive(robot_name) {: #method-i-add_passive }
|
|
105
|
+
Adds a robot as a passive (standby) member of the group.
|
|
106
|
+
|
|
107
|
+
Passive robots maintain synchronized working memory but don't actively
|
|
108
|
+
participate in conversations. They serve as warm standbys for failover.
|
|
109
|
+
|
|
110
|
+
**`@param`** [String] Unique name for the robot
|
|
111
|
+
|
|
112
|
+
**`@raise`** [ArgumentError] if robot_name is already a member
|
|
113
|
+
|
|
114
|
+
**`@return`** [Integer] The robot's database ID
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
**`@example`**
|
|
118
|
+
```ruby
|
|
119
|
+
robot_id = group.add_passive('standby-agent')
|
|
120
|
+
```
|
|
121
|
+
## clear_working_memory() {: #method-i-clear_working_memory }
|
|
122
|
+
Clears shared working memory for all group members.
|
|
123
|
+
|
|
124
|
+
Updates database flags and notifies all members to clear their in-memory
|
|
125
|
+
caches.
|
|
126
|
+
|
|
127
|
+
**`@return`** [Integer] Number of robot_node records updated
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
**`@example`**
|
|
131
|
+
```ruby
|
|
132
|
+
cleared_count = group.clear_working_memory
|
|
133
|
+
puts "Cleared #{cleared_count} working memory entries"
|
|
134
|
+
```
|
|
135
|
+
## demote(robot_name) {: #method-i-demote }
|
|
136
|
+
Demotes an active robot to passive status.
|
|
137
|
+
|
|
138
|
+
The robot retains its working memory but stops handling queries. Cannot demote
|
|
139
|
+
the last active robot.
|
|
140
|
+
|
|
141
|
+
**`@param`** [String] Name of the active robot to demote
|
|
142
|
+
|
|
143
|
+
**`@raise`** [ArgumentError] if robot_name is not an active member
|
|
144
|
+
|
|
145
|
+
**`@raise`** [ArgumentError] if this is the last active robot
|
|
146
|
+
|
|
147
|
+
**`@return`** [void]
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
**`@example`**
|
|
151
|
+
```ruby
|
|
152
|
+
group.demote('primary-agent')
|
|
153
|
+
group.passive?('primary-agent') # => true
|
|
154
|
+
```
|
|
155
|
+
## failover!() {: #method-i-failover! }
|
|
156
|
+
Performs automatic failover to the first passive robot.
|
|
157
|
+
|
|
158
|
+
Promotes the first passive robot to active status. The promoted robot already
|
|
159
|
+
has synchronized working memory and can immediately handle requests.
|
|
160
|
+
|
|
161
|
+
**`@raise`** [RuntimeError] if no passive robots are available
|
|
162
|
+
|
|
163
|
+
**`@return`** [String] Name of the promoted robot
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
**`@example`**
|
|
167
|
+
```ruby
|
|
168
|
+
promoted = group.failover!
|
|
169
|
+
puts "#{promoted} is now active"
|
|
170
|
+
```
|
|
171
|
+
## in_sync?() {: #method-i-in_sync? }
|
|
172
|
+
Checks if all members have identical working memory.
|
|
173
|
+
|
|
174
|
+
Compares the set of working memory node IDs across all members.
|
|
175
|
+
|
|
176
|
+
**`@return`** [Boolean] true if all members have the same working memory nodes
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
**`@example`**
|
|
180
|
+
```ruby
|
|
181
|
+
if group.in_sync?
|
|
182
|
+
puts "All robots synchronized"
|
|
183
|
+
else
|
|
184
|
+
group.sync_all
|
|
185
|
+
end
|
|
186
|
+
```
|
|
187
|
+
## initialize(name:, active:[], passive:[], max_tokens:4000, db_config:nil) {: #method-i-initialize }
|
|
188
|
+
Creates a new robot group with optional initial members.
|
|
189
|
+
|
|
190
|
+
Initializes the group, sets up the PostgreSQL pub/sub channel for real-time
|
|
191
|
+
synchronization, and registers initial active and passive robots.
|
|
192
|
+
|
|
193
|
+
**`@param`** [String] Unique name for this robot group
|
|
194
|
+
|
|
195
|
+
**`@param`** [Array<String>] Names of robots to add as active members
|
|
196
|
+
|
|
197
|
+
**`@param`** [Array<String>] Names of robots to add as passive (standby) members
|
|
198
|
+
|
|
199
|
+
**`@param`** [Integer] Maximum token budget for shared working memory
|
|
200
|
+
|
|
201
|
+
**`@param`** [Hash, nil] PostgreSQL connection config (defaults to HTM::Database.default_config)
|
|
202
|
+
|
|
203
|
+
**`@return`** [RobotGroup] a new instance of RobotGroup
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
**`@example`**
|
|
207
|
+
```ruby
|
|
208
|
+
group = HTM::RobotGroup.new(
|
|
209
|
+
name: 'support-team',
|
|
210
|
+
active: ['agent-1'],
|
|
211
|
+
passive: ['agent-2'],
|
|
212
|
+
max_tokens: 4000
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
**`@example`**
|
|
216
|
+
```ruby
|
|
217
|
+
group = HTM::RobotGroup.new(name: 'dynamic-team')
|
|
218
|
+
group.add_active('agent-1')
|
|
219
|
+
group.add_passive('agent-2')
|
|
220
|
+
```
|
|
221
|
+
## member?(robot_name) {: #method-i-member? }
|
|
222
|
+
Checks if a robot is a member of this group.
|
|
223
|
+
|
|
224
|
+
**`@param`** [String] Name of the robot to check
|
|
225
|
+
|
|
226
|
+
**`@return`** [Boolean] true if the robot is an active or passive member
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
**`@example`**
|
|
230
|
+
```ruby
|
|
231
|
+
group.member?('agent-1') # => true
|
|
232
|
+
group.member?('unknown') # => false
|
|
233
|
+
```
|
|
234
|
+
## member_ids() {: #method-i-member_ids }
|
|
235
|
+
Returns database IDs of all group members.
|
|
236
|
+
|
|
237
|
+
**`@return`** [Array<Integer>] Array of robot IDs (both active and passive)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
**`@example`**
|
|
241
|
+
```ruby
|
|
242
|
+
group.member_ids # => [1, 2, 3]
|
|
243
|
+
```
|
|
244
|
+
## passive?(robot_name) {: #method-i-passive? }
|
|
245
|
+
Checks if a robot is a passive member of this group.
|
|
246
|
+
|
|
247
|
+
**`@param`** [String] Name of the robot to check
|
|
248
|
+
|
|
249
|
+
**`@return`** [Boolean] true if the robot is a passive member
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
**`@example`**
|
|
253
|
+
```ruby
|
|
254
|
+
group.passive?('standby-agent') # => true
|
|
255
|
+
```
|
|
256
|
+
## passive_robot_names() {: #method-i-passive_robot_names }
|
|
257
|
+
Returns names of all passive robots.
|
|
258
|
+
|
|
259
|
+
**`@return`** [Array<String>] Array of passive robot names
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
**`@example`**
|
|
263
|
+
```ruby
|
|
264
|
+
group.passive_robot_names # => ['standby-agent']
|
|
265
|
+
```
|
|
266
|
+
## promote(robot_name) {: #method-i-promote }
|
|
267
|
+
Promotes a passive robot to active status.
|
|
268
|
+
|
|
269
|
+
The robot retains its synchronized working memory and becomes eligible to
|
|
270
|
+
handle queries and add memories.
|
|
271
|
+
|
|
272
|
+
**`@param`** [String] Name of the passive robot to promote
|
|
273
|
+
|
|
274
|
+
**`@raise`** [ArgumentError] if robot_name is not a passive member
|
|
275
|
+
|
|
276
|
+
**`@return`** [void]
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
**`@example`**
|
|
280
|
+
```ruby
|
|
281
|
+
group.promote('standby-agent')
|
|
282
|
+
group.active?('standby-agent') # => true
|
|
283
|
+
```
|
|
284
|
+
## recall(query, **options) {: #method-i-recall }
|
|
285
|
+
Recalls memories from shared working memory.
|
|
286
|
+
|
|
287
|
+
Uses the first active robot to perform the query against the shared working
|
|
288
|
+
memory context.
|
|
289
|
+
|
|
290
|
+
**`@option`** []
|
|
291
|
+
|
|
292
|
+
**`@option`** []
|
|
293
|
+
|
|
294
|
+
**`@param`** [String] The search query
|
|
295
|
+
|
|
296
|
+
**`@param`** [Hash] Additional options passed to HTM#recall
|
|
297
|
+
|
|
298
|
+
**`@raise`** [RuntimeError] if no active robots exist in the group
|
|
299
|
+
|
|
300
|
+
**`@return`** [Array] Array of matching memories
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
**`@example`**
|
|
304
|
+
```ruby
|
|
305
|
+
results = group.recall('billing issue', limit: 5, strategy: :fulltext)
|
|
306
|
+
```
|
|
307
|
+
## remember(content, originator:nil, **options) {: #method-i-remember }
|
|
308
|
+
Adds content to shared working memory for all group members.
|
|
309
|
+
|
|
310
|
+
The memory is created by the specified originator (or first active robot) and
|
|
311
|
+
automatically synchronized to all other members via database and real-time
|
|
312
|
+
notifications.
|
|
313
|
+
|
|
314
|
+
**`@param`** [String] The content to remember
|
|
315
|
+
|
|
316
|
+
**`@param`** [String, nil] Name of the robot creating the memory (optional)
|
|
317
|
+
|
|
318
|
+
**`@param`** [Hash] Additional options passed to HTM#remember
|
|
319
|
+
|
|
320
|
+
**`@raise`** [RuntimeError] if no active robots exist in the group
|
|
321
|
+
|
|
322
|
+
**`@return`** [Integer] The node ID of the created memory
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
**`@example`**
|
|
326
|
+
```ruby
|
|
327
|
+
node_id = group.remember('Customer prefers morning appointments.')
|
|
328
|
+
```
|
|
329
|
+
**`@example`**
|
|
330
|
+
```ruby
|
|
331
|
+
node_id = group.remember(
|
|
332
|
+
'Escalated to billing department.',
|
|
333
|
+
originator: 'agent-2'
|
|
334
|
+
)
|
|
335
|
+
```
|
|
336
|
+
## remove(robot_name) {: #method-i-remove }
|
|
337
|
+
Removes a robot from the group.
|
|
338
|
+
|
|
339
|
+
Clears the robot's working memory flags in the database. The robot can be
|
|
340
|
+
either active or passive.
|
|
341
|
+
|
|
342
|
+
**`@param`** [String] Name of the robot to remove
|
|
343
|
+
|
|
344
|
+
**`@return`** [void]
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
**`@example`**
|
|
348
|
+
```ruby
|
|
349
|
+
group.remove('departing-agent')
|
|
350
|
+
```
|
|
351
|
+
## shutdown() {: #method-i-shutdown }
|
|
352
|
+
Shuts down the group by stopping the listener thread.
|
|
353
|
+
|
|
354
|
+
Should be called when the group is no longer needed to release resources and
|
|
355
|
+
close the PostgreSQL listener connection.
|
|
356
|
+
|
|
357
|
+
**`@return`** [void]
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
**`@example`**
|
|
361
|
+
```ruby
|
|
362
|
+
group.shutdown
|
|
363
|
+
```
|
|
364
|
+
## status() {: #method-i-status }
|
|
365
|
+
Returns comprehensive status information about the group.
|
|
366
|
+
|
|
367
|
+
**`@option`** []
|
|
368
|
+
|
|
369
|
+
**`@option`** []
|
|
370
|
+
|
|
371
|
+
**`@option`** []
|
|
372
|
+
|
|
373
|
+
**`@option`** []
|
|
374
|
+
|
|
375
|
+
**`@option`** []
|
|
376
|
+
|
|
377
|
+
**`@option`** []
|
|
378
|
+
|
|
379
|
+
**`@option`** []
|
|
380
|
+
|
|
381
|
+
**`@option`** []
|
|
382
|
+
|
|
383
|
+
**`@option`** []
|
|
384
|
+
|
|
385
|
+
**`@param`** [Hash] a customizable set of options
|
|
386
|
+
|
|
387
|
+
**`@return`** [Hash] Status hash with the following keys:
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
**`@example`**
|
|
391
|
+
```ruby
|
|
392
|
+
status = group.status
|
|
393
|
+
puts "Group: #{status[:name]}"
|
|
394
|
+
puts "Active: #{status[:active].join(', ')}"
|
|
395
|
+
puts "Utilization: #{(status[:token_utilization] * 100).round(1)}%"
|
|
396
|
+
```
|
|
397
|
+
## sync_all() {: #method-i-sync_all }
|
|
398
|
+
Synchronizes all members to a consistent state.
|
|
399
|
+
|
|
400
|
+
Ensures every member has access to all shared working memory nodes.
|
|
401
|
+
|
|
402
|
+
**`@return`** [Hash] Sync results with :synced_nodes and :members_updated counts
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
**`@example`**
|
|
406
|
+
```ruby
|
|
407
|
+
result = group.sync_all
|
|
408
|
+
puts "Synced #{result[:synced_nodes]} nodes to #{result[:members_updated]} members"
|
|
409
|
+
```
|
|
410
|
+
## sync_robot(robot_name) {: #method-i-sync_robot }
|
|
411
|
+
Synchronizes a specific robot to match the group's shared working memory.
|
|
412
|
+
|
|
413
|
+
Copies working memory flags from other members to the specified robot,
|
|
414
|
+
ensuring it has access to all shared context.
|
|
415
|
+
|
|
416
|
+
**`@param`** [String] Name of the robot to synchronize
|
|
417
|
+
|
|
418
|
+
**`@raise`** [ArgumentError] if robot_name is not a member
|
|
419
|
+
|
|
420
|
+
**`@return`** [Integer] Number of nodes synchronized
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
**`@example`**
|
|
424
|
+
```ruby
|
|
425
|
+
synced = group.sync_robot('new-agent')
|
|
426
|
+
puts "Synchronized #{synced} nodes"
|
|
427
|
+
```
|
|
428
|
+
## sync_stats() {: #method-i-sync_stats }
|
|
429
|
+
Returns statistics about real-time synchronization.
|
|
430
|
+
|
|
431
|
+
**`@return`** [Hash] Stats hash with :nodes_synced and :evictions_synced counts
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
**`@example`**
|
|
435
|
+
```ruby
|
|
436
|
+
stats = group.sync_stats
|
|
437
|
+
puts "Nodes synced: #{stats[:nodes_synced]}"
|
|
438
|
+
puts "Evictions synced: #{stats[:evictions_synced]}"
|
|
439
|
+
```
|
|
440
|
+
## transfer_working_memory(from_robot, to_robot, clear_source:true) {: #method-i-transfer_working_memory }
|
|
441
|
+
Transfers working memory from one robot to another.
|
|
442
|
+
|
|
443
|
+
Copies all working memory node references from the source robot to the target
|
|
444
|
+
robot, optionally clearing the source.
|
|
445
|
+
|
|
446
|
+
**`@param`** [String] Name of the source robot
|
|
447
|
+
|
|
448
|
+
**`@param`** [String] Name of the destination robot
|
|
449
|
+
|
|
450
|
+
**`@param`** [Boolean] Whether to clear source's working memory after transfer
|
|
451
|
+
|
|
452
|
+
**`@raise`** [ArgumentError] if either robot is not a member
|
|
453
|
+
|
|
454
|
+
**`@return`** [Integer] Number of nodes transferred
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
**`@example`**
|
|
458
|
+
```ruby
|
|
459
|
+
transferred = group.transfer_working_memory('failing-agent', 'backup-agent')
|
|
460
|
+
```
|
|
461
|
+
**`@example`**
|
|
462
|
+
```ruby
|
|
463
|
+
transferred = group.transfer_working_memory(
|
|
464
|
+
'agent-1', 'agent-2',
|
|
465
|
+
clear_source: false
|
|
466
|
+
)
|
|
467
|
+
```
|
|
468
|
+
## working_memory_contents() {: #method-i-working_memory_contents }
|
|
469
|
+
Returns all nodes currently in shared working memory.
|
|
470
|
+
|
|
471
|
+
Queries the database for the union of all members' working memory, returning
|
|
472
|
+
nodes sorted by creation date (newest first).
|
|
473
|
+
|
|
474
|
+
**`@return`** [ActiveRecord::Relation<HTM::Models::Node>] Collection of nodes
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
**`@example`**
|
|
478
|
+
```ruby
|
|
479
|
+
nodes = group.working_memory_contents
|
|
480
|
+
nodes.each { |n| puts n.content }
|
|
481
|
+
```
|