@peebles-group/agentlib-js 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/Agent.js +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peebles-group/agentlib-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A minimal JavaScript library implementing concurrent async agents for illustrating multi-agent systems and other agentic design patterns including recursive ones purely through function calling loops.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/src/Agent.js
CHANGED
|
@@ -31,6 +31,38 @@ export class Agent {
|
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Add a native tool at runtime
|
|
36
|
+
* Expected shape: { name: string, description?: string, func: (args) => Promise<any> | any }
|
|
37
|
+
*/
|
|
38
|
+
addTool(tool) {
|
|
39
|
+
if (!tool || typeof tool !== 'object') {
|
|
40
|
+
throw new Error("Invalid tool: expected an object");
|
|
41
|
+
}
|
|
42
|
+
const { name, func } = tool;
|
|
43
|
+
if (typeof name !== 'string' || name.trim() === '') {
|
|
44
|
+
throw new Error("Invalid tool: missing valid 'name' (string)");
|
|
45
|
+
}
|
|
46
|
+
if (typeof func !== 'function') {
|
|
47
|
+
throw new Error("Invalid tool: missing 'func' (function)");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Prevent name collisions across native and MCP tools
|
|
51
|
+
const nameExistsInNative = this.nativeTools.some(t => t && t.name === name);
|
|
52
|
+
const nameExistsInMCP = this.mcpManager ? this.mcpManager.getAllTools().some(t => t && t.name === name) : false;
|
|
53
|
+
if (nameExistsInNative || nameExistsInMCP) {
|
|
54
|
+
throw new Error(`Tool with name '${name}' already exists`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof tool.description !== 'string') {
|
|
58
|
+
tool.description = '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.nativeTools.push(tool);
|
|
62
|
+
this.updateSystemPrompt();
|
|
63
|
+
return tool;
|
|
64
|
+
}
|
|
65
|
+
|
|
34
66
|
getAllTools() {
|
|
35
67
|
const mcpTools = this.mcpManager ? this.mcpManager.getAllTools() : [];
|
|
36
68
|
return [...this.nativeTools, ...mcpTools];
|