agent99 0.0.4 → 0.0.5

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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/A2A_SPEC-dev.md +1829 -0
  3. data/CHANGELOG.md +31 -0
  4. data/COMMITS.md +196 -0
  5. data/DOCS.md +96 -0
  6. data/README.md +200 -78
  7. data/Rakefile +62 -0
  8. data/docs/AI/htm.md +215 -0
  9. data/docs/AI/htm.rb +141 -0
  10. data/docs/AI/htm_demo.db +0 -0
  11. data/docs/AI/notes_on_htm_implementation.md +1319 -0
  12. data/docs/AI/some_code.rb +692 -0
  13. data/docs/advanced-topics/a2a-protocol.md +13 -0
  14. data/docs/{control_actions.md → advanced-topics/control-actions.md} +2 -0
  15. data/docs/advanced-topics/model-context-protocol.md +4 -0
  16. data/docs/advanced-topics/multi-agent-processing.md +674 -0
  17. data/docs/agent-development/request-response-handling.md +512 -0
  18. data/docs/api-reference/agent99-base.md +463 -0
  19. data/docs/api-reference/message-clients.md +495 -0
  20. data/docs/api-reference/registry-client.md +470 -0
  21. data/docs/api-reference/schemas.md +518 -0
  22. data/docs/assets/css/custom.css +27 -0
  23. data/docs/assets/images/agent-lifecycle.svg +73 -0
  24. data/docs/assets/images/agent-registry-process.svg +86 -0
  25. data/docs/assets/images/agent-registry-processes.svg +114 -0
  26. data/docs/assets/images/agent-types-overview.svg +51 -0
  27. data/docs/assets/images/agent99-architecture.svg +85 -0
  28. data/docs/assets/images/agent99_logo.png +0 -0
  29. data/docs/assets/images/control-actions-state.svg +83 -0
  30. data/docs/assets/images/knowledge-graph.svg +77 -0
  31. data/docs/assets/images/message-processing-flow.svg +148 -0
  32. data/docs/assets/images/multi-agent-system.svg +66 -0
  33. data/docs/assets/images/proxy-pattern-sequence.svg +48 -0
  34. data/docs/assets/images/request-flow.svg +97 -0
  35. data/docs/assets/images/request-processing-lifecycle.svg +50 -0
  36. data/docs/assets/images/request-response-sequence.svg +39 -0
  37. data/docs/{agent_lifecycle.md → core-concepts/agent-lifecycle.md} +2 -0
  38. data/docs/core-concepts/agent-types.md +255 -0
  39. data/docs/{architecture.md → core-concepts/architecture.md} +5 -5
  40. data/docs/{what_is_an_agent.md → core-concepts/what-is-an-agent.md} +1 -1
  41. data/docs/diagrams/message-flow-sequence.svg +198 -0
  42. data/docs/diagrams/p2p-network-topology.svg +181 -0
  43. data/docs/diagrams/smart-transport-routing.svg +165 -0
  44. data/docs/diagrams/three-layer-architecture.svg +77 -0
  45. data/docs/diagrams/transport-extension-api.svg +309 -0
  46. data/docs/diagrams/transport-extension-architecture.svg +234 -0
  47. data/docs/diagrams/transport-selection-flowchart.svg +264 -0
  48. data/docs/examples/advanced-examples.md +951 -0
  49. data/docs/examples/basic-examples.md +268 -0
  50. data/docs/{agent_registry_processes.md → framework-components/agent-registry.md} +1 -1
  51. data/docs/{message_processing.md → framework-components/message-processing.md} +3 -1
  52. data/docs/getting-started/basic-example.md +306 -0
  53. data/docs/getting-started/installation.md +160 -0
  54. data/docs/getting-started/overview.md +64 -0
  55. data/docs/getting-started/quick-start.md +179 -0
  56. data/docs/index.md +97 -0
  57. data/examples/DEMO.md +148 -0
  58. data/examples/README.md +50 -0
  59. data/examples/bad_agent.rb +32 -0
  60. data/examples/registry.rb +0 -8
  61. data/examples/run_demo.rb +433 -0
  62. data/lib/agent99/amqp_message_client.rb +2 -2
  63. data/lib/agent99/base.rb +1 -1
  64. data/lib/agent99/message_processing.rb +6 -12
  65. data/lib/agent99/registry_client.rb +4 -1
  66. data/lib/agent99/version.rb +1 -1
  67. data/lib/agent99.rb +1 -1
  68. data/mkdocs.yml +195 -0
  69. data/p2p_plan.md +533 -0
  70. data/p2p_roadmap.md +299 -0
  71. data/registry_plan.md +1818 -0
  72. metadata +89 -32
  73. data/docs/README.md +0 -57
  74. data/docs/diagrams/agent_registry_processes.dot +0 -42
  75. data/docs/diagrams/agent_registry_processes.png +0 -0
  76. data/docs/diagrams/high_level_architecture.dot +0 -26
  77. data/docs/diagrams/high_level_architecture.png +0 -0
  78. data/docs/diagrams/request_flow.dot +0 -42
  79. data/docs/diagrams/request_flow.png +0 -0
  80. /data/docs/{advanced_features.md → advanced-topics/advanced-features.md} +0 -0
  81. /data/docs/{extending_the_framework.md → advanced-topics/extending-the-framework.md} +0 -0
  82. /data/docs/{custom_agent_implementation.md → agent-development/custom-agent-implementation.md} +0 -0
  83. /data/docs/{error_handling_and_logging.md → agent-development/error-handling-and-logging.md} +0 -0
  84. /data/docs/{schema_definition.md → agent-development/schema-definition.md} +0 -0
  85. /data/docs/{api_reference.md → api-reference/overview.md} +0 -0
  86. /data/docs/{agent_discovery.md → framework-components/agent-discovery.md} +0 -0
  87. /data/docs/{messaging_system.md → framework-components/messaging-system.md} +0 -0
  88. /data/docs/{breaking_change_v0.0.4.md → operations/breaking-changes.md} +0 -0
  89. /data/docs/{configuration.md → operations/configuration.md} +0 -0
  90. /data/docs/{preformance_considerations.md → operations/performance-considerations.md} +0 -0
  91. /data/docs/{security.md → operations/security.md} +0 -0
  92. /data/docs/{troubleshooting.md → operations/troubleshooting.md} +0 -0
data/Rakefile CHANGED
@@ -6,3 +6,65 @@ require "minitest/test_task"
6
6
  Minitest::TestTask.create
7
7
 
8
8
  task default: :test
9
+
10
+ # Additional test tasks for Agent99
11
+ require "rake/testtask"
12
+
13
+ # Unit tests only
14
+ Rake::TestTask.new(:test_unit) do |t|
15
+ t.libs << "lib"
16
+ t.libs << "test"
17
+ t.test_files = FileList["test/agent99/*test*.rb"]
18
+ t.verbose = true
19
+ end
20
+
21
+ # Integration tests only
22
+ Rake::TestTask.new(:test_integration) do |t|
23
+ t.libs << "lib"
24
+ t.libs << "test"
25
+ t.test_files = FileList["test/integration/*test*.rb"]
26
+ t.verbose = true
27
+ end
28
+
29
+ # System tests only
30
+ Rake::TestTask.new(:test_system) do |t|
31
+ t.libs << "lib"
32
+ t.libs << "test"
33
+ t.test_files = FileList["test/system/*test*.rb"]
34
+ t.verbose = true
35
+ end
36
+
37
+ desc "Run tests with coverage reporting (requires simplecov gem)"
38
+ task :test_coverage do
39
+ ENV["COVERAGE"] = "true"
40
+ Rake::Task[:test].invoke
41
+ end
42
+
43
+ desc "Run tests in verbose mode"
44
+ task :test_verbose do
45
+ ENV["VERBOSE"] = "true"
46
+ Rake::Task[:test].invoke
47
+ end
48
+
49
+ desc "Show test statistics"
50
+ task :test_stats do
51
+ unit_tests = Dir.glob("test/agent99/*test*.rb").size
52
+ integration_tests = Dir.glob("test/integration/*test*.rb").size
53
+ system_tests = Dir.glob("test/system/*test*.rb").size
54
+ total_tests = unit_tests + integration_tests + system_tests
55
+
56
+ puts "Test Statistics:"
57
+ puts " Unit tests: #{unit_tests}"
58
+ puts " Integration tests: #{integration_tests}"
59
+ puts " System tests: #{system_tests}"
60
+ puts " Total test files: #{total_tests}"
61
+
62
+ # Count test methods
63
+ test_methods = 0
64
+ Dir.glob("test/**/*test*.rb").each do |file|
65
+ content = File.read(file)
66
+ test_methods += content.scan(/def test_/).size
67
+ end
68
+
69
+ puts " Total test methods: #{test_methods}"
70
+ end
data/docs/AI/htm.md ADDED
@@ -0,0 +1,215 @@
1
+ # Hierarchical Temporal Memory in AI Systems
2
+
3
+ ## Table of Contents
4
+ - [Introduction](#introduction)
5
+ - [Understanding Hierarchical Temporal Memory](#understanding-hierarchical-temporal-memory)
6
+ - [Layers of Memory](#layers-of-memory)
7
+ - [Topic Columns](#topic-columns)
8
+ - [Memory Cell Promotion and Forgetting](#memory-cell-promotion-and-forgetting)
9
+ - [Implications for AI Systems](#implications-for-ai-systems)
10
+ - [Conclusion](#conclusion)
11
+ - [Some Code Ideas](#some-code-ideas)
12
+
13
+ ## Introduction
14
+
15
+ Hierarchical Temporal Memory (HTM) is a computational model that mimics some aspects of the neocortex, developed by the Numenta research company. It focuses on how the brain processes information over time and is designed to learn patterns and sequences in data. HTM operates on principles of hierarchy, meaning it organizes information in layers, and temporal memory, which enables it to remember sequences and make predictions based on temporal patterns. This model is particularly effective for tasks involving time series data and has applications in anomaly detection, robotics, and various cognitive computing tasks.
16
+
17
+ ## Understanding Hierarchical Temporal Memory
18
+
19
+ Hierarchical Temporal Memory is inspired by the theory of how the brain works, particularly focusing on how it learns patterns and sequences. The fundamental ideas were put forward by Jeff Hawkins, co-founder of Numenta, who theorized that real intelligence is derived from understanding and manipulating temporal sequences.
20
+
21
+ HTM leverages a structure that is hierarchical and spatially organized. Each level of the hierarchy processes information at varying degrees of abstraction. The bottom layers deal with raw sensory input, while the upper layers interpret this data into meaningful contexts.
22
+
23
+ This model is particularly valuable in applications involving complex time series, where the demand for understanding sequences over time is crucial. The capability of HTM to generalize from sparse data makes it unique compared to traditional machine learning techniques.
24
+
25
+ ## Layers of Memory
26
+
27
+ HTM's architecture consists of several layers, each designed for specific functions. The bottom layer, known as the input layer, is responsible for receiving raw data inputs. Subsequent layers process this information, identifying patterns and sequences that inform decisions.
28
+
29
+ 1. **Input Layer**: Receives sensory data and converts it into a usable format for the next layer.
30
+ 2. **Temporal Pooling Layer**: Captures the temporal dependencies in the data.
31
+ 3. **Spatial Pooling Layer**: Encodes spatial relationships and builds a representation of the input data.
32
+
33
+ This multi-layered approach enables HTM to build increasingly sophisticated representations of the data at each layer, akin to how the neocortex might operate.
34
+
35
+ ## Topic Columns
36
+
37
+ Each "column" in HTM can be viewed as a mini-neural network that processes input from the layer below it. These columns work in parallel to learn spatial and temporal patterns. Thus, they respond to specific features of the incoming data, allowing HTM to develop a hierarchy of data features. Columns also facilitate learning through inhibition, promoting the most active neurons while suppressing others.
38
+
39
+ ## Memory Cell Promotion and Forgetting
40
+
41
+ The mechanisms by which HTM promotes or forgets memory cells mirror more biological processes.
42
+
43
+ ### Promotion
44
+
45
+ Cells that consistently provide accurate predictions based on the learned sequence are promoted. For instance, if certain neurons within a column recognize patterns that lead to accurate outcomes, they're trained to engage more actively depending on their performance over time.
46
+
47
+ ### Forgetting
48
+
49
+ Forgetting is equally important; neurons that fail to respond to valid sequences are gradually demoted. This ensures that the model does not become overly reliant on outdated information, allowing new patterns and sequences to emerge and be incorporated.
50
+
51
+ ## Implications for AI Systems
52
+
53
+ By modeling the functioning of the neocortex, HTM introduces a new paradigm in machine learning, emphasizing time and sequences over static data processing. This has significant implications in various fields:
54
+
55
+ - **Anomaly Detection**: In finance, HTM can be used to identify unusual patterns in transactions that may indicate fraud.
56
+ - **Robotics**: Robots leveraging HTM can learn from their experiences in real-time, adapting to environmental changes dynamically.
57
+ - **Natural Language Processing**: Understanding the temporal relationships between phrases can enhance language models, leading to more contextually accurate interpretations.
58
+
59
+ ## Conclusion
60
+
61
+ Hierarchical Temporal Memory presents a powerful framework for understanding and replicating the cognitive processes of the human brain. With its ability to learn from temporal patterns, it opens new frontiers in artificial intelligence and machine learning.
62
+
63
+ ## Some Code Ideas
64
+
65
+ ```ruby
66
+ require 'active_record'
67
+
68
+ class CreateHtmTable < ActiveRecord::Migration[7.0]
69
+ def change
70
+ create_table :htm do |t|
71
+ t.uuid :event, null: false
72
+ t.text :proposition, null: false
73
+ t.string :state, null: false
74
+ t.datetime :last_accessed, null: false
75
+ t.integer :hit_count, null: false, default: 0
76
+ t.float :vector, null: false, array: true, limit: 2048
77
+
78
+ t.timestamps
79
+ end
80
+
81
+ add_index :htm, :event, unique: true
82
+ add_index :htm, :state
83
+
84
+ execute <<-SQL
85
+ ALTER TABLE htm
86
+ ADD CONSTRAINT check_state
87
+ CHECK (state IN ('STM', 'MTM', 'LTM', 'PM'))
88
+ SQL
89
+
90
+ execute <<-SQL
91
+ ALTER TABLE htm
92
+ ADD CONSTRAINT check_vector_length
93
+ CHECK (array_length(vector, 1) = 2048)
94
+ SQL
95
+ end
96
+ end
97
+ ```
98
+
99
+ This is a notional model for the table. I'm having second thoughts about keeping track of the hit count. I think maybe access time is all that is needed and that is provided by the AR timestamps.
100
+
101
+ ```ruby
102
+ require 'active_record'
103
+ require 'neighbors'
104
+
105
+ class Htm < ActiveRecord::Base
106
+ STATES = %w[STM MTM LTM PM].freeze
107
+
108
+ validates :event, presence: true
109
+ validates :proposition, presence: true
110
+ validates :state, presence: true, inclusion: { in: STATES }
111
+ validates :vector, presence: true, length: { is: 2048 }
112
+
113
+ def self.search_and_update(event_uuid:, query_vector:, top_k: 10)
114
+ records = where(event: event_uuid)
115
+ vectors = records.pluck(:vector)
116
+
117
+ neighbor_search = Neighbors::NearestNeighbors.new(vectors)
118
+ nearest_indices = neighbor_search.search(query_vector, k: top_k)
119
+
120
+ nearest_records = records.where(id: records.ids.values_at(*nearest_indices))
121
+
122
+ nearest_records.each do |record|
123
+ record.hit_count += 1
124
+ record.last_accessed = Time.current
125
+ record.save!
126
+ end
127
+
128
+ nearest_records
129
+ end
130
+
131
+ def update_state
132
+ event_config = StateConfig.find_by(event: event)
133
+ current_time = Time.current
134
+ time_since_creation = current_time - created_at
135
+ time_since_last_access = current_time - last_accessed
136
+
137
+ if should_promote?(event_config, time_since_creation)
138
+ promote_state
139
+ elsif should_demote?(event_config, time_since_last_access)
140
+ demote_state
141
+ end
142
+ end
143
+
144
+ private
145
+
146
+ def should_promote?(config, time_delta)
147
+ current_state_index = STATES.index(state)
148
+ return false if current_state_index == STATES.length - 1
149
+
150
+ next_state = STATES[current_state_index + 1]
151
+ time_delta > config.promotion_time(next_state) &&
152
+ hit_count > config.promotion_hits(next_state)
153
+ end
154
+
155
+ def should_demote?(config, time_delta)
156
+ current_state_index = STATES.index(state)
157
+ return false if current_state_index == 0
158
+
159
+ time_delta < config.demotion_time(state) &&
160
+ hit_count < config.demotion_hits(state)
161
+ end
162
+
163
+ def promote_state
164
+ current_index = STATES.index(state)
165
+ self.state = STATES[current_index + 1] if current_index < STATES.length - 1
166
+ save!
167
+ end
168
+
169
+ def demote_state
170
+ current_index = STATES.index(state)
171
+ self.state = STATES[current_index - 1] if current_index > 0
172
+ save!
173
+ end
174
+ end
175
+
176
+ class StateConfig < ActiveRecord::Base
177
+ def promotion_time(state)
178
+ case state
179
+ when 'MTM' then mtm_promotion_time
180
+ when 'LTM' then ltm_promotion_time
181
+ when 'PM' then pm_promotion_time
182
+ else 0
183
+ end
184
+ end
185
+
186
+ def promotion_hits(state)
187
+ case state
188
+ when 'MTM' then mtm_promotion_hits
189
+ when 'LTM' then ltm_promotion_hits
190
+ when 'PM' then pm_promotion_hits
191
+ else 0
192
+ end
193
+ end
194
+
195
+ def demotion_time(state)
196
+ case state
197
+ when 'MTM' then mtm_demotion_time
198
+ when 'LTM' then ltm_demotion_time
199
+ when 'PM' then pm_demotion_time
200
+ else Float::INFINITY
201
+ end
202
+ end
203
+
204
+ def demotion_hits(state)
205
+ case state
206
+ when 'MTM' then mtm_demotion_hits
207
+ when 'LTM' then ltm_demotion_hits
208
+ when 'PM' then pm_demotion_hits
209
+ else Float::INFINITY
210
+ end
211
+ end
212
+ end
213
+ ```
214
+
215
+
data/docs/AI/htm.rb ADDED
@@ -0,0 +1,141 @@
1
+ # File: examples/AI/htm.rb
2
+
3
+ require 'sqlite3'
4
+ require 'securerandom'
5
+ require 'time'
6
+
7
+ class HTMDemo
8
+ STATES = %w[STM MTM LTM PM].freeze
9
+
10
+ def initialize(db_name: 'htm_demo.db')
11
+ @db = SQLite3::Database.new(db_name)
12
+ @db.results_as_hash = true
13
+ create_tables
14
+ end
15
+
16
+ def create_tables
17
+ @db.execute <<-SQL
18
+ CREATE TABLE IF NOT EXISTS htm_cells (
19
+ id INTEGER PRIMARY KEY,
20
+ column_id INTEGER NOT NULL,
21
+ state TEXT NOT NULL,
22
+ last_accessed DATETIME NOT NULL,
23
+ hit_count INTEGER NOT NULL DEFAULT 0,
24
+ data TEXT NOT NULL
25
+ )
26
+ SQL
27
+
28
+ @db.execute <<-SQL
29
+ CREATE TABLE IF NOT EXISTS htm_columns (
30
+ id INTEGER PRIMARY KEY,
31
+ layer INTEGER NOT NULL
32
+ )
33
+ SQL
34
+ end
35
+
36
+ def create_column(layer:)
37
+ @db.execute('INSERT INTO htm_columns (layer) VALUES (?)', [layer])
38
+ @db.last_insert_row_id
39
+ end
40
+
41
+ def create_cell(column_id:, data:)
42
+ @db.execute(<<-SQL, {
43
+ INSERT INTO htm_cells (column_id, state, last_accessed, data)
44
+ VALUES (:column_id, :state, :last_accessed, :data)
45
+ SQL
46
+ column_id: column_id,
47
+ state: 'STM',
48
+ last_accessed: Time.now.strftime('%Y-%m-%dT%H:%M:%S%z'),
49
+ data: data
50
+ })
51
+ @db.last_insert_row_id
52
+ end
53
+
54
+ def update_cell(id:)
55
+ @db.execute(<<-SQL, {
56
+ UPDATE htm_cells
57
+ SET hit_count = hit_count + 1, last_accessed = :last_accessed
58
+ WHERE id = :id
59
+ SQL
60
+ id: id,
61
+ last_accessed: Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
62
+ })
63
+ end
64
+
65
+ def promote_cell(id:)
66
+ current_state = @db.get_first_value('SELECT state FROM htm_cells WHERE id = ?', [id])
67
+ current_index = STATES.index(current_state)
68
+
69
+ if current_index < STATES.length - 1
70
+ new_state = STATES[current_index + 1]
71
+ @db.execute('UPDATE htm_cells SET state = ? WHERE id = ?', [new_state, id])
72
+ end
73
+ end
74
+
75
+ def forget_cell(id:)
76
+ current_state = @db.get_first_value('SELECT state FROM htm_cells WHERE id = ?', [id])
77
+ current_index = STATES.index(current_state)
78
+
79
+ if current_index > 0
80
+ new_state = STATES[current_index - 1]
81
+ @db.execute('UPDATE htm_cells SET state = ? WHERE id = ?', [new_state, id])
82
+ end
83
+ end
84
+
85
+ def search_cells(query:, limit: 5)
86
+ @db.execute(<<-SQL, {
87
+ SELECT * FROM htm_cells
88
+ WHERE data LIKE :query
89
+ ORDER BY hit_count DESC
90
+ LIMIT :limit
91
+ SQL
92
+ query: "%#{query}%",
93
+ limit: limit
94
+ })
95
+ end
96
+
97
+ def display_stats
98
+ puts "HTM Statistics:"
99
+ puts "---------------"
100
+
101
+ STATES.each do |state|
102
+ count = @db.get_first_value('SELECT COUNT(*) FROM htm_cells WHERE state = ?', [state])
103
+ puts "#{state} cells: #{count}"
104
+ end
105
+
106
+ total_cells = @db.get_first_value('SELECT COUNT(*) FROM htm_cells')
107
+ total_columns = @db.get_first_value('SELECT COUNT(*) FROM htm_columns')
108
+ puts "Total cells: #{total_cells}"
109
+ puts "Total columns: #{total_columns}"
110
+ end
111
+ end
112
+
113
+ # Usage example
114
+ htm = HTMDemo.new
115
+
116
+ # Create some columns and cells
117
+ 5.times do |i|
118
+ column_id = htm.create_column(layer: i % 3 + 1)
119
+ 10.times do
120
+ htm.create_cell(column_id: column_id, data: SecureRandom.hex(10))
121
+ end
122
+ end
123
+
124
+ # Simulate some cell activations and promotions
125
+ 20.times do
126
+ cell_id = htm.search_cells(query: SecureRandom.hex(5), limit: 1).first&.fetch('id')
127
+ if cell_id
128
+ htm.update_cell(id: cell_id)
129
+ htm.promote_cell(id: cell_id) if rand < 0.3
130
+ end
131
+ end
132
+
133
+ # Simulate some cell forgetting
134
+ 10.times do
135
+ cell_id = htm.search_cells(query: SecureRandom.hex(5), limit: 1).first&.fetch('id')
136
+ htm.forget_cell(id: cell_id) if cell_id && rand < 0.2
137
+ end
138
+
139
+ # Display final statistics
140
+ htm.display_stats
141
+
Binary file