@agentforge/patterns 0.12.0 → 0.12.1
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/LICENSE +22 -0
- package/README.md +59 -43
- package/package.json +15 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Tom Van Schoor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -156,7 +156,8 @@ const searchTool = {
|
|
|
156
156
|
name: 'search',
|
|
157
157
|
description: 'Search for information',
|
|
158
158
|
schema: z.object({ query: z.string() }),
|
|
159
|
-
|
|
159
|
+
metadata: { category: 'search' },
|
|
160
|
+
invoke: async ({ query }) => {
|
|
160
161
|
// Search implementation
|
|
161
162
|
return { results: [...] };
|
|
162
163
|
},
|
|
@@ -166,7 +167,8 @@ const analyzeTool = {
|
|
|
166
167
|
name: 'analyze',
|
|
167
168
|
description: 'Analyze data',
|
|
168
169
|
schema: z.object({ data: z.any() }),
|
|
169
|
-
|
|
170
|
+
metadata: { category: 'utility' },
|
|
171
|
+
invoke: async ({ data }) => {
|
|
170
172
|
// Analysis implementation
|
|
171
173
|
return { insights: [...] };
|
|
172
174
|
},
|
|
@@ -175,7 +177,7 @@ const analyzeTool = {
|
|
|
175
177
|
// Create the agent
|
|
176
178
|
const agent = createPlanExecuteAgent({
|
|
177
179
|
planner: {
|
|
178
|
-
|
|
180
|
+
model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
179
181
|
maxSteps: 5,
|
|
180
182
|
},
|
|
181
183
|
executor: {
|
|
@@ -183,7 +185,7 @@ const agent = createPlanExecuteAgent({
|
|
|
183
185
|
parallel: true, // Enable parallel execution
|
|
184
186
|
},
|
|
185
187
|
replanner: {
|
|
186
|
-
|
|
188
|
+
model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
187
189
|
replanThreshold: 0.7, // Replan if confidence < 0.7
|
|
188
190
|
},
|
|
189
191
|
});
|
|
@@ -209,20 +211,24 @@ import { ChatOpenAI } from '@langchain/openai';
|
|
|
209
211
|
// Create the agent
|
|
210
212
|
const agent = createReflectionAgent({
|
|
211
213
|
generator: {
|
|
212
|
-
|
|
214
|
+
model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
213
215
|
systemPrompt: 'You are a professional writer. Create high-quality content.',
|
|
214
216
|
},
|
|
215
217
|
reflector: {
|
|
216
|
-
|
|
218
|
+
model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
217
219
|
systemPrompt: 'Critique the content for clarity, engagement, and professionalism.',
|
|
218
220
|
},
|
|
221
|
+
reviser: {
|
|
222
|
+
model: new ChatOpenAI({ model: 'gpt-4' }),
|
|
223
|
+
systemPrompt: 'Revise the content based on the critique.',
|
|
224
|
+
},
|
|
219
225
|
maxIterations: 3,
|
|
220
226
|
verbose: true,
|
|
221
227
|
});
|
|
222
228
|
|
|
223
229
|
// Use the agent
|
|
224
230
|
const result = await agent.invoke({
|
|
225
|
-
|
|
231
|
+
input: 'Write a blog post about AI',
|
|
226
232
|
});
|
|
227
233
|
|
|
228
234
|
console.log(result.reflections); // All critiques
|
|
@@ -237,41 +243,31 @@ Coordinate specialized agents:
|
|
|
237
243
|
import { MultiAgentSystemBuilder } from '@agentforge/patterns';
|
|
238
244
|
import { ChatOpenAI } from '@langchain/openai';
|
|
239
245
|
|
|
240
|
-
const
|
|
246
|
+
const model = new ChatOpenAI({ model: 'gpt-4' });
|
|
241
247
|
|
|
242
248
|
// Create builder
|
|
243
249
|
const builder = new MultiAgentSystemBuilder({
|
|
244
250
|
supervisor: {
|
|
245
|
-
|
|
251
|
+
model,
|
|
246
252
|
strategy: 'skill-based', // or 'llm-based', 'round-robin', etc.
|
|
247
253
|
},
|
|
248
|
-
aggregator: {
|
|
254
|
+
aggregator: { model },
|
|
249
255
|
});
|
|
250
256
|
|
|
251
257
|
// Register specialized workers
|
|
252
258
|
builder.registerWorkers([
|
|
253
259
|
{
|
|
254
|
-
|
|
255
|
-
name: 'Tech Support',
|
|
260
|
+
name: 'tech_support',
|
|
256
261
|
description: 'Handles technical issues',
|
|
257
|
-
capabilities:
|
|
258
|
-
|
|
259
|
-
tools: ['diagnostic', 'troubleshoot'],
|
|
260
|
-
available: true,
|
|
261
|
-
},
|
|
262
|
-
llm,
|
|
262
|
+
capabilities: ['technical', 'troubleshooting', 'debugging'],
|
|
263
|
+
model,
|
|
263
264
|
tools: [diagnosticTool, troubleshootTool],
|
|
264
265
|
},
|
|
265
266
|
{
|
|
266
|
-
|
|
267
|
-
name: 'Billing Support',
|
|
267
|
+
name: 'billing_support',
|
|
268
268
|
description: 'Handles billing inquiries',
|
|
269
|
-
capabilities:
|
|
270
|
-
|
|
271
|
-
tools: ['account_check', 'refund_process'],
|
|
272
|
-
available: true,
|
|
273
|
-
},
|
|
274
|
-
llm,
|
|
269
|
+
capabilities: ['billing', 'payments', 'refunds'],
|
|
270
|
+
model,
|
|
275
271
|
tools: [checkAccountTool, processRefundTool],
|
|
276
272
|
},
|
|
277
273
|
]);
|
|
@@ -350,25 +346,23 @@ import {
|
|
|
350
346
|
```typescript
|
|
351
347
|
{
|
|
352
348
|
planner: {
|
|
353
|
-
|
|
349
|
+
model: BaseChatModel, // LLM for planning
|
|
354
350
|
systemPrompt?: string, // Custom planning prompt
|
|
355
|
-
maxSteps?: number, // Max steps in plan (default:
|
|
351
|
+
maxSteps?: number, // Max steps in plan (default: 7)
|
|
356
352
|
includeToolDescriptions?: boolean,
|
|
357
353
|
},
|
|
358
354
|
executor: {
|
|
359
355
|
tools: Tool[], // Available tools
|
|
360
|
-
|
|
356
|
+
model?: BaseChatModel, // Optional LLM for sub-tasks
|
|
361
357
|
parallel?: boolean, // Enable parallel execution
|
|
362
358
|
stepTimeout?: number, // Timeout per step (ms)
|
|
363
|
-
maxParallelSteps?: number, // Max concurrent steps
|
|
364
359
|
},
|
|
365
360
|
replanner?: {
|
|
366
|
-
|
|
361
|
+
model: BaseChatModel, // LLM for replanning
|
|
367
362
|
replanThreshold?: number, // Confidence threshold (0-1)
|
|
368
363
|
systemPrompt?: string, // Custom replanning prompt
|
|
369
364
|
},
|
|
370
365
|
maxIterations?: number, // Max planning iterations
|
|
371
|
-
returnIntermediateSteps?: boolean,
|
|
372
366
|
verbose?: boolean,
|
|
373
367
|
}
|
|
374
368
|
```
|
|
@@ -397,17 +391,19 @@ import {
|
|
|
397
391
|
```typescript
|
|
398
392
|
{
|
|
399
393
|
generator: {
|
|
400
|
-
|
|
394
|
+
model: BaseChatModel, // LLM for generation
|
|
401
395
|
systemPrompt?: string, // Custom generation prompt
|
|
402
396
|
},
|
|
403
397
|
reflector: {
|
|
404
|
-
|
|
398
|
+
model: BaseChatModel, // LLM for reflection
|
|
405
399
|
systemPrompt?: string, // Custom reflection prompt
|
|
406
|
-
|
|
400
|
+
},
|
|
401
|
+
reviser: {
|
|
402
|
+
model: BaseChatModel, // LLM for revision
|
|
403
|
+
systemPrompt?: string, // Custom revision prompt
|
|
407
404
|
},
|
|
408
405
|
maxIterations?: number, // Max reflection cycles (default: 3)
|
|
409
|
-
|
|
410
|
-
returnIntermediateSteps?: boolean,
|
|
406
|
+
qualityCriteria?: string[], // Quality criteria for reflection
|
|
411
407
|
verbose?: boolean,
|
|
412
408
|
}
|
|
413
409
|
```
|
|
@@ -431,7 +427,8 @@ import {
|
|
|
431
427
|
|
|
432
428
|
**Main API**:
|
|
433
429
|
- `createMultiAgentSystem(config)` - Create a complete Multi-Agent system
|
|
434
|
-
- `
|
|
430
|
+
- `MultiAgentSystemBuilder` - Builder for creating Multi-Agent systems with workers
|
|
431
|
+
- `registerWorkers(system, workers)` - Update worker capabilities in state (Note: does not add worker nodes to compiled graphs; use builder or pass workers to createMultiAgentSystem)
|
|
435
432
|
|
|
436
433
|
**Configuration**:
|
|
437
434
|
```typescript
|
|
@@ -458,13 +455,32 @@ import {
|
|
|
458
455
|
- `'load-balanced'` - Route to least busy worker
|
|
459
456
|
- Custom rule-based routing
|
|
460
457
|
|
|
461
|
-
**Worker Configuration
|
|
458
|
+
**Worker Configuration** (for createMultiAgentSystem):
|
|
459
|
+
```typescript
|
|
460
|
+
{
|
|
461
|
+
id: string, // Unique worker identifier
|
|
462
|
+
capabilities: { // Worker capabilities
|
|
463
|
+
skills: string[], // Worker skills
|
|
464
|
+
tools: string[], // Tool names (not objects)
|
|
465
|
+
available: boolean, // Availability status
|
|
466
|
+
currentWorkload?: number, // Current workload
|
|
467
|
+
},
|
|
468
|
+
tools?: Tool[], // Actual tool implementations
|
|
469
|
+
model?: BaseChatModel, // Worker-specific model
|
|
470
|
+
systemPrompt?: string, // Worker-specific prompt
|
|
471
|
+
executeFn?: Function, // Custom execution function
|
|
472
|
+
agent?: CompiledStateGraph, // Pre-built agent
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
**Worker Configuration** (for MultiAgentSystemBuilder.registerWorkers):
|
|
462
477
|
```typescript
|
|
463
478
|
{
|
|
464
|
-
name: string, //
|
|
465
|
-
description
|
|
466
|
-
capabilities: string[], //
|
|
467
|
-
tools
|
|
479
|
+
name: string, // Worker name (becomes 'id')
|
|
480
|
+
description?: string, // Worker description
|
|
481
|
+
capabilities: string[], // Array of skill names
|
|
482
|
+
tools?: Tool[], // Available tools
|
|
483
|
+
model?: BaseChatModel, // Worker-specific model
|
|
468
484
|
systemPrompt?: string, // Worker-specific prompt
|
|
469
485
|
}
|
|
470
486
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/patterns",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Agent patterns (ReAct, Planner-Executor) for AgentForge framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -16,17 +16,6 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
21
|
-
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
22
|
-
"test": "vitest",
|
|
23
|
-
"test:coverage": "vitest --coverage",
|
|
24
|
-
"typecheck": "tsc --noEmit",
|
|
25
|
-
"lint": "eslint src",
|
|
26
|
-
"lint:fix": "eslint src --fix",
|
|
27
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
28
|
-
"clean": "rm -rf dist *.tsbuildinfo"
|
|
29
|
-
},
|
|
30
19
|
"keywords": [
|
|
31
20
|
"agents",
|
|
32
21
|
"ai",
|
|
@@ -47,13 +36,13 @@
|
|
|
47
36
|
"url": "https://github.com/TVScoundrel/agentforge/issues"
|
|
48
37
|
},
|
|
49
38
|
"dependencies": {
|
|
50
|
-
"@agentforge/core": "
|
|
39
|
+
"@agentforge/core": "0.12.1",
|
|
51
40
|
"@langchain/core": "^1.1.17",
|
|
52
41
|
"@langchain/langgraph": "^1.1.2",
|
|
53
42
|
"zod": "^3.23.8"
|
|
54
43
|
},
|
|
55
44
|
"devDependencies": {
|
|
56
|
-
"@agentforge/testing": "
|
|
45
|
+
"@agentforge/testing": "0.12.1",
|
|
57
46
|
"@eslint/js": "^9.17.0",
|
|
58
47
|
"@types/node": "^22.10.2",
|
|
59
48
|
"eslint": "^9.17.0",
|
|
@@ -62,5 +51,16 @@
|
|
|
62
51
|
"typescript": "^5.3.3",
|
|
63
52
|
"typescript-eslint": "^8.19.1",
|
|
64
53
|
"vitest": "^1.6.1"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
57
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
58
|
+
"test": "vitest",
|
|
59
|
+
"test:coverage": "vitest --coverage",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"lint": "eslint src",
|
|
62
|
+
"lint:fix": "eslint src --fix",
|
|
63
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
64
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|