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
@@ -0,0 +1,470 @@
1
+ # Registry Client API
2
+
3
+ The Registry Client provides programmatic access to the Agent99 registry service for agent registration, discovery, and management operations.
4
+
5
+ ## Overview
6
+
7
+ The registry client is built into `Agent99::Base` but can also be used independently for advanced registry operations.
8
+
9
+ ## Basic Usage
10
+
11
+ ### Auto-Registration (Built-in)
12
+
13
+ Most agents use automatic registration through the base class:
14
+
15
+ ```ruby
16
+ class MyAgent < Agent99::Base
17
+ def info
18
+ {
19
+ name: self.class.to_s,
20
+ type: :server,
21
+ capabilities: ['example', 'demo']
22
+ }
23
+ end
24
+
25
+ def process_request(payload)
26
+ # Agent automatically registers on startup
27
+ send_response(message: "Hello from registered agent!")
28
+ end
29
+ end
30
+ ```
31
+
32
+ ### Manual Registration
33
+
34
+ For advanced use cases, you can manually register agents:
35
+
36
+ ```ruby
37
+ registry = Agent99::RegistryClient.new
38
+ agent_info = {
39
+ name: "CustomAgent",
40
+ type: "server",
41
+ capabilities: ["custom", "manual"],
42
+ host: "localhost",
43
+ port: 5000
44
+ }
45
+
46
+ # Register the agent
47
+ registry.register_agent(agent_info)
48
+ ```
49
+
50
+ ## Registry Client Methods
51
+
52
+ ### `#register_agent(agent_info)`
53
+
54
+ Registers an agent with the registry.
55
+
56
+ ```ruby
57
+ def register_agent(agent_info)
58
+ # POST /agents
59
+ end
60
+ ```
61
+
62
+ **Parameters:**
63
+ - `agent_info` (Hash) - Agent information
64
+
65
+ **Required Fields:**
66
+ - `name` (String) - Unique agent name
67
+ - `type` (String) - Agent type (`"server"`, `"client"`, `"hybrid"`)
68
+ - `capabilities` (Array) - List of capabilities
69
+
70
+ **Optional Fields:**
71
+ - `host` (String) - Agent host (default: detected)
72
+ - `port` (Integer) - Agent port (default: auto-assigned)
73
+ - `metadata` (Hash) - Additional metadata
74
+ - `schema` (Hash) - Request/response schemas
75
+
76
+ **Example:**
77
+ ```ruby
78
+ registry.register_agent({
79
+ name: "WeatherService",
80
+ type: "server",
81
+ capabilities: ["weather", "forecast", "temperature"],
82
+ host: "weather.example.com",
83
+ port: 8080,
84
+ metadata: {
85
+ version: "1.2.3",
86
+ region: "us-west"
87
+ }
88
+ })
89
+ ```
90
+
91
+ ### `#unregister_agent(agent_name)`
92
+
93
+ Removes an agent from the registry.
94
+
95
+ ```ruby
96
+ def unregister_agent(agent_name)
97
+ # DELETE /agents/:name
98
+ end
99
+ ```
100
+
101
+ **Parameters:**
102
+ - `agent_name` (String) - Name of agent to remove
103
+
104
+ **Example:**
105
+ ```ruby
106
+ registry.unregister_agent("WeatherService")
107
+ ```
108
+
109
+ ### `#discover_agents(capabilities = [])`
110
+
111
+ Finds agents that match specified capabilities.
112
+
113
+ ```ruby
114
+ def discover_agents(capabilities = [])
115
+ # GET /agents/discover?capabilities=cap1,cap2
116
+ end
117
+ ```
118
+
119
+ **Parameters:**
120
+ - `capabilities` (Array) - Required capabilities (empty array returns all)
121
+
122
+ **Returns:** Array of agent information hashes
123
+
124
+ **Example:**
125
+ ```ruby
126
+ # Find all weather agents
127
+ weather_agents = registry.discover_agents(["weather"])
128
+
129
+ # Find agents with multiple capabilities
130
+ calc_agents = registry.discover_agents(["calculator", "math"])
131
+
132
+ # Find all agents
133
+ all_agents = registry.discover_agents([])
134
+ ```
135
+
136
+ ### `#get_agent(agent_name)`
137
+
138
+ Retrieves detailed information about a specific agent.
139
+
140
+ ```ruby
141
+ def get_agent(agent_name)
142
+ # GET /agents/:name
143
+ end
144
+ ```
145
+
146
+ **Parameters:**
147
+ - `agent_name` (String) - Agent name
148
+
149
+ **Returns:** Agent information hash or nil if not found
150
+
151
+ **Example:**
152
+ ```ruby
153
+ agent_info = registry.get_agent("WeatherService")
154
+ if agent_info
155
+ puts "Agent capabilities: #{agent_info[:capabilities]}"
156
+ else
157
+ puts "Agent not found"
158
+ end
159
+ ```
160
+
161
+ ### `#list_agents`
162
+
163
+ Lists all registered agents.
164
+
165
+ ```ruby
166
+ def list_agents
167
+ # GET /agents
168
+ end
169
+ ```
170
+
171
+ **Returns:** Array of all registered agent information
172
+
173
+ **Example:**
174
+ ```ruby
175
+ all_agents = registry.list_agents
176
+ puts "Total agents: #{all_agents.size}"
177
+
178
+ all_agents.each do |agent|
179
+ puts "#{agent[:name]} (#{agent[:type]}) - #{agent[:capabilities].join(', ')}"
180
+ end
181
+ ```
182
+
183
+ ### `#health_check`
184
+
185
+ Checks registry service health.
186
+
187
+ ```ruby
188
+ def health_check
189
+ # GET /health
190
+ end
191
+ ```
192
+
193
+ **Returns:** Health status hash
194
+
195
+ **Example:**
196
+ ```ruby
197
+ health = registry.health_check
198
+ puts "Registry status: #{health[:status]}"
199
+ puts "Uptime: #{health[:uptime]}"
200
+ ```
201
+
202
+ ## Advanced Usage
203
+
204
+ ### Custom Registry Client
205
+
206
+ For applications that need to interact with multiple registries or require custom configuration:
207
+
208
+ ```ruby
209
+ require 'agent99/registry_client'
210
+
211
+ # Custom registry client
212
+ registry = Agent99::RegistryClient.new(
213
+ base_url: 'http://registry.example.com:8080',
214
+ timeout: 15,
215
+ retry_attempts: 5
216
+ )
217
+
218
+ # Use custom client
219
+ agents = registry.discover_agents(['database'])
220
+ ```
221
+
222
+ ### Registry Client Configuration
223
+
224
+ ```ruby
225
+ class Agent99::RegistryClient
226
+ def initialize(options = {})
227
+ @base_url = options[:base_url] || ENV['AGENT99_REGISTRY_URL'] || 'http://localhost:4567'
228
+ @timeout = options[:timeout] || 30
229
+ @retry_attempts = options[:retry_attempts] || 3
230
+ @retry_delay = options[:retry_delay] || 1
231
+ end
232
+ end
233
+ ```
234
+
235
+ **Configuration Options:**
236
+ - `base_url` - Registry service URL
237
+ - `timeout` - HTTP timeout in seconds
238
+ - `retry_attempts` - Number of retry attempts
239
+ - `retry_delay` - Delay between retries in seconds
240
+
241
+ ## Error Handling
242
+
243
+ The registry client raises specific exceptions for different error conditions:
244
+
245
+ ```ruby
246
+ begin
247
+ registry.register_agent(agent_info)
248
+ rescue Agent99::RegistryError => e
249
+ case e.code
250
+ when 'AGENT_EXISTS'
251
+ puts "Agent already registered"
252
+ when 'VALIDATION_ERROR'
253
+ puts "Invalid agent info: #{e.message}"
254
+ when 'REGISTRY_UNAVAILABLE'
255
+ puts "Registry service unavailable"
256
+ else
257
+ puts "Registration failed: #{e.message}"
258
+ end
259
+ end
260
+ ```
261
+
262
+ ### Common Exceptions
263
+
264
+ - `Agent99::RegistryError` - Base registry exception
265
+ - `Agent99::RegistryConnectionError` - Network/connection issues
266
+ - `Agent99::RegistryValidationError` - Invalid agent data
267
+ - `Agent99::RegistryNotFoundError` - Agent/resource not found
268
+
269
+ ## Response Formats
270
+
271
+ ### Agent Information Structure
272
+
273
+ ```json
274
+ {
275
+ "name": "WeatherService",
276
+ "type": "server",
277
+ "capabilities": ["weather", "forecast"],
278
+ "host": "localhost",
279
+ "port": 8080,
280
+ "registered_at": "2024-12-12T10:30:00Z",
281
+ "last_seen": "2024-12-12T10:35:00Z",
282
+ "metadata": {
283
+ "version": "1.2.3",
284
+ "region": "us-west"
285
+ },
286
+ "schema": {
287
+ "request": { /* JSON Schema */ },
288
+ "response": { /* JSON Schema */ }
289
+ }
290
+ }
291
+ ```
292
+
293
+ ### Discovery Response
294
+
295
+ ```json
296
+ {
297
+ "agents": [
298
+ {
299
+ "name": "WeatherService",
300
+ "type": "server",
301
+ "capabilities": ["weather", "forecast"],
302
+ "host": "localhost",
303
+ "port": 8080
304
+ }
305
+ ],
306
+ "total_count": 1,
307
+ "matching_capabilities": ["weather"]
308
+ }
309
+ ```
310
+
311
+ ## Registry HTTP API
312
+
313
+ The registry exposes a REST API that the client uses:
314
+
315
+ ### Endpoints
316
+
317
+ | Method | Endpoint | Description |
318
+ |--------|----------|-------------|
319
+ | `POST` | `/agents` | Register new agent |
320
+ | `GET` | `/agents` | List all agents |
321
+ | `GET` | `/agents/:name` | Get specific agent |
322
+ | `DELETE` | `/agents/:name` | Unregister agent |
323
+ | `GET` | `/agents/discover` | Discover agents by capabilities |
324
+ | `GET` | `/health` | Registry health check |
325
+
326
+ ### Query Parameters
327
+
328
+ **Discovery endpoint (`/agents/discover`):**
329
+ - `capabilities` - Comma-separated list of required capabilities
330
+ - `type` - Filter by agent type (`server`, `client`, `hybrid`)
331
+ - `limit` - Maximum number of results
332
+ - `offset` - Pagination offset
333
+
334
+ **Example requests:**
335
+ ```bash
336
+ # Find weather agents
337
+ GET /agents/discover?capabilities=weather
338
+
339
+ # Find server agents with math capability
340
+ GET /agents/discover?capabilities=math&type=server
341
+
342
+ # Paginated results
343
+ GET /agents/discover?limit=10&offset=20
344
+ ```
345
+
346
+ ## Testing Registry Operations
347
+
348
+ ### Unit Tests
349
+
350
+ ```ruby
351
+ require 'minitest/autorun'
352
+ require 'webmock/minitest'
353
+
354
+ class TestRegistryClient < Minitest::Test
355
+ def setup
356
+ @registry = Agent99::RegistryClient.new(
357
+ base_url: 'http://test-registry:4567'
358
+ )
359
+ end
360
+
361
+ def test_agent_registration
362
+ agent_info = {
363
+ name: "TestAgent",
364
+ type: "server",
365
+ capabilities: ["test"]
366
+ }
367
+
368
+ # Mock the HTTP request
369
+ stub_request(:post, "http://test-registry:4567/agents")
370
+ .with(body: agent_info.to_json)
371
+ .to_return(status: 201, body: '{"status": "registered"}')
372
+
373
+ result = @registry.register_agent(agent_info)
374
+ assert_equal "registered", result["status"]
375
+ end
376
+
377
+ def test_agent_discovery
378
+ # Mock discovery response
379
+ response_body = {
380
+ agents: [
381
+ { name: "TestAgent", capabilities: ["test"] }
382
+ ]
383
+ }.to_json
384
+
385
+ stub_request(:get, "http://test-registry:4567/agents/discover")
386
+ .with(query: { capabilities: "test" })
387
+ .to_return(status: 200, body: response_body)
388
+
389
+ agents = @registry.discover_agents(["test"])
390
+ assert_equal 1, agents.size
391
+ assert_equal "TestAgent", agents.first["name"]
392
+ end
393
+ end
394
+ ```
395
+
396
+ ### Integration Tests
397
+
398
+ ```ruby
399
+ class TestRegistryIntegration < Minitest::Test
400
+ def setup
401
+ # Start test registry server
402
+ @registry_server = start_test_registry
403
+ @registry = Agent99::RegistryClient.new(
404
+ base_url: 'http://localhost:4567'
405
+ )
406
+ end
407
+
408
+ def teardown
409
+ @registry_server.stop
410
+ end
411
+
412
+ def test_full_agent_lifecycle
413
+ agent_info = {
414
+ name: "IntegrationTestAgent",
415
+ type: "server",
416
+ capabilities: ["integration", "test"]
417
+ }
418
+
419
+ # Register agent
420
+ @registry.register_agent(agent_info)
421
+
422
+ # Verify registration
423
+ found_agents = @registry.discover_agents(["integration"])
424
+ assert_equal 1, found_agents.size
425
+
426
+ # Get agent details
427
+ agent_details = @registry.get_agent("IntegrationTestAgent")
428
+ assert_equal "server", agent_details["type"]
429
+
430
+ # Unregister agent
431
+ @registry.unregister_agent("IntegrationTestAgent")
432
+
433
+ # Verify removal
434
+ found_agents = @registry.discover_agents(["integration"])
435
+ assert_empty found_agents
436
+ end
437
+ end
438
+ ```
439
+
440
+ ## Best Practices
441
+
442
+ ### 1. Registration
443
+ - **Use descriptive names**: Include service purpose and instance info
444
+ - **Provide rich metadata**: Version, region, capabilities
445
+ - **Handle registration failures**: Retry with backoff
446
+ - **Clean up on shutdown**: Always unregister agents
447
+
448
+ ### 2. Discovery
449
+ - **Cache results**: Don't discover on every request
450
+ - **Handle empty results**: Plan for no matching agents
451
+ - **Use specific capabilities**: More specific = better matches
452
+ - **Implement fallbacks**: Have backup discovery strategies
453
+
454
+ ### 3. Error Handling
455
+ - **Catch specific exceptions**: Handle different error types appropriately
456
+ - **Implement retries**: With exponential backoff
457
+ - **Monitor registry health**: Check before critical operations
458
+ - **Log registry operations**: For debugging and monitoring
459
+
460
+ ### 4. Performance
461
+ - **Batch operations**: When possible, batch registry calls
462
+ - **Use connection pooling**: For high-frequency operations
463
+ - **Monitor response times**: Track registry performance
464
+ - **Implement circuit breakers**: Protect against registry failures
465
+
466
+ ## Next Steps
467
+
468
+ - **[Message Clients](message-clients.md)** - Message broker client APIs
469
+ - **[Agent99::Base](agent99-base.md)** - Core agent class reference
470
+ - **[Configuration](../operations/configuration.md)** - Registry configuration options