agent99 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -1
- data/README.md +34 -26
- data/docs/README.md +57 -0
- data/docs/advanced_features.md +115 -0
- data/docs/agent99_framework/central_registry.md +94 -0
- data/docs/agent99_framework/message_client.md +120 -0
- data/docs/agent99_framework/registry_client.md +119 -0
- data/docs/agent_discovery.md +66 -0
- data/docs/agent_lifecycle.md +137 -0
- data/docs/agent_registry_processes.md +108 -0
- data/docs/api_reference.md +146 -0
- data/docs/architecture.md +77 -0
- data/docs/breaking_change_v0.0.4.md +26 -0
- data/docs/configuration.md +17 -0
- data/docs/control_actions.md +179 -0
- data/docs/custom_agent_implementation.md +30 -0
- data/docs/diagrams/agent_registry_processes.dot +42 -0
- data/docs/diagrams/agent_registry_processes.png +0 -0
- data/docs/diagrams/high_level_architecture.dot +26 -0
- data/docs/diagrams/high_level_architecture.png +0 -0
- data/docs/diagrams/request_flow.dot +42 -0
- data/docs/diagrams/request_flow.png +0 -0
- data/docs/error_handling_and_logging.md +13 -0
- data/docs/extending_the_framework.md +11 -0
- data/docs/message_processing.md +165 -0
- data/docs/messaging_system.md +129 -0
- data/docs/preformance_considerations.md +9 -0
- data/docs/schema_definition.md +78 -0
- data/docs/security.md +9 -0
- data/docs/troubleshooting.md +11 -0
- data/docs/what_is_an_agent.md +293 -0
- data/examples/README.md +43 -0
- data/examples/agent_watcher.rb +106 -0
- data/examples/agents/.keep +0 -0
- data/examples/chief_agent.rb +17 -6
- data/examples/control.rb +16 -7
- data/examples/example_agent.rb +39 -0
- data/examples/kaos_spy.rb +63 -0
- data/examples/maxwell_agent86.rb +15 -26
- data/examples/registry.rb +24 -13
- data/lib/agent99/agent_discovery.rb +4 -0
- data/lib/agent99/agent_lifecycle.rb +34 -10
- data/lib/agent99/base.rb +5 -1
- data/lib/agent99/header_schema.rb +5 -0
- data/lib/agent99/message_processing.rb +3 -1
- data/lib/agent99/registry_client.rb +12 -11
- data/lib/agent99/tcp_message_client.rb +183 -0
- data/lib/agent99/version.rb +1 -1
- metadata +50 -3
- data/docs/todo.md +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1821eef1dcc40dde4e8b93a553728086ab5217020c7635bef4c993a437c88a24
|
4
|
+
data.tar.gz: 8f2b26e50c28c257728cc5dc0b2eb6712b02b1eb3286fd3a1185e5517eef5ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cce04381c30134bc1058d69e6c4090ed12551974884b3e71b5871ed483b81a24fd028b9fb142e48ae51ab60236c1a5c404522bd431d4309285c5a3d42102c9bd
|
7
|
+
data.tar.gz: 28e77a074b28f3cc3b8106bb4ba6faaedcbf7ad7215ea03b261aabdaee5560874ed57155af956a035b0e42814cf37c1a9d42e459086edbb72e93c94d1740b9ac
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,32 @@
|
|
1
|
-
|
1
|
+
# The Changelog
|
2
2
|
|
3
|
+
## [Unreleased]
|
3
4
|
|
4
5
|
## Released
|
5
6
|
|
7
|
+
### [0.0.4] 2024-12-14
|
8
|
+
|
9
|
+
- This is a [breaking change](docs/breaking_change_v0.0.4.md)
|
10
|
+
- Replaced the capabilities method with the info method so that lots of stuff can be incorporated into an agent's information packet maintained by the registry.
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
### [0.0.3] - 2024-12-08
|
15
|
+
|
16
|
+
- Document advanced features and update examples
|
17
|
+
- Add AgentWatcher and ExampleAgent implementations
|
18
|
+
- Update control actions documentation for Agent99
|
19
|
+
- Add request flow diagram and update messaging docs
|
20
|
+
- Update schema documentation for improved clarity
|
21
|
+
- Reorganize documentation and update architecture details
|
22
|
+
- Update API reference with detailed implementation guidelines
|
23
|
+
- Extend agent lifecycle documentation
|
24
|
+
- Enhance agent discovery documentation and registry logic
|
25
|
+
- Add KaosSpy example agent
|
26
|
+
- Update README links to lowercase for consistency
|
27
|
+
- Add documentation for Agent99 framework
|
28
|
+
- Add Sinatra dependency and document registry processes
|
29
|
+
|
6
30
|
### [0.0.2] - 2024-12-07
|
7
31
|
|
8
32
|
- Added examples/control.rb
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Agent99
|
1
|
+
# Agent99
|
2
2
|
|
3
|
-
**Under Development** Initial release has no AI components - its just a generic client-server / request-response micro-services system using a peer-to-peer messaging broker and a centralized agent registry.
|
3
|
+
**Under Development** Initial release has no AI components - its just a generic client-server / request-response micro-services system using a peer-to-peer messaging broker and a centralized agent registry. To keep up with the version changes review [The Changelog](./CHANGELOG.md) file.
|
4
|
+
|
5
|
+
v0.0.4 has a [breaking_change.](docs/breaking_change_v0.0.4.md)
|
4
6
|
|
5
7
|
Agent99 is a Ruby-based framework for building and managing AI agents in a distributed system. It provides a robust foundation for creating intelligent agents that can communicate, discover each other, and perform various tasks.
|
6
8
|
|
@@ -55,6 +57,8 @@ Whether you’re a seasoned Ruby developer or just getting started, Agent99 prov
|
|
55
57
|
- Registry Integration: Register and discover agents through a central registry
|
56
58
|
- Error Handling and Logging: Built-in error management and logging capabilities
|
57
59
|
- Control Actions: Pause, resume, update configuration, and request status of agents
|
60
|
+
- Dynamic Agent Loading: Support for runtime loading and deployment of new agents
|
61
|
+
- Multi-Agent Processing: Run multiple agents within the same process using thread isolation
|
58
62
|
|
59
63
|
## Installation
|
60
64
|
|
@@ -83,39 +87,36 @@ Here's a basic example of how to create an AI agent:
|
|
83
87
|
```ruby
|
84
88
|
require 'agent99'
|
85
89
|
|
86
|
-
class
|
90
|
+
class GreeterRequest < SimpleJsonSchemaBuilder::Base
|
87
91
|
object do
|
88
92
|
object :header, schema: Agent99::HeaderSchema
|
89
|
-
|
90
|
-
# Define your agents parameters ....
|
91
|
-
string :greeting, required: false, examples: ["Hello"]
|
92
|
-
string :name, required: true, examples: ["World"]
|
93
|
+
string :name, required: true, examples: ["World"]
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
class
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
class GreeterAgent < Agent99::Base
|
98
|
+
def info
|
99
|
+
{
|
100
|
+
name: self.class.to_s,
|
101
|
+
type: :server,
|
102
|
+
capabilities: ['greeter', 'hello_world'],
|
103
|
+
request_schema: GreeterRequest.schema,
|
104
|
+
# Uncomment and define these schemas as needed:
|
105
|
+
# response_schema: {}, # Agent99::RESPONSE.schema
|
106
|
+
# control_schema: {}, # Agent99::CONTROL.schema
|
107
|
+
# error_schema: {}, # Agent99::ERROR.schema
|
108
|
+
}
|
102
109
|
end
|
103
110
|
|
104
|
-
def
|
105
|
-
|
106
|
-
response
|
107
|
-
|
108
|
-
# Not every request needs a response
|
111
|
+
def process_request(payload)
|
112
|
+
name = payload.dig(:name)
|
113
|
+
response = { result: "Hello, #{name}!" }
|
109
114
|
send_response(response)
|
110
115
|
end
|
111
|
-
|
112
|
-
def receive_response
|
113
|
-
# You sent a request to another agent
|
114
|
-
# now handle the response.
|
115
|
-
end
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
# Create and run the agent
|
119
|
+
agent = GreeterAgent.new
|
119
120
|
agent.run
|
120
121
|
```
|
121
122
|
|
@@ -123,7 +124,14 @@ agent.run
|
|
123
124
|
|
124
125
|
The framework can be configured through environment variables:
|
125
126
|
|
126
|
-
- `
|
127
|
+
- `AGENT99_REGISTRY_URL`: URL of the agent registry service (default: 'http://localhost:4567')
|
128
|
+
|
129
|
+
Depending on which messaging client you are using, additional environment variables may be used.
|
130
|
+
|
131
|
+
TODO: show envars for AMQP via Bunny
|
132
|
+
TODO: show envars for NATS via nats0server
|
133
|
+
|
134
|
+
See the examples folder for a default registry service implementation.
|
127
135
|
|
128
136
|
## Contributing
|
129
137
|
|
@@ -138,4 +146,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/MadBom
|
|
138
146
|
|
139
147
|
## License
|
140
148
|
|
141
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
149
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/docs/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Agent99 Framework Documentation
|
2
|
+
|
3
|
+
Welcome to the Agent99 Framework documentation! Below is a table of contents and brief summaries of each markdown file available in this directory. Explore each document for more detailed information on the Agent99 Framework and how to effectively utilize it in your projects!
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
|
7
|
+
1. **[Agent Discovery](agent_discovery.md)**
|
8
|
+
- This document explains how agents within the Agent99 framework discover each other based on their declared capabilities, including the registration and querying processes involved.
|
9
|
+
|
10
|
+
2. **[Agent Lifecycle](agent_lifecycle.md)**
|
11
|
+
- Learn about the various stages an agent undergoes during its lifetime, from creation and initialization to running and graceful shutdown.
|
12
|
+
|
13
|
+
3. **[Agent Registry Processes](agent_registry_processes.md)**
|
14
|
+
- This file details the processes handled by the Agent registry, including registration, discovery, and withdrawal of agents, along with example code to illustrate these concepts.
|
15
|
+
|
16
|
+
4. **[API Reference](api_reference.md)**
|
17
|
+
- The API Reference provides comprehensive details about public methods and classes within Agent99, ensuring developers can leverage its full capabilities.
|
18
|
+
|
19
|
+
5. **[Architecture Overview](architecture_overview.md)**
|
20
|
+
- An overview of the architecture of Agent99, describing its microservices-oriented structure, communication workflows, and how agents operate within the system.
|
21
|
+
|
22
|
+
6. **[Configuration](configuration.md)**
|
23
|
+
- Discover how to configure agents using environment variables, including important settings such as the registry base URL.
|
24
|
+
|
25
|
+
7. **[Control Actions](control_actions.md)**
|
26
|
+
- This document lists the control actions available to agents, such as shutdown, pause, and resume, along with instructions on how to create custom actions.
|
27
|
+
|
28
|
+
8. **[Custom Agent Implementation](custom_agent_implementation.md)**
|
29
|
+
- Guidelines on creating custom agents, including subclassing, defining schemas, and implementing request and response handling.
|
30
|
+
|
31
|
+
9. **[Error Handling and Logging](error_handling_and_logging.md)**
|
32
|
+
- Understanding the error handling mechanisms in Agent99, as well as how to configure logging for better monitoring and debugging.
|
33
|
+
|
34
|
+
10. **[Extending the Framework](extending_the_framework.md)**
|
35
|
+
- Instructions on how to extend Agent99 by implementing custom modules, defining new message types, and using hooks for additional functionality.
|
36
|
+
|
37
|
+
11. **[Message Processing](message_processing.md)**
|
38
|
+
- This document outlines the different message types supported by Agent99, how they are processed, and the importance of schema validation.
|
39
|
+
|
40
|
+
12. **[Messaging Systems](messaging_systems.md)**
|
41
|
+
- Overview of the messaging protocols supported by Agent99, including AMQP and NATS, and guidance on how to switch between them.
|
42
|
+
|
43
|
+
13. **[Advanced Features](advanced_features.md)**
|
44
|
+
- Learn about dynamic agent loading, multi-agent processing, and best practices for running multiple agents within the same process.
|
45
|
+
|
46
|
+
14. **[Performance Considerations](performance_considerations.md)**
|
47
|
+
- Best practices for ensuring optimal performance within the framework, including optimization techniques and profiling performance.
|
48
|
+
|
49
|
+
15. **[Schema Definition](schema_definition.md)**
|
50
|
+
- Detailed instructions on how to define schemas using `SimpleJsonSchemaBuilder`, with examples to guide you through the process.
|
51
|
+
|
52
|
+
16. **[Security](security.md)**
|
53
|
+
- Recommendations on implementing security measures within Agent99, focusing on message encryption and access control.
|
54
|
+
|
55
|
+
17. **[Troubleshooting](troubleshooting.md)**
|
56
|
+
- Common issues encountered while using Agent99 and suggested steps for debugging, including examining logs and configuration settings.
|
57
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Agent99 Framework
|
2
|
+
|
3
|
+
## Advanced Features
|
4
|
+
|
5
|
+
Ruby supports dynamic loading and deployment of libraries at runtime. Agent99 takes advantage of this ability through the `AgentWatcher` system. This powerful feature allows you to:
|
6
|
+
|
7
|
+
- Monitor a directory for new agent files
|
8
|
+
- Automatically load and instantiate new agents when detected
|
9
|
+
- Run multiple agents within the same process
|
10
|
+
- Manage agent lifecycle independently
|
11
|
+
|
12
|
+
### Using AgentWatcher
|
13
|
+
|
14
|
+
The `AgentWatcher` (found in `examples/agent_watcher.rb`) provides a framework for dynamically loading and running agents:
|
15
|
+
|
16
|
+
1. Start the AgentWatcher:
|
17
|
+
```ruby
|
18
|
+
watcher = AgentWatcher.new
|
19
|
+
watcher.run
|
20
|
+
```
|
21
|
+
|
22
|
+
2. Deploy new agents by copying their .rb files to the watched directory (default: './agents'):
|
23
|
+
```bash
|
24
|
+
cp my_new_agent.rb agents/
|
25
|
+
```
|
26
|
+
|
27
|
+
The AgentWatcher will:
|
28
|
+
- Detect the new file
|
29
|
+
- Load the agent class
|
30
|
+
- Instantiate the agent
|
31
|
+
- Run it in a separate thread
|
32
|
+
|
33
|
+
### Example Implementation
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class MyDynamicAgent < Agent99::Base
|
37
|
+
def info
|
38
|
+
{
|
39
|
+
# ...
|
40
|
+
type: :server,
|
41
|
+
capabilities: ['my_capability'],
|
42
|
+
# ...
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def receive_request
|
47
|
+
# Handle requests
|
48
|
+
send_response(status: 'success')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
## Multi-Agent Processing
|
54
|
+
|
55
|
+
Agent99 supports running multiple agents within the same process, with each agent running in its own thread. This approach:
|
56
|
+
|
57
|
+
- Reduces resource overhead compared to separate processes
|
58
|
+
- Maintains isolation between agents
|
59
|
+
- Allows efficient inter-agent communication
|
60
|
+
- Simplifies agent management
|
61
|
+
|
62
|
+
### Benefits
|
63
|
+
|
64
|
+
1. **Resource Efficiency**: Share common resources while maintaining agent isolation
|
65
|
+
2. **Simplified Deployment**: Manage multiple agents through a single process
|
66
|
+
3. **Enhanced Communication**: Direct inter-agent communication within the same process
|
67
|
+
4. **Centralized Management**: Monitor and control multiple agents from a single point
|
68
|
+
|
69
|
+
### Implementation Considerations
|
70
|
+
|
71
|
+
When running multiple agents in the same process:
|
72
|
+
|
73
|
+
1. Each agent runs in its own thread for isolation
|
74
|
+
2. Agents can still communicate through the standard messaging system
|
75
|
+
3. Errors in one agent won't affect others
|
76
|
+
4. Resource sharing is handled automatically by the framework
|
77
|
+
|
78
|
+
### Example Setup
|
79
|
+
|
80
|
+
Using AgentWatcher to manage multiple agents:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Start the watcher
|
84
|
+
watcher = AgentWatcher.new
|
85
|
+
watcher.run
|
86
|
+
|
87
|
+
# Deploy multiple agents
|
88
|
+
cp agent1.rb agents/
|
89
|
+
cp agent2.rb agents/
|
90
|
+
cp agent3.rb agents/
|
91
|
+
```
|
92
|
+
|
93
|
+
Each agent will run independently in its own thread while sharing the same process space.
|
94
|
+
|
95
|
+
## Best Practices
|
96
|
+
|
97
|
+
1. **Error Handling**
|
98
|
+
- Implement proper error handling in each agent
|
99
|
+
- Use the built-in logging system
|
100
|
+
- Monitor agent health through status checks
|
101
|
+
|
102
|
+
2. **Resource Management**
|
103
|
+
- Monitor memory usage when running many agents
|
104
|
+
- Implement proper cleanup in the `fini` method
|
105
|
+
- Use appropriate thread pool sizes
|
106
|
+
|
107
|
+
3. **Deployment**
|
108
|
+
- Use meaningful file names for easy identification
|
109
|
+
- Maintain clear separation of concerns between agents
|
110
|
+
- Document agent dependencies and requirements
|
111
|
+
|
112
|
+
4. **Monitoring**
|
113
|
+
- Implement health checks in your agents
|
114
|
+
- Use logging for debugging and monitoring
|
115
|
+
- Set up appropriate alerting for critical agents
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Central Registry
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
The Central Registry is a crucial component of the Agent99 Framework, serving as a centralized hub for agent registration, discovery, and management. Its primary purpose is to facilitate communication and coordination between various agents within the framework, allowing them to register their capabilities and discover other agents with specific skills.
|
6
|
+
|
7
|
+
The registry provides a RESTful API that can be implemented in any programming language or web framework that supports HTTPS endpoints. This document outlines the API specifications for implementing a compatible Central Registry.
|
8
|
+
|
9
|
+
## API Endpoints
|
10
|
+
|
11
|
+
### 1. Health Check
|
12
|
+
|
13
|
+
- **Endpoint**: GET /healthcheck
|
14
|
+
- **Purpose**: Provides a simple health check for the registry service.
|
15
|
+
- **Response**: JSON object containing the current count of registered agents.
|
16
|
+
- **Example Response**:
|
17
|
+
```json
|
18
|
+
{
|
19
|
+
"agent_count": 5
|
20
|
+
}
|
21
|
+
```
|
22
|
+
|
23
|
+
### 2. Register Agent
|
24
|
+
|
25
|
+
- **Endpoint**: POST /register
|
26
|
+
- **Purpose**: Allows an agent to register itself with the registry, providing its name and capabilities.
|
27
|
+
- **Request Body**: JSON object containing agent information.
|
28
|
+
- **Response**: JSON object with a newly generated UUID for the registered agent.
|
29
|
+
- **Example Request**:
|
30
|
+
```json
|
31
|
+
{
|
32
|
+
"name": "TextAnalyzer",
|
33
|
+
"capabilities": ["sentiment analysis", "named entity recognition"]
|
34
|
+
}
|
35
|
+
```
|
36
|
+
- **Example Response**:
|
37
|
+
```json
|
38
|
+
{
|
39
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000"
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
### 3. Discover Agents
|
44
|
+
|
45
|
+
- **Endpoint**: GET /discover
|
46
|
+
- **Purpose**: Allows discovery of agents based on a specific capability.
|
47
|
+
- **Query Parameter**: capability (string)
|
48
|
+
- **Response**: JSON array of matching agents with their full information.
|
49
|
+
- **Example Request**: GET /discover?capability=sentiment+analysis
|
50
|
+
- **Example Response**:
|
51
|
+
```json
|
52
|
+
[
|
53
|
+
{
|
54
|
+
"name": "TextAnalyzer",
|
55
|
+
"capabilities": ["sentiment analysis", "named entity recognition"],
|
56
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000"
|
57
|
+
}
|
58
|
+
]
|
59
|
+
```
|
60
|
+
|
61
|
+
### 4. Withdraw Agent
|
62
|
+
|
63
|
+
- **Endpoint**: DELETE /withdraw/:uuid
|
64
|
+
- **Purpose**: Removes an agent from the registry using its UUID.
|
65
|
+
- **Response**:
|
66
|
+
- 204 No Content if successful
|
67
|
+
- 404 Not Found if the agent UUID is not in the registry
|
68
|
+
- **Example Request**: DELETE /withdraw/550e8400-e29b-41d4-a716-446655440000
|
69
|
+
|
70
|
+
### 5. List All Agents
|
71
|
+
|
72
|
+
- **Endpoint**: GET /
|
73
|
+
- **Purpose**: Retrieves a list of all registered agents.
|
74
|
+
- **Response**: JSON array containing all registered agents' information.
|
75
|
+
|
76
|
+
## Implementation Notes
|
77
|
+
|
78
|
+
1. Agent capabilities should be stored and compared in lowercase to ensure case-insensitive matching.
|
79
|
+
2. The current implementation uses an in-memory array to store agent information. For production use, consider using a persistent database like SQLite or a more scalable solution.
|
80
|
+
3. The discovery process currently uses simple keyword matching. Future enhancements could include semantic matching for more accurate agent discovery.
|
81
|
+
|
82
|
+
## Potential Enhancements
|
83
|
+
|
84
|
+
1. **Persistent Storage**: Implement a database backend for storing agent information, ensuring data persistence across server restarts.
|
85
|
+
2. **Authentication and Authorization**: Add security measures to protect sensitive endpoints and ensure only authorized agents can register or withdraw.
|
86
|
+
3. **Semantic Matching**: Enhance the discovery process with natural language processing or vector search capabilities for more intelligent agent matching.
|
87
|
+
4. **Agent Health Monitoring**: Implement periodic health checks on registered agents to ensure they are still active and available.
|
88
|
+
5. **Versioning**: Add support for agent versioning to manage different versions of agents with similar capabilities.
|
89
|
+
6. **Pagination**: Implement pagination for the discovery and list all endpoints to handle large numbers of agents efficiently.
|
90
|
+
7. **Metrics and Logging**: Add comprehensive logging and metrics collection for better monitoring and debugging of the registry service.
|
91
|
+
8. **API Rate Limiting**: Implement rate limiting to prevent abuse and ensure fair usage of the registry service.
|
92
|
+
|
93
|
+
By implementing this API, developers can create a compatible Central Registry for the Agent99 Framework in their preferred language or framework, enabling seamless integration and communication between diverse agents in the ecosystem.
|
94
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Message Client Documentation for Agent99 Framework
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
The Message Client is a crucial component of the Agent99 Framework, providing an interface for agents to communicate with each other through a message broker. This document outlines the required methods and functionalities that should be implemented in any message client to ensure compatibility with the Agent99 Framework.
|
6
|
+
|
7
|
+
## Message Format Requirements
|
8
|
+
|
9
|
+
All messages sent and received through the Agent99 Framework must adhere to the following format requirements:
|
10
|
+
|
11
|
+
1. **JSON Format**: All messages must be in JSON format. This ensures consistency and ease of parsing across different implementations and languages.
|
12
|
+
|
13
|
+
2. **Header Element**: Each message must include a `header` element that conforms to the `HeaderSchema` defined for the Agent99 Framework. The `HeaderSchema` is as follows:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class Agent99::HeaderSchema < SimpleJsonSchemaBuilder::Base
|
17
|
+
object do
|
18
|
+
string :from_uuid, required: true, examples: [SecureRandom.uuid]
|
19
|
+
string :to_uuid, required: true, examples: [SecureRandom.uuid]
|
20
|
+
string :event_uuid, required: true, examples: [SecureRandom.uuid]
|
21
|
+
string :type, required: true, examples: %w[request response control]
|
22
|
+
integer :timestamp, required: true, examples: [Agent99::Timestamp.new.to_i]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
3. **Message Types**: The `type` field in the header must be one of: `request`, `response`, or `control`.
|
28
|
+
|
29
|
+
4. **Validation**: All incoming messages are validated against the appropriate schema based on their type. If validation errors are found, an error response message is returned to the sender.
|
30
|
+
|
31
|
+
## Class: MessageClient
|
32
|
+
|
33
|
+
### Initialization
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
def initialize(config: {}, logger: Logger.new($stdout))
|
37
|
+
# Implementation details...
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Creates a new instance of the MessageClient.
|
42
|
+
|
43
|
+
- `config:` A hash containing configuration options for the message broker connection.
|
44
|
+
- `logger:` A logger instance for output (default: stdout logger).
|
45
|
+
|
46
|
+
### Public Methods
|
47
|
+
|
48
|
+
#### setup
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
def setup(agent_id:, logger:)
|
52
|
+
# Implementation details...
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Sets up the necessary resources for an agent to start communicating.
|
57
|
+
|
58
|
+
- `agent_id:` The unique identifier for the agent.
|
59
|
+
- `logger:` A logger instance for output.
|
60
|
+
- Returns: An object representing the agent's message queue or channel.
|
61
|
+
|
62
|
+
#### listen_for_messages
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
def listen_for_messages(
|
66
|
+
queue,
|
67
|
+
request_handler:,
|
68
|
+
response_handler:,
|
69
|
+
control_handler:
|
70
|
+
)
|
71
|
+
# Implementation details...
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Starts listening for incoming messages on the specified queue.
|
76
|
+
|
77
|
+
- `queue:` The queue or channel object returned by the `setup` method.
|
78
|
+
- `request_handler:` A callable object to handle incoming request messages.
|
79
|
+
- `response_handler:` A callable object to handle incoming response messages.
|
80
|
+
- `control_handler:` A callable object to handle incoming control messages.
|
81
|
+
|
82
|
+
#### publish
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
def publish(message:)
|
86
|
+
# Implementation details...
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
Publishes a message to the specified queue.
|
91
|
+
|
92
|
+
- `message:` A hash containing the message to be published. This must be in JSON format and include a header that conforms to the `HeaderSchema`.
|
93
|
+
- Returns: A hash indicating the success or failure of the publish operation, including details if the message structure is invalid.
|
94
|
+
|
95
|
+
#### delete_queue
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
def delete_queue(queue_name:)
|
99
|
+
# Implementation details...
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
Deletes the specified queue or cleans up resources associated with it.
|
104
|
+
|
105
|
+
- `queue_name:` The name of the queue to be deleted.
|
106
|
+
|
107
|
+
### Implementation Notes
|
108
|
+
|
109
|
+
1. **Message Validation**: Implement thorough validation for all incoming and outgoing messages. Ensure that they are in JSON format and contain a header that conforms to the `HeaderSchema`. If validation fails for incoming messages, send an error response to the sender with details about the validation issues.
|
110
|
+
|
111
|
+
2. **Error Handling**: Implement robust error handling for all methods, especially for connection, publishing, and validation errors.
|
112
|
+
|
113
|
+
3. **Logging**: Provide detailed logging for all operations, including successful actions, validation results, and errors.
|
114
|
+
|
115
|
+
4. **Performance and Scalability**: Optimize the client to handle a large number of JSON-formatted messages efficiently, considering potential performance impacts of validation.
|
116
|
+
|
117
|
+
5. **Thread Safety**: Ensure that the client is thread-safe, particularly when handling message validation and publishing.
|
118
|
+
|
119
|
+
By adhering to these requirements and implementing the MessageClient with these considerations, developers can ensure that their implementations will be fully compatible with the Agent99 Framework. The strict adherence to JSON formatting and the inclusion of a standardized header in all messages promotes consistency and reliability in inter-agent communication within the framework.
|
120
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# RegistryClient Documentation
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
The RegistryClient class is a crucial component of the Agent99 framework, providing a Ruby interface to interact with the Central Registry service. It encapsulates the HTTP communication logic required to register agents, discover capabilities, and manage agent lifecycle within the Agent99 ecosystem.
|
6
|
+
|
7
|
+
## Class: Agent99::RegistryClient
|
8
|
+
|
9
|
+
### Initialization
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
def initialize(base_url: ENV.fetch('REGISTRY_BASE_URL', 'http://localhost:4567'),
|
13
|
+
logger: Logger.new($stdout))
|
14
|
+
```
|
15
|
+
|
16
|
+
Creates a new instance of the RegistryClient.
|
17
|
+
|
18
|
+
- `base_url`: The URL of the Central Registry service (default: http://localhost:4567)
|
19
|
+
- `logger`: A logger instance for output (default: stdout logger)
|
20
|
+
|
21
|
+
### Public Methods
|
22
|
+
|
23
|
+
#### register
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
def register(name:, capabilities:)
|
27
|
+
```
|
28
|
+
|
29
|
+
Registers an agent with the Central Registry.
|
30
|
+
|
31
|
+
- `name`: The name of the agent
|
32
|
+
- `capabilities`: An array of capabilities the agent possesses
|
33
|
+
- Returns: The UUID of the registered agent
|
34
|
+
|
35
|
+
One of the first improvement that should be considered when registering a new agent is adding its JSON schema for its request and response messages. This way there should be no question about how to interface with the agent.
|
36
|
+
|
37
|
+
#### withdraw
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
def withdraw(id)
|
41
|
+
```
|
42
|
+
|
43
|
+
Withdraws an agent from the Central Registry.
|
44
|
+
|
45
|
+
- `id`: The UUID of the agent to withdraw
|
46
|
+
- Returns: nil
|
47
|
+
|
48
|
+
#### discover
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
def discover(capability:)
|
52
|
+
```
|
53
|
+
|
54
|
+
Discovers agents with a specific capability.
|
55
|
+
|
56
|
+
- `capability`: The capability to search for
|
57
|
+
- Returns: An array of agents matching the capability
|
58
|
+
|
59
|
+
#### fetch_all_agents
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
def fetch_all_agents
|
63
|
+
```
|
64
|
+
|
65
|
+
Retrieves all registered agents from the Central Registry.
|
66
|
+
|
67
|
+
- Returns: An array of all registered agents
|
68
|
+
|
69
|
+
### Private Methods
|
70
|
+
|
71
|
+
The class includes several private methods for handling HTTP requests and responses:
|
72
|
+
|
73
|
+
- `create_request`: Creates an HTTP request object
|
74
|
+
- `send_request`: Sends an HTTP request and handles exceptions
|
75
|
+
- `handle_response`: Processes the HTTP response based on its status code
|
76
|
+
|
77
|
+
## Usage Example
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
client = Agent99::RegistryClient.new
|
81
|
+
agent_id = client.register(name: "TextAnalyzer", capabilities: ["sentiment analysis", "named entity recognition"])
|
82
|
+
matching_agents = client.discover(capability: "sentiment analysis")
|
83
|
+
client.withdraw(agent_id)
|
84
|
+
```
|
85
|
+
|
86
|
+
## Potential Improvements
|
87
|
+
|
88
|
+
1. **Error Handling**: Implement more granular error handling and custom exceptions for different types of failures (e.g., network errors, authentication errors).
|
89
|
+
|
90
|
+
2. **Retry Mechanism**: Add a retry mechanism for transient failures, potentially using a library like `retriable`.
|
91
|
+
|
92
|
+
3. **Connection Pooling**: Implement connection pooling to improve performance when making multiple requests.
|
93
|
+
|
94
|
+
4. **Caching**: Add caching for frequently accessed data, such as the list of all agents or common capability searches.
|
95
|
+
|
96
|
+
5. **Asynchronous Operations**: Provide asynchronous versions of methods for non-blocking operations, possibly using Ruby's `async`/`await` syntax or a library like `concurrent-ruby`.
|
97
|
+
|
98
|
+
6. **Pagination Support**: Implement pagination for methods that return potentially large datasets, such as `fetch_all_agents`.
|
99
|
+
|
100
|
+
7. **Capability Normalization**: Normalize capabilities (e.g., lowercase, remove whitespace) before sending to ensure consistent matching.
|
101
|
+
|
102
|
+
8. **Batch Operations**: Add support for batch registration or withdrawal of multiple agents in a single request.
|
103
|
+
|
104
|
+
9. **Logging Enhancements**: Improve logging to include more detailed information about requests and responses for better debugging.
|
105
|
+
|
106
|
+
10. **Configuration Options**: Allow more configuration options, such as timeout settings, custom headers, or SSL/TLS options.
|
107
|
+
|
108
|
+
11. **Capability Validation**: Implement client-side validation of capabilities before sending requests to the server.
|
109
|
+
|
110
|
+
12. **Agent Status Updates**: Add methods to update an agent's status or capabilities without full re-registration.
|
111
|
+
|
112
|
+
13. **Metrics Collection**: Integrate with a metrics library to collect and report on API usage and performance.
|
113
|
+
|
114
|
+
14. **Authentication Support**: Add support for authentication mechanisms if the Central Registry implements them in the future.
|
115
|
+
|
116
|
+
15. **API Versioning**: Implement support for API versioning to handle potential future changes in the Central Registry API.
|
117
|
+
|
118
|
+
By implementing these improvements, the RegistryClient can become more robust, efficient, and feature-rich, enhancing its utility within the Agent99 framework.
|
119
|
+
|