@peebles-group/agentlib-js 1.0.1 → 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/README.md +16 -12
- package/package.json +1 -1
- package/src/Agent.js +32 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A lightweight Node.js library for building AI agents with LLM providers and MCP
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install peebles-agentlib
|
|
8
|
+
npm install @peebles-group/agentlib-js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
@@ -22,7 +22,7 @@ npm install peebles-agentlib
|
|
|
22
22
|
mkdir my-agent-project
|
|
23
23
|
cd my-agent-project
|
|
24
24
|
npm init -y
|
|
25
|
-
npm install peebles-agentlib dotenv
|
|
25
|
+
npm install @peebles-group/agentlib-js dotenv
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## Features
|
|
@@ -36,10 +36,13 @@ npm install peebles-agentlib
|
|
|
36
36
|
## Basic Usage
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
|
-
import { Agent } from 'peebles-agentlib';
|
|
39
|
+
import { Agent, LLMService } from '@peebles-group/agentlib-js';
|
|
40
40
|
import dotenv from 'dotenv';
|
|
41
41
|
dotenv.config();
|
|
42
42
|
|
|
43
|
+
// Initialize LLM service for direct tasks
|
|
44
|
+
const llm = new LLMService('openai', process.env.OPENAI_API_KEY);
|
|
45
|
+
|
|
43
46
|
// Simple agent
|
|
44
47
|
const agent = new Agent('openai', process.env.OPENAI_API_KEY, {
|
|
45
48
|
model: 'gpt-4o-mini'
|
|
@@ -66,7 +69,7 @@ await mcpAgent.addMCPServer('browser', {
|
|
|
66
69
|
AgentLib supports type-safe structured outputs using Zod schemas for reliable JSON responses.
|
|
67
70
|
|
|
68
71
|
```javascript
|
|
69
|
-
import { Agent } from 'peebles-agentlib';
|
|
72
|
+
import { Agent } from '@peebles-group/agentlib-js';
|
|
70
73
|
import { z } from 'zod';
|
|
71
74
|
import dotenv from 'dotenv';
|
|
72
75
|
dotenv.config();
|
|
@@ -112,7 +115,7 @@ The repository includes several development examples that demonstrate different
|
|
|
112
115
|
|
|
113
116
|
```javascript
|
|
114
117
|
// In your project
|
|
115
|
-
import { Agent } from 'peebles-agentlib';
|
|
118
|
+
import { Agent } from '@peebles-group/agentlib-js';
|
|
116
119
|
|
|
117
120
|
// Instead of (development only)
|
|
118
121
|
import { Agent } from './src/Agent.js';
|
|
@@ -137,7 +140,7 @@ const agent = new Agent(provider, apiKey, options);
|
|
|
137
140
|
|
|
138
141
|
**Example:**
|
|
139
142
|
```javascript
|
|
140
|
-
import { Agent } from 'peebles-agentlib';
|
|
143
|
+
import { Agent } from '@peebles-group/agentlib-js';
|
|
141
144
|
|
|
142
145
|
const agent = new Agent('openai', process.env.OPENAI_API_KEY, {
|
|
143
146
|
model: 'gpt-4o-mini',
|
|
@@ -187,12 +190,13 @@ When calling an LLM, the result object has the following structure:
|
|
|
187
190
|
]
|
|
188
191
|
},
|
|
189
192
|
{
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
id: 'fc_0c7a9f052c2a6aec0068fa6e20bca0819abbc24ec38aad74dc',
|
|
194
|
+
type: 'function_call',
|
|
195
|
+
status: 'completed',
|
|
196
|
+
arguments: '{"element":"Our Menu","ref":"e222","doubleClick":false,"button":"left","modifiers":[]}',
|
|
197
|
+
call_id: 'call_iBNFPVHDsSH1UUGUIUM5uvCE',
|
|
198
|
+
name: 'browser_click'
|
|
199
|
+
}
|
|
196
200
|
],
|
|
197
201
|
"parallel_tool_calls": true,
|
|
198
202
|
"previous_response_id": null,
|
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];
|