agntx 1.0.0
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.
- package/README.md +55 -0
- package/index.js +57 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AgentHub
|
|
2
|
+
|
|
3
|
+
A simple utility hub for agent-based workflows.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install agenthub
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { createAgent, log } = require('agenthub');
|
|
15
|
+
|
|
16
|
+
// Create a new agent
|
|
17
|
+
const agent = createAgent({
|
|
18
|
+
name: 'my-agent',
|
|
19
|
+
description: 'A sample agent'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Execute a task
|
|
23
|
+
agent.execute(async (ctx) => {
|
|
24
|
+
log('info', `Agent ${ctx.name} is running`);
|
|
25
|
+
return 'Task completed';
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
### `createAgent(config)`
|
|
32
|
+
|
|
33
|
+
Creates a new agent with the given configuration.
|
|
34
|
+
|
|
35
|
+
- `config.name` (string): The name of the agent
|
|
36
|
+
- `config.description` (string, optional): Description of the agent
|
|
37
|
+
|
|
38
|
+
Returns an agent object with:
|
|
39
|
+
- `name`: Agent name
|
|
40
|
+
- `description`: Agent description
|
|
41
|
+
- `id`: Unique identifier
|
|
42
|
+
- `createdAt`: Creation timestamp
|
|
43
|
+
- `execute(task)`: Method to execute tasks
|
|
44
|
+
|
|
45
|
+
### `log(level, message, meta)`
|
|
46
|
+
|
|
47
|
+
Simple logging utility.
|
|
48
|
+
|
|
49
|
+
- `level` (string): Log level ('info', 'warn', 'error')
|
|
50
|
+
- `message` (string): The message to log
|
|
51
|
+
- `meta` (object, optional): Additional metadata
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentHub - A simple utility hub for agent-based workflows
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new agent with the given configuration
|
|
7
|
+
* @param {Object} config - Agent configuration
|
|
8
|
+
* @param {string} config.name - The name of the agent
|
|
9
|
+
* @param {string} [config.description] - Optional description
|
|
10
|
+
* @returns {Object} The created agent object
|
|
11
|
+
*/
|
|
12
|
+
function createAgent(config = {}) {
|
|
13
|
+
const { name = 'default-agent', description = '' } = config;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
description,
|
|
18
|
+
id: `agent_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
19
|
+
createdAt: new Date().toISOString(),
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Execute a task with this agent
|
|
23
|
+
* @param {Function} task - The task function to execute
|
|
24
|
+
* @returns {Promise} The result of the task
|
|
25
|
+
*/
|
|
26
|
+
async execute(task) {
|
|
27
|
+
if (typeof task !== 'function') {
|
|
28
|
+
throw new Error('Task must be a function');
|
|
29
|
+
}
|
|
30
|
+
return await task(this);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Simple logger utility for agents
|
|
37
|
+
* @param {string} level - Log level (info, warn, error)
|
|
38
|
+
* @param {string} message - The message to log
|
|
39
|
+
* @param {Object} [meta] - Optional metadata
|
|
40
|
+
*/
|
|
41
|
+
function log(level, message, meta = {}) {
|
|
42
|
+
const timestamp = new Date().toISOString();
|
|
43
|
+
const logEntry = {
|
|
44
|
+
timestamp,
|
|
45
|
+
level,
|
|
46
|
+
message,
|
|
47
|
+
...meta
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
console.log(JSON.stringify(logEntry));
|
|
51
|
+
return logEntry;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
createAgent,
|
|
56
|
+
log
|
|
57
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agntx",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple utility hub for agent-based workflows",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"agent",
|
|
11
|
+
"hub",
|
|
12
|
+
"utility"
|
|
13
|
+
],
|
|
14
|
+
"author": "mikemajara",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/miguelalcalde/agenthub.git"
|
|
19
|
+
}
|
|
20
|
+
}
|