@agentforge/core 0.3.8 → 0.3.9
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/dist/index.cjs +189 -5
- package/dist/index.d.cts +266 -1
- package/dist/index.d.ts +266 -1
- package/dist/index.js +188 -5
- package/package.json +13 -13
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/dist/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ __export(index_exports, {
|
|
|
51
51
|
ToolMetadataSchema: () => ToolMetadataSchema,
|
|
52
52
|
ToolNameSchema: () => ToolNameSchema,
|
|
53
53
|
ToolRegistry: () => ToolRegistry,
|
|
54
|
+
ToolRelationsSchema: () => ToolRelationsSchema,
|
|
54
55
|
batch: () => batch,
|
|
55
56
|
broadcast: () => broadcast,
|
|
56
57
|
cache: () => cache,
|
|
@@ -177,6 +178,28 @@ var ToolExampleSchema = import_zod.z.object({
|
|
|
177
178
|
*/
|
|
178
179
|
explanation: import_zod.z.string().min(1).optional()
|
|
179
180
|
});
|
|
181
|
+
var ToolRelationsSchema = import_zod.z.object({
|
|
182
|
+
/**
|
|
183
|
+
* Tools that must be called before this tool
|
|
184
|
+
*/
|
|
185
|
+
requires: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
186
|
+
/**
|
|
187
|
+
* Tools that work well with this tool
|
|
188
|
+
*/
|
|
189
|
+
suggests: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
190
|
+
/**
|
|
191
|
+
* Tools that conflict with this tool
|
|
192
|
+
*/
|
|
193
|
+
conflicts: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
194
|
+
/**
|
|
195
|
+
* Tools this typically follows in a workflow
|
|
196
|
+
*/
|
|
197
|
+
follows: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
198
|
+
/**
|
|
199
|
+
* Tools this typically precedes in a workflow
|
|
200
|
+
*/
|
|
201
|
+
precedes: import_zod.z.array(import_zod.z.string().min(1)).optional()
|
|
202
|
+
});
|
|
180
203
|
var ToolNameSchema = import_zod.z.string().min(2, "Tool name must be at least 2 characters").max(50, "Tool name must be at most 50 characters").regex(
|
|
181
204
|
/^[a-z][a-z0-9-]*[a-z0-9]$/,
|
|
182
205
|
"Tool name must be kebab-case (lowercase letters, numbers, hyphens only, must start with a letter)"
|
|
@@ -235,7 +258,11 @@ var ToolMetadataSchema = import_zod.z.object({
|
|
|
235
258
|
/**
|
|
236
259
|
* Replacement tool name - if provided, must be valid tool name
|
|
237
260
|
*/
|
|
238
|
-
replacedBy: ToolNameSchema.optional()
|
|
261
|
+
replacedBy: ToolNameSchema.optional(),
|
|
262
|
+
/**
|
|
263
|
+
* Tool relations - defines relationships with other tools
|
|
264
|
+
*/
|
|
265
|
+
relations: ToolRelationsSchema.optional()
|
|
239
266
|
});
|
|
240
267
|
function validateToolMetadata(metadata) {
|
|
241
268
|
return ToolMetadataSchema.safeParse(metadata);
|
|
@@ -544,13 +571,93 @@ var ToolBuilder = class {
|
|
|
544
571
|
}
|
|
545
572
|
/**
|
|
546
573
|
* Set author (optional)
|
|
547
|
-
*
|
|
574
|
+
*
|
|
548
575
|
* @param author - Tool author name
|
|
549
576
|
*/
|
|
550
577
|
author(author) {
|
|
551
578
|
this.metadata.author = author;
|
|
552
579
|
return this;
|
|
553
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Set tools that must be called before this tool (optional)
|
|
583
|
+
*
|
|
584
|
+
* @param tools - Array of tool names that are required
|
|
585
|
+
* @example
|
|
586
|
+
* ```ts
|
|
587
|
+
* .requires(['view-file', 'search-codebase'])
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
requires(tools) {
|
|
591
|
+
if (!this.metadata.relations) {
|
|
592
|
+
this.metadata.relations = {};
|
|
593
|
+
}
|
|
594
|
+
this.metadata.relations.requires = tools;
|
|
595
|
+
return this;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Set tools that work well with this tool (optional)
|
|
599
|
+
*
|
|
600
|
+
* @param tools - Array of tool names that are suggested
|
|
601
|
+
* @example
|
|
602
|
+
* ```ts
|
|
603
|
+
* .suggests(['run-tests', 'format-code'])
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
suggests(tools) {
|
|
607
|
+
if (!this.metadata.relations) {
|
|
608
|
+
this.metadata.relations = {};
|
|
609
|
+
}
|
|
610
|
+
this.metadata.relations.suggests = tools;
|
|
611
|
+
return this;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Set tools that conflict with this tool (optional)
|
|
615
|
+
*
|
|
616
|
+
* @param tools - Array of tool names that conflict
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* .conflicts(['delete-file'])
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
conflicts(tools) {
|
|
623
|
+
if (!this.metadata.relations) {
|
|
624
|
+
this.metadata.relations = {};
|
|
625
|
+
}
|
|
626
|
+
this.metadata.relations.conflicts = tools;
|
|
627
|
+
return this;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Set tools this typically follows in a workflow (optional)
|
|
631
|
+
*
|
|
632
|
+
* @param tools - Array of tool names this follows
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* .follows(['search-codebase', 'view-file'])
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
follows(tools) {
|
|
639
|
+
if (!this.metadata.relations) {
|
|
640
|
+
this.metadata.relations = {};
|
|
641
|
+
}
|
|
642
|
+
this.metadata.relations.follows = tools;
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Set tools this typically precedes in a workflow (optional)
|
|
647
|
+
*
|
|
648
|
+
* @param tools - Array of tool names this precedes
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* .precedes(['run-tests'])
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
precedes(tools) {
|
|
655
|
+
if (!this.metadata.relations) {
|
|
656
|
+
this.metadata.relations = {};
|
|
657
|
+
}
|
|
658
|
+
this.metadata.relations.precedes = tools;
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
554
661
|
/**
|
|
555
662
|
* Set the input schema (required)
|
|
556
663
|
*
|
|
@@ -1032,9 +1139,11 @@ var ToolRegistry = class {
|
|
|
1032
1139
|
includeExamples = false,
|
|
1033
1140
|
includeNotes = false,
|
|
1034
1141
|
includeLimitations = false,
|
|
1142
|
+
includeRelations = false,
|
|
1035
1143
|
groupByCategory = false,
|
|
1036
1144
|
categories,
|
|
1037
|
-
maxExamplesPerTool
|
|
1145
|
+
maxExamplesPerTool,
|
|
1146
|
+
minimal = false
|
|
1038
1147
|
} = options;
|
|
1039
1148
|
let tools = this.getAll();
|
|
1040
1149
|
if (categories && categories.length > 0) {
|
|
@@ -1060,7 +1169,9 @@ var ToolRegistry = class {
|
|
|
1060
1169
|
includeExamples,
|
|
1061
1170
|
includeNotes,
|
|
1062
1171
|
includeLimitations,
|
|
1063
|
-
|
|
1172
|
+
includeRelations,
|
|
1173
|
+
maxExamplesPerTool,
|
|
1174
|
+
minimal
|
|
1064
1175
|
}));
|
|
1065
1176
|
}
|
|
1066
1177
|
lines.push("");
|
|
@@ -1071,7 +1182,9 @@ var ToolRegistry = class {
|
|
|
1071
1182
|
includeExamples,
|
|
1072
1183
|
includeNotes,
|
|
1073
1184
|
includeLimitations,
|
|
1074
|
-
|
|
1185
|
+
includeRelations,
|
|
1186
|
+
maxExamplesPerTool,
|
|
1187
|
+
minimal
|
|
1075
1188
|
}));
|
|
1076
1189
|
lines.push("");
|
|
1077
1190
|
}
|
|
@@ -1089,6 +1202,44 @@ var ToolRegistry = class {
|
|
|
1089
1202
|
formatToolForPrompt(tool, options) {
|
|
1090
1203
|
const { metadata } = tool;
|
|
1091
1204
|
const lines = [];
|
|
1205
|
+
if (options.minimal) {
|
|
1206
|
+
lines.push(`## ${metadata.name}`);
|
|
1207
|
+
let hasContent = false;
|
|
1208
|
+
if (options.includeRelations && metadata.relations) {
|
|
1209
|
+
const relationLines = this.formatRelations(metadata.relations);
|
|
1210
|
+
if (relationLines.length > 0) {
|
|
1211
|
+
lines.push(...relationLines);
|
|
1212
|
+
hasContent = true;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (options.includeExamples && metadata.examples && metadata.examples.length > 0) {
|
|
1216
|
+
const maxExamples = options.maxExamplesPerTool || metadata.examples.length;
|
|
1217
|
+
const examples = metadata.examples.slice(0, maxExamples);
|
|
1218
|
+
for (const example of examples) {
|
|
1219
|
+
lines.push(` Example: ${example.description}`);
|
|
1220
|
+
lines.push(` Input: ${JSON.stringify(example.input)}`);
|
|
1221
|
+
if (example.explanation) {
|
|
1222
|
+
lines.push(` ${example.explanation}`);
|
|
1223
|
+
}
|
|
1224
|
+
hasContent = true;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (options.includeNotes && metadata.usageNotes) {
|
|
1228
|
+
lines.push(` Notes: ${metadata.usageNotes}`);
|
|
1229
|
+
hasContent = true;
|
|
1230
|
+
}
|
|
1231
|
+
if (options.includeLimitations && metadata.limitations && metadata.limitations.length > 0) {
|
|
1232
|
+
lines.push(` Limitations:`);
|
|
1233
|
+
for (const limitation of metadata.limitations) {
|
|
1234
|
+
lines.push(` - ${limitation}`);
|
|
1235
|
+
}
|
|
1236
|
+
hasContent = true;
|
|
1237
|
+
}
|
|
1238
|
+
if (!hasContent) {
|
|
1239
|
+
return [];
|
|
1240
|
+
}
|
|
1241
|
+
return lines;
|
|
1242
|
+
}
|
|
1092
1243
|
lines.push(`- ${metadata.name}: ${metadata.description}`);
|
|
1093
1244
|
const schemaShape = tool.schema._def?.shape?.();
|
|
1094
1245
|
if (schemaShape) {
|
|
@@ -1102,6 +1253,12 @@ var ToolRegistry = class {
|
|
|
1102
1253
|
lines.push(` Parameters: ${paramDescriptions.join(", ")}`);
|
|
1103
1254
|
}
|
|
1104
1255
|
}
|
|
1256
|
+
if (options.includeRelations && metadata.relations) {
|
|
1257
|
+
const relationLines = this.formatRelations(metadata.relations);
|
|
1258
|
+
if (relationLines.length > 0) {
|
|
1259
|
+
lines.push(...relationLines);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1105
1262
|
if (options.includeNotes && metadata.usageNotes) {
|
|
1106
1263
|
lines.push(` Notes: ${metadata.usageNotes}`);
|
|
1107
1264
|
}
|
|
@@ -1124,6 +1281,32 @@ var ToolRegistry = class {
|
|
|
1124
1281
|
}
|
|
1125
1282
|
return lines;
|
|
1126
1283
|
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Format tool relations for inclusion in a prompt
|
|
1286
|
+
*
|
|
1287
|
+
* @param relations - The relations to format
|
|
1288
|
+
* @returns Array of formatted lines
|
|
1289
|
+
* @private
|
|
1290
|
+
*/
|
|
1291
|
+
formatRelations(relations) {
|
|
1292
|
+
const lines = [];
|
|
1293
|
+
if (relations.requires && relations.requires.length > 0) {
|
|
1294
|
+
lines.push(` Requires: ${relations.requires.join(", ")}`);
|
|
1295
|
+
}
|
|
1296
|
+
if (relations.suggests && relations.suggests.length > 0) {
|
|
1297
|
+
lines.push(` Suggests: ${relations.suggests.join(", ")}`);
|
|
1298
|
+
}
|
|
1299
|
+
if (relations.conflicts && relations.conflicts.length > 0) {
|
|
1300
|
+
lines.push(` Conflicts: ${relations.conflicts.join(", ")}`);
|
|
1301
|
+
}
|
|
1302
|
+
if (relations.follows && relations.follows.length > 0) {
|
|
1303
|
+
lines.push(` Follows: ${relations.follows.join(", ")}`);
|
|
1304
|
+
}
|
|
1305
|
+
if (relations.precedes && relations.precedes.length > 0) {
|
|
1306
|
+
lines.push(` Precedes: ${relations.precedes.join(", ")}`);
|
|
1307
|
+
}
|
|
1308
|
+
return lines;
|
|
1309
|
+
}
|
|
1127
1310
|
};
|
|
1128
1311
|
|
|
1129
1312
|
// src/tools/executor.ts
|
|
@@ -3959,6 +4142,7 @@ function createCircuitBreaker(options) {
|
|
|
3959
4142
|
ToolMetadataSchema,
|
|
3960
4143
|
ToolNameSchema,
|
|
3961
4144
|
ToolRegistry,
|
|
4145
|
+
ToolRelationsSchema,
|
|
3962
4146
|
batch,
|
|
3963
4147
|
broadcast,
|
|
3964
4148
|
cache,
|
package/dist/index.d.cts
CHANGED
|
@@ -100,6 +100,61 @@ interface ToolExample {
|
|
|
100
100
|
*/
|
|
101
101
|
explanation?: string;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* ToolRelations - Defines relationships between tools
|
|
105
|
+
*
|
|
106
|
+
* Helps LLMs understand tool workflows and dependencies.
|
|
107
|
+
*
|
|
108
|
+
* Why tool relations?
|
|
109
|
+
* - Express dependencies: "Must call tool X before tool Y"
|
|
110
|
+
* - Suggest workflows: "After X, consider calling Y"
|
|
111
|
+
* - Prevent conflicts: "Don't use X and Y together"
|
|
112
|
+
* - Guide LLM decisions: Better tool selection and ordering
|
|
113
|
+
*
|
|
114
|
+
* Example:
|
|
115
|
+
* ```ts
|
|
116
|
+
* const relations: ToolRelations = {
|
|
117
|
+
* requires: ['view-file'], // Must call this first
|
|
118
|
+
* suggests: ['run-tests'], // Often used together
|
|
119
|
+
* conflicts: ['delete-file'], // Don't use together
|
|
120
|
+
* follows: ['search-codebase'], // Typically called after
|
|
121
|
+
* precedes: ['edit-file'] // Typically called before
|
|
122
|
+
* };
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
interface ToolRelations {
|
|
126
|
+
/**
|
|
127
|
+
* Tools that should be called before this tool
|
|
128
|
+
*
|
|
129
|
+
* Example: 'edit-file' requires 'view-file' to be called first
|
|
130
|
+
* to ensure you know the file contents before editing.
|
|
131
|
+
*/
|
|
132
|
+
requires?: string[];
|
|
133
|
+
/**
|
|
134
|
+
* Tools that work well with this tool
|
|
135
|
+
*
|
|
136
|
+
* Example: 'edit-file' suggests 'run-tests' to verify changes.
|
|
137
|
+
*/
|
|
138
|
+
suggests?: string[];
|
|
139
|
+
/**
|
|
140
|
+
* Tools that conflict with this tool
|
|
141
|
+
*
|
|
142
|
+
* Example: 'create-file' conflicts with 'delete-file' on the same path.
|
|
143
|
+
*/
|
|
144
|
+
conflicts?: string[];
|
|
145
|
+
/**
|
|
146
|
+
* Tools this typically follows in a workflow
|
|
147
|
+
*
|
|
148
|
+
* Example: 'edit-file' typically follows 'view-file' or 'search-codebase'.
|
|
149
|
+
*/
|
|
150
|
+
follows?: string[];
|
|
151
|
+
/**
|
|
152
|
+
* Tools this typically precedes in a workflow
|
|
153
|
+
*
|
|
154
|
+
* Example: 'view-file' typically precedes 'edit-file'.
|
|
155
|
+
*/
|
|
156
|
+
precedes?: string[];
|
|
157
|
+
}
|
|
103
158
|
/**
|
|
104
159
|
* ToolMetadata - Rich metadata for a tool
|
|
105
160
|
*
|
|
@@ -193,6 +248,25 @@ interface ToolMetadata {
|
|
|
193
248
|
* Example: 'read-file-v2'
|
|
194
249
|
*/
|
|
195
250
|
replacedBy?: string;
|
|
251
|
+
/**
|
|
252
|
+
* Tool relations (optional)
|
|
253
|
+
* Defines relationships with other tools
|
|
254
|
+
*
|
|
255
|
+
* Helps LLMs understand:
|
|
256
|
+
* - Which tools should be called before/after this tool
|
|
257
|
+
* - Which tools work well together
|
|
258
|
+
* - Which tools conflict with this tool
|
|
259
|
+
*
|
|
260
|
+
* Example:
|
|
261
|
+
* ```ts
|
|
262
|
+
* relations: {
|
|
263
|
+
* requires: ['view-file'],
|
|
264
|
+
* suggests: ['run-tests'],
|
|
265
|
+
* follows: ['search-codebase']
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
relations?: ToolRelations;
|
|
196
270
|
}
|
|
197
271
|
/**
|
|
198
272
|
* Tool - Complete tool definition
|
|
@@ -314,6 +388,57 @@ declare const ToolExampleSchema: z.ZodObject<{
|
|
|
314
388
|
output?: unknown;
|
|
315
389
|
explanation?: string | undefined;
|
|
316
390
|
}>;
|
|
391
|
+
/**
|
|
392
|
+
* Schema for ToolRelations
|
|
393
|
+
*
|
|
394
|
+
* Validates tool relationship definitions.
|
|
395
|
+
* All fields are optional arrays of tool names.
|
|
396
|
+
*
|
|
397
|
+
* Example:
|
|
398
|
+
* ```ts
|
|
399
|
+
* ToolRelationsSchema.parse({
|
|
400
|
+
* requires: ['view-file'],
|
|
401
|
+
* suggests: ['run-tests', 'format-code'],
|
|
402
|
+
* conflicts: ['delete-file'],
|
|
403
|
+
* follows: ['search-codebase'],
|
|
404
|
+
* precedes: ['run-tests']
|
|
405
|
+
* });
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare const ToolRelationsSchema: z.ZodObject<{
|
|
409
|
+
/**
|
|
410
|
+
* Tools that must be called before this tool
|
|
411
|
+
*/
|
|
412
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
413
|
+
/**
|
|
414
|
+
* Tools that work well with this tool
|
|
415
|
+
*/
|
|
416
|
+
suggests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
417
|
+
/**
|
|
418
|
+
* Tools that conflict with this tool
|
|
419
|
+
*/
|
|
420
|
+
conflicts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
421
|
+
/**
|
|
422
|
+
* Tools this typically follows in a workflow
|
|
423
|
+
*/
|
|
424
|
+
follows: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
425
|
+
/**
|
|
426
|
+
* Tools this typically precedes in a workflow
|
|
427
|
+
*/
|
|
428
|
+
precedes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
429
|
+
}, "strip", z.ZodTypeAny, {
|
|
430
|
+
requires?: string[] | undefined;
|
|
431
|
+
suggests?: string[] | undefined;
|
|
432
|
+
conflicts?: string[] | undefined;
|
|
433
|
+
follows?: string[] | undefined;
|
|
434
|
+
precedes?: string[] | undefined;
|
|
435
|
+
}, {
|
|
436
|
+
requires?: string[] | undefined;
|
|
437
|
+
suggests?: string[] | undefined;
|
|
438
|
+
conflicts?: string[] | undefined;
|
|
439
|
+
follows?: string[] | undefined;
|
|
440
|
+
precedes?: string[] | undefined;
|
|
441
|
+
}>;
|
|
317
442
|
/**
|
|
318
443
|
* Schema for tool names
|
|
319
444
|
*
|
|
@@ -420,6 +545,43 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
420
545
|
* Replacement tool name - if provided, must be valid tool name
|
|
421
546
|
*/
|
|
422
547
|
replacedBy: z.ZodOptional<z.ZodString>;
|
|
548
|
+
/**
|
|
549
|
+
* Tool relations - defines relationships with other tools
|
|
550
|
+
*/
|
|
551
|
+
relations: z.ZodOptional<z.ZodObject<{
|
|
552
|
+
/**
|
|
553
|
+
* Tools that must be called before this tool
|
|
554
|
+
*/
|
|
555
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
556
|
+
/**
|
|
557
|
+
* Tools that work well with this tool
|
|
558
|
+
*/
|
|
559
|
+
suggests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
560
|
+
/**
|
|
561
|
+
* Tools that conflict with this tool
|
|
562
|
+
*/
|
|
563
|
+
conflicts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
564
|
+
/**
|
|
565
|
+
* Tools this typically follows in a workflow
|
|
566
|
+
*/
|
|
567
|
+
follows: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
568
|
+
/**
|
|
569
|
+
* Tools this typically precedes in a workflow
|
|
570
|
+
*/
|
|
571
|
+
precedes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
572
|
+
}, "strip", z.ZodTypeAny, {
|
|
573
|
+
requires?: string[] | undefined;
|
|
574
|
+
suggests?: string[] | undefined;
|
|
575
|
+
conflicts?: string[] | undefined;
|
|
576
|
+
follows?: string[] | undefined;
|
|
577
|
+
precedes?: string[] | undefined;
|
|
578
|
+
}, {
|
|
579
|
+
requires?: string[] | undefined;
|
|
580
|
+
suggests?: string[] | undefined;
|
|
581
|
+
conflicts?: string[] | undefined;
|
|
582
|
+
follows?: string[] | undefined;
|
|
583
|
+
precedes?: string[] | undefined;
|
|
584
|
+
}>>;
|
|
423
585
|
}, "strip", z.ZodTypeAny, {
|
|
424
586
|
description: string;
|
|
425
587
|
name: string;
|
|
@@ -438,6 +600,13 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
438
600
|
author?: string | undefined;
|
|
439
601
|
deprecated?: boolean | undefined;
|
|
440
602
|
replacedBy?: string | undefined;
|
|
603
|
+
relations?: {
|
|
604
|
+
requires?: string[] | undefined;
|
|
605
|
+
suggests?: string[] | undefined;
|
|
606
|
+
conflicts?: string[] | undefined;
|
|
607
|
+
follows?: string[] | undefined;
|
|
608
|
+
precedes?: string[] | undefined;
|
|
609
|
+
} | undefined;
|
|
441
610
|
}, {
|
|
442
611
|
description: string;
|
|
443
612
|
name: string;
|
|
@@ -456,6 +625,13 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
456
625
|
author?: string | undefined;
|
|
457
626
|
deprecated?: boolean | undefined;
|
|
458
627
|
replacedBy?: string | undefined;
|
|
628
|
+
relations?: {
|
|
629
|
+
requires?: string[] | undefined;
|
|
630
|
+
suggests?: string[] | undefined;
|
|
631
|
+
conflicts?: string[] | undefined;
|
|
632
|
+
follows?: string[] | undefined;
|
|
633
|
+
precedes?: string[] | undefined;
|
|
634
|
+
} | undefined;
|
|
459
635
|
}>;
|
|
460
636
|
/**
|
|
461
637
|
* Helper function to validate tool metadata
|
|
@@ -496,6 +672,13 @@ declare function validateToolMetadata(metadata: unknown): z.SafeParseReturnType<
|
|
|
496
672
|
author?: string | undefined;
|
|
497
673
|
deprecated?: boolean | undefined;
|
|
498
674
|
replacedBy?: string | undefined;
|
|
675
|
+
relations?: {
|
|
676
|
+
requires?: string[] | undefined;
|
|
677
|
+
suggests?: string[] | undefined;
|
|
678
|
+
conflicts?: string[] | undefined;
|
|
679
|
+
follows?: string[] | undefined;
|
|
680
|
+
precedes?: string[] | undefined;
|
|
681
|
+
} | undefined;
|
|
499
682
|
}, {
|
|
500
683
|
description: string;
|
|
501
684
|
name: string;
|
|
@@ -514,6 +697,13 @@ declare function validateToolMetadata(metadata: unknown): z.SafeParseReturnType<
|
|
|
514
697
|
author?: string | undefined;
|
|
515
698
|
deprecated?: boolean | undefined;
|
|
516
699
|
replacedBy?: string | undefined;
|
|
700
|
+
relations?: {
|
|
701
|
+
requires?: string[] | undefined;
|
|
702
|
+
suggests?: string[] | undefined;
|
|
703
|
+
conflicts?: string[] | undefined;
|
|
704
|
+
follows?: string[] | undefined;
|
|
705
|
+
precedes?: string[] | undefined;
|
|
706
|
+
} | undefined;
|
|
517
707
|
}>;
|
|
518
708
|
/**
|
|
519
709
|
* Helper function to validate tool name
|
|
@@ -802,6 +992,56 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
802
992
|
* @param author - Tool author name
|
|
803
993
|
*/
|
|
804
994
|
author(author: string): this;
|
|
995
|
+
/**
|
|
996
|
+
* Set tools that must be called before this tool (optional)
|
|
997
|
+
*
|
|
998
|
+
* @param tools - Array of tool names that are required
|
|
999
|
+
* @example
|
|
1000
|
+
* ```ts
|
|
1001
|
+
* .requires(['view-file', 'search-codebase'])
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
requires(tools: string[]): this;
|
|
1005
|
+
/**
|
|
1006
|
+
* Set tools that work well with this tool (optional)
|
|
1007
|
+
*
|
|
1008
|
+
* @param tools - Array of tool names that are suggested
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* .suggests(['run-tests', 'format-code'])
|
|
1012
|
+
* ```
|
|
1013
|
+
*/
|
|
1014
|
+
suggests(tools: string[]): this;
|
|
1015
|
+
/**
|
|
1016
|
+
* Set tools that conflict with this tool (optional)
|
|
1017
|
+
*
|
|
1018
|
+
* @param tools - Array of tool names that conflict
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* .conflicts(['delete-file'])
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
conflicts(tools: string[]): this;
|
|
1025
|
+
/**
|
|
1026
|
+
* Set tools this typically follows in a workflow (optional)
|
|
1027
|
+
*
|
|
1028
|
+
* @param tools - Array of tool names this follows
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```ts
|
|
1031
|
+
* .follows(['search-codebase', 'view-file'])
|
|
1032
|
+
* ```
|
|
1033
|
+
*/
|
|
1034
|
+
follows(tools: string[]): this;
|
|
1035
|
+
/**
|
|
1036
|
+
* Set tools this typically precedes in a workflow (optional)
|
|
1037
|
+
*
|
|
1038
|
+
* @param tools - Array of tool names this precedes
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* .precedes(['run-tests'])
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
precedes(tools: string[]): this;
|
|
805
1045
|
/**
|
|
806
1046
|
* Set the input schema (required)
|
|
807
1047
|
*
|
|
@@ -886,12 +1126,29 @@ interface PromptOptions {
|
|
|
886
1126
|
includeNotes?: boolean;
|
|
887
1127
|
/** Include limitations in the prompt */
|
|
888
1128
|
includeLimitations?: boolean;
|
|
1129
|
+
/** Include tool relations in the prompt */
|
|
1130
|
+
includeRelations?: boolean;
|
|
889
1131
|
/** Group tools by category */
|
|
890
1132
|
groupByCategory?: boolean;
|
|
891
1133
|
/** Filter by specific categories */
|
|
892
1134
|
categories?: ToolCategory[];
|
|
893
1135
|
/** Maximum number of examples to include per tool */
|
|
894
1136
|
maxExamplesPerTool?: number;
|
|
1137
|
+
/**
|
|
1138
|
+
* Minimal mode - only supplementary context, not full definitions
|
|
1139
|
+
*
|
|
1140
|
+
* Use this when tool definitions are sent via API (OpenAI, Anthropic, etc.)
|
|
1141
|
+
*
|
|
1142
|
+
* When true:
|
|
1143
|
+
* - Excludes basic tool name/description/parameters
|
|
1144
|
+
* - Includes only relations, examples, notes, limitations
|
|
1145
|
+
* - Tool names are used as headers for matching
|
|
1146
|
+
*
|
|
1147
|
+
* When false (default):
|
|
1148
|
+
* - Includes full tool definitions (current behavior)
|
|
1149
|
+
* - Backward compatible
|
|
1150
|
+
*/
|
|
1151
|
+
minimal?: boolean;
|
|
895
1152
|
}
|
|
896
1153
|
/**
|
|
897
1154
|
* Tool Registry - Central registry for managing tools
|
|
@@ -1182,6 +1439,14 @@ declare class ToolRegistry {
|
|
|
1182
1439
|
* @private
|
|
1183
1440
|
*/
|
|
1184
1441
|
private formatToolForPrompt;
|
|
1442
|
+
/**
|
|
1443
|
+
* Format tool relations for inclusion in a prompt
|
|
1444
|
+
*
|
|
1445
|
+
* @param relations - The relations to format
|
|
1446
|
+
* @returns Array of formatted lines
|
|
1447
|
+
* @private
|
|
1448
|
+
*/
|
|
1449
|
+
private formatRelations;
|
|
1185
1450
|
}
|
|
1186
1451
|
|
|
1187
1452
|
/**
|
|
@@ -4073,4 +4338,4 @@ declare class CircuitBreaker {
|
|
|
4073
4338
|
}
|
|
4074
4339
|
declare function createCircuitBreaker(options: CircuitBreakerOptions): CircuitBreaker;
|
|
4075
4340
|
|
|
4076
|
-
export { AgentError, type AggregateNode, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type ReducerFunction, RegistryEvent, type RequestConfig, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolSimulatorConfig, type TracingOptions, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getToolDescription, getToolJsonSchema, isMemoryCheckpointer, isTracingEnabled, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, retry, safeValidateSchemaDescriptions, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withErrorHandler, withMetrics, withRetry, withTimeout, withTracing };
|
|
4341
|
+
export { AgentError, type AggregateNode, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type ReducerFunction, RegistryEvent, type RequestConfig, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getToolDescription, getToolJsonSchema, isMemoryCheckpointer, isTracingEnabled, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, retry, safeValidateSchemaDescriptions, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withErrorHandler, withMetrics, withRetry, withTimeout, withTracing };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,61 @@ interface ToolExample {
|
|
|
100
100
|
*/
|
|
101
101
|
explanation?: string;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* ToolRelations - Defines relationships between tools
|
|
105
|
+
*
|
|
106
|
+
* Helps LLMs understand tool workflows and dependencies.
|
|
107
|
+
*
|
|
108
|
+
* Why tool relations?
|
|
109
|
+
* - Express dependencies: "Must call tool X before tool Y"
|
|
110
|
+
* - Suggest workflows: "After X, consider calling Y"
|
|
111
|
+
* - Prevent conflicts: "Don't use X and Y together"
|
|
112
|
+
* - Guide LLM decisions: Better tool selection and ordering
|
|
113
|
+
*
|
|
114
|
+
* Example:
|
|
115
|
+
* ```ts
|
|
116
|
+
* const relations: ToolRelations = {
|
|
117
|
+
* requires: ['view-file'], // Must call this first
|
|
118
|
+
* suggests: ['run-tests'], // Often used together
|
|
119
|
+
* conflicts: ['delete-file'], // Don't use together
|
|
120
|
+
* follows: ['search-codebase'], // Typically called after
|
|
121
|
+
* precedes: ['edit-file'] // Typically called before
|
|
122
|
+
* };
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
interface ToolRelations {
|
|
126
|
+
/**
|
|
127
|
+
* Tools that should be called before this tool
|
|
128
|
+
*
|
|
129
|
+
* Example: 'edit-file' requires 'view-file' to be called first
|
|
130
|
+
* to ensure you know the file contents before editing.
|
|
131
|
+
*/
|
|
132
|
+
requires?: string[];
|
|
133
|
+
/**
|
|
134
|
+
* Tools that work well with this tool
|
|
135
|
+
*
|
|
136
|
+
* Example: 'edit-file' suggests 'run-tests' to verify changes.
|
|
137
|
+
*/
|
|
138
|
+
suggests?: string[];
|
|
139
|
+
/**
|
|
140
|
+
* Tools that conflict with this tool
|
|
141
|
+
*
|
|
142
|
+
* Example: 'create-file' conflicts with 'delete-file' on the same path.
|
|
143
|
+
*/
|
|
144
|
+
conflicts?: string[];
|
|
145
|
+
/**
|
|
146
|
+
* Tools this typically follows in a workflow
|
|
147
|
+
*
|
|
148
|
+
* Example: 'edit-file' typically follows 'view-file' or 'search-codebase'.
|
|
149
|
+
*/
|
|
150
|
+
follows?: string[];
|
|
151
|
+
/**
|
|
152
|
+
* Tools this typically precedes in a workflow
|
|
153
|
+
*
|
|
154
|
+
* Example: 'view-file' typically precedes 'edit-file'.
|
|
155
|
+
*/
|
|
156
|
+
precedes?: string[];
|
|
157
|
+
}
|
|
103
158
|
/**
|
|
104
159
|
* ToolMetadata - Rich metadata for a tool
|
|
105
160
|
*
|
|
@@ -193,6 +248,25 @@ interface ToolMetadata {
|
|
|
193
248
|
* Example: 'read-file-v2'
|
|
194
249
|
*/
|
|
195
250
|
replacedBy?: string;
|
|
251
|
+
/**
|
|
252
|
+
* Tool relations (optional)
|
|
253
|
+
* Defines relationships with other tools
|
|
254
|
+
*
|
|
255
|
+
* Helps LLMs understand:
|
|
256
|
+
* - Which tools should be called before/after this tool
|
|
257
|
+
* - Which tools work well together
|
|
258
|
+
* - Which tools conflict with this tool
|
|
259
|
+
*
|
|
260
|
+
* Example:
|
|
261
|
+
* ```ts
|
|
262
|
+
* relations: {
|
|
263
|
+
* requires: ['view-file'],
|
|
264
|
+
* suggests: ['run-tests'],
|
|
265
|
+
* follows: ['search-codebase']
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
relations?: ToolRelations;
|
|
196
270
|
}
|
|
197
271
|
/**
|
|
198
272
|
* Tool - Complete tool definition
|
|
@@ -314,6 +388,57 @@ declare const ToolExampleSchema: z.ZodObject<{
|
|
|
314
388
|
output?: unknown;
|
|
315
389
|
explanation?: string | undefined;
|
|
316
390
|
}>;
|
|
391
|
+
/**
|
|
392
|
+
* Schema for ToolRelations
|
|
393
|
+
*
|
|
394
|
+
* Validates tool relationship definitions.
|
|
395
|
+
* All fields are optional arrays of tool names.
|
|
396
|
+
*
|
|
397
|
+
* Example:
|
|
398
|
+
* ```ts
|
|
399
|
+
* ToolRelationsSchema.parse({
|
|
400
|
+
* requires: ['view-file'],
|
|
401
|
+
* suggests: ['run-tests', 'format-code'],
|
|
402
|
+
* conflicts: ['delete-file'],
|
|
403
|
+
* follows: ['search-codebase'],
|
|
404
|
+
* precedes: ['run-tests']
|
|
405
|
+
* });
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare const ToolRelationsSchema: z.ZodObject<{
|
|
409
|
+
/**
|
|
410
|
+
* Tools that must be called before this tool
|
|
411
|
+
*/
|
|
412
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
413
|
+
/**
|
|
414
|
+
* Tools that work well with this tool
|
|
415
|
+
*/
|
|
416
|
+
suggests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
417
|
+
/**
|
|
418
|
+
* Tools that conflict with this tool
|
|
419
|
+
*/
|
|
420
|
+
conflicts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
421
|
+
/**
|
|
422
|
+
* Tools this typically follows in a workflow
|
|
423
|
+
*/
|
|
424
|
+
follows: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
425
|
+
/**
|
|
426
|
+
* Tools this typically precedes in a workflow
|
|
427
|
+
*/
|
|
428
|
+
precedes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
429
|
+
}, "strip", z.ZodTypeAny, {
|
|
430
|
+
requires?: string[] | undefined;
|
|
431
|
+
suggests?: string[] | undefined;
|
|
432
|
+
conflicts?: string[] | undefined;
|
|
433
|
+
follows?: string[] | undefined;
|
|
434
|
+
precedes?: string[] | undefined;
|
|
435
|
+
}, {
|
|
436
|
+
requires?: string[] | undefined;
|
|
437
|
+
suggests?: string[] | undefined;
|
|
438
|
+
conflicts?: string[] | undefined;
|
|
439
|
+
follows?: string[] | undefined;
|
|
440
|
+
precedes?: string[] | undefined;
|
|
441
|
+
}>;
|
|
317
442
|
/**
|
|
318
443
|
* Schema for tool names
|
|
319
444
|
*
|
|
@@ -420,6 +545,43 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
420
545
|
* Replacement tool name - if provided, must be valid tool name
|
|
421
546
|
*/
|
|
422
547
|
replacedBy: z.ZodOptional<z.ZodString>;
|
|
548
|
+
/**
|
|
549
|
+
* Tool relations - defines relationships with other tools
|
|
550
|
+
*/
|
|
551
|
+
relations: z.ZodOptional<z.ZodObject<{
|
|
552
|
+
/**
|
|
553
|
+
* Tools that must be called before this tool
|
|
554
|
+
*/
|
|
555
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
556
|
+
/**
|
|
557
|
+
* Tools that work well with this tool
|
|
558
|
+
*/
|
|
559
|
+
suggests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
560
|
+
/**
|
|
561
|
+
* Tools that conflict with this tool
|
|
562
|
+
*/
|
|
563
|
+
conflicts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
564
|
+
/**
|
|
565
|
+
* Tools this typically follows in a workflow
|
|
566
|
+
*/
|
|
567
|
+
follows: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
568
|
+
/**
|
|
569
|
+
* Tools this typically precedes in a workflow
|
|
570
|
+
*/
|
|
571
|
+
precedes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
572
|
+
}, "strip", z.ZodTypeAny, {
|
|
573
|
+
requires?: string[] | undefined;
|
|
574
|
+
suggests?: string[] | undefined;
|
|
575
|
+
conflicts?: string[] | undefined;
|
|
576
|
+
follows?: string[] | undefined;
|
|
577
|
+
precedes?: string[] | undefined;
|
|
578
|
+
}, {
|
|
579
|
+
requires?: string[] | undefined;
|
|
580
|
+
suggests?: string[] | undefined;
|
|
581
|
+
conflicts?: string[] | undefined;
|
|
582
|
+
follows?: string[] | undefined;
|
|
583
|
+
precedes?: string[] | undefined;
|
|
584
|
+
}>>;
|
|
423
585
|
}, "strip", z.ZodTypeAny, {
|
|
424
586
|
description: string;
|
|
425
587
|
name: string;
|
|
@@ -438,6 +600,13 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
438
600
|
author?: string | undefined;
|
|
439
601
|
deprecated?: boolean | undefined;
|
|
440
602
|
replacedBy?: string | undefined;
|
|
603
|
+
relations?: {
|
|
604
|
+
requires?: string[] | undefined;
|
|
605
|
+
suggests?: string[] | undefined;
|
|
606
|
+
conflicts?: string[] | undefined;
|
|
607
|
+
follows?: string[] | undefined;
|
|
608
|
+
precedes?: string[] | undefined;
|
|
609
|
+
} | undefined;
|
|
441
610
|
}, {
|
|
442
611
|
description: string;
|
|
443
612
|
name: string;
|
|
@@ -456,6 +625,13 @@ declare const ToolMetadataSchema: z.ZodObject<{
|
|
|
456
625
|
author?: string | undefined;
|
|
457
626
|
deprecated?: boolean | undefined;
|
|
458
627
|
replacedBy?: string | undefined;
|
|
628
|
+
relations?: {
|
|
629
|
+
requires?: string[] | undefined;
|
|
630
|
+
suggests?: string[] | undefined;
|
|
631
|
+
conflicts?: string[] | undefined;
|
|
632
|
+
follows?: string[] | undefined;
|
|
633
|
+
precedes?: string[] | undefined;
|
|
634
|
+
} | undefined;
|
|
459
635
|
}>;
|
|
460
636
|
/**
|
|
461
637
|
* Helper function to validate tool metadata
|
|
@@ -496,6 +672,13 @@ declare function validateToolMetadata(metadata: unknown): z.SafeParseReturnType<
|
|
|
496
672
|
author?: string | undefined;
|
|
497
673
|
deprecated?: boolean | undefined;
|
|
498
674
|
replacedBy?: string | undefined;
|
|
675
|
+
relations?: {
|
|
676
|
+
requires?: string[] | undefined;
|
|
677
|
+
suggests?: string[] | undefined;
|
|
678
|
+
conflicts?: string[] | undefined;
|
|
679
|
+
follows?: string[] | undefined;
|
|
680
|
+
precedes?: string[] | undefined;
|
|
681
|
+
} | undefined;
|
|
499
682
|
}, {
|
|
500
683
|
description: string;
|
|
501
684
|
name: string;
|
|
@@ -514,6 +697,13 @@ declare function validateToolMetadata(metadata: unknown): z.SafeParseReturnType<
|
|
|
514
697
|
author?: string | undefined;
|
|
515
698
|
deprecated?: boolean | undefined;
|
|
516
699
|
replacedBy?: string | undefined;
|
|
700
|
+
relations?: {
|
|
701
|
+
requires?: string[] | undefined;
|
|
702
|
+
suggests?: string[] | undefined;
|
|
703
|
+
conflicts?: string[] | undefined;
|
|
704
|
+
follows?: string[] | undefined;
|
|
705
|
+
precedes?: string[] | undefined;
|
|
706
|
+
} | undefined;
|
|
517
707
|
}>;
|
|
518
708
|
/**
|
|
519
709
|
* Helper function to validate tool name
|
|
@@ -802,6 +992,56 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
802
992
|
* @param author - Tool author name
|
|
803
993
|
*/
|
|
804
994
|
author(author: string): this;
|
|
995
|
+
/**
|
|
996
|
+
* Set tools that must be called before this tool (optional)
|
|
997
|
+
*
|
|
998
|
+
* @param tools - Array of tool names that are required
|
|
999
|
+
* @example
|
|
1000
|
+
* ```ts
|
|
1001
|
+
* .requires(['view-file', 'search-codebase'])
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
requires(tools: string[]): this;
|
|
1005
|
+
/**
|
|
1006
|
+
* Set tools that work well with this tool (optional)
|
|
1007
|
+
*
|
|
1008
|
+
* @param tools - Array of tool names that are suggested
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* .suggests(['run-tests', 'format-code'])
|
|
1012
|
+
* ```
|
|
1013
|
+
*/
|
|
1014
|
+
suggests(tools: string[]): this;
|
|
1015
|
+
/**
|
|
1016
|
+
* Set tools that conflict with this tool (optional)
|
|
1017
|
+
*
|
|
1018
|
+
* @param tools - Array of tool names that conflict
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* .conflicts(['delete-file'])
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
conflicts(tools: string[]): this;
|
|
1025
|
+
/**
|
|
1026
|
+
* Set tools this typically follows in a workflow (optional)
|
|
1027
|
+
*
|
|
1028
|
+
* @param tools - Array of tool names this follows
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```ts
|
|
1031
|
+
* .follows(['search-codebase', 'view-file'])
|
|
1032
|
+
* ```
|
|
1033
|
+
*/
|
|
1034
|
+
follows(tools: string[]): this;
|
|
1035
|
+
/**
|
|
1036
|
+
* Set tools this typically precedes in a workflow (optional)
|
|
1037
|
+
*
|
|
1038
|
+
* @param tools - Array of tool names this precedes
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* .precedes(['run-tests'])
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
precedes(tools: string[]): this;
|
|
805
1045
|
/**
|
|
806
1046
|
* Set the input schema (required)
|
|
807
1047
|
*
|
|
@@ -886,12 +1126,29 @@ interface PromptOptions {
|
|
|
886
1126
|
includeNotes?: boolean;
|
|
887
1127
|
/** Include limitations in the prompt */
|
|
888
1128
|
includeLimitations?: boolean;
|
|
1129
|
+
/** Include tool relations in the prompt */
|
|
1130
|
+
includeRelations?: boolean;
|
|
889
1131
|
/** Group tools by category */
|
|
890
1132
|
groupByCategory?: boolean;
|
|
891
1133
|
/** Filter by specific categories */
|
|
892
1134
|
categories?: ToolCategory[];
|
|
893
1135
|
/** Maximum number of examples to include per tool */
|
|
894
1136
|
maxExamplesPerTool?: number;
|
|
1137
|
+
/**
|
|
1138
|
+
* Minimal mode - only supplementary context, not full definitions
|
|
1139
|
+
*
|
|
1140
|
+
* Use this when tool definitions are sent via API (OpenAI, Anthropic, etc.)
|
|
1141
|
+
*
|
|
1142
|
+
* When true:
|
|
1143
|
+
* - Excludes basic tool name/description/parameters
|
|
1144
|
+
* - Includes only relations, examples, notes, limitations
|
|
1145
|
+
* - Tool names are used as headers for matching
|
|
1146
|
+
*
|
|
1147
|
+
* When false (default):
|
|
1148
|
+
* - Includes full tool definitions (current behavior)
|
|
1149
|
+
* - Backward compatible
|
|
1150
|
+
*/
|
|
1151
|
+
minimal?: boolean;
|
|
895
1152
|
}
|
|
896
1153
|
/**
|
|
897
1154
|
* Tool Registry - Central registry for managing tools
|
|
@@ -1182,6 +1439,14 @@ declare class ToolRegistry {
|
|
|
1182
1439
|
* @private
|
|
1183
1440
|
*/
|
|
1184
1441
|
private formatToolForPrompt;
|
|
1442
|
+
/**
|
|
1443
|
+
* Format tool relations for inclusion in a prompt
|
|
1444
|
+
*
|
|
1445
|
+
* @param relations - The relations to format
|
|
1446
|
+
* @returns Array of formatted lines
|
|
1447
|
+
* @private
|
|
1448
|
+
*/
|
|
1449
|
+
private formatRelations;
|
|
1185
1450
|
}
|
|
1186
1451
|
|
|
1187
1452
|
/**
|
|
@@ -4073,4 +4338,4 @@ declare class CircuitBreaker {
|
|
|
4073
4338
|
}
|
|
4074
4339
|
declare function createCircuitBreaker(options: CircuitBreakerOptions): CircuitBreaker;
|
|
4075
4340
|
|
|
4076
|
-
export { AgentError, type AggregateNode, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type ReducerFunction, RegistryEvent, type RequestConfig, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolSimulatorConfig, type TracingOptions, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getToolDescription, getToolJsonSchema, isMemoryCheckpointer, isTracingEnabled, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, retry, safeValidateSchemaDescriptions, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withErrorHandler, withMetrics, withRetry, withTimeout, withTracing };
|
|
4341
|
+
export { AgentError, type AggregateNode, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type ReducerFunction, RegistryEvent, type RequestConfig, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getToolDescription, getToolJsonSchema, isMemoryCheckpointer, isTracingEnabled, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, retry, safeValidateSchemaDescriptions, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withErrorHandler, withMetrics, withRetry, withTimeout, withTracing };
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,28 @@ var ToolExampleSchema = z.object({
|
|
|
35
35
|
*/
|
|
36
36
|
explanation: z.string().min(1).optional()
|
|
37
37
|
});
|
|
38
|
+
var ToolRelationsSchema = z.object({
|
|
39
|
+
/**
|
|
40
|
+
* Tools that must be called before this tool
|
|
41
|
+
*/
|
|
42
|
+
requires: z.array(z.string().min(1)).optional(),
|
|
43
|
+
/**
|
|
44
|
+
* Tools that work well with this tool
|
|
45
|
+
*/
|
|
46
|
+
suggests: z.array(z.string().min(1)).optional(),
|
|
47
|
+
/**
|
|
48
|
+
* Tools that conflict with this tool
|
|
49
|
+
*/
|
|
50
|
+
conflicts: z.array(z.string().min(1)).optional(),
|
|
51
|
+
/**
|
|
52
|
+
* Tools this typically follows in a workflow
|
|
53
|
+
*/
|
|
54
|
+
follows: z.array(z.string().min(1)).optional(),
|
|
55
|
+
/**
|
|
56
|
+
* Tools this typically precedes in a workflow
|
|
57
|
+
*/
|
|
58
|
+
precedes: z.array(z.string().min(1)).optional()
|
|
59
|
+
});
|
|
38
60
|
var ToolNameSchema = z.string().min(2, "Tool name must be at least 2 characters").max(50, "Tool name must be at most 50 characters").regex(
|
|
39
61
|
/^[a-z][a-z0-9-]*[a-z0-9]$/,
|
|
40
62
|
"Tool name must be kebab-case (lowercase letters, numbers, hyphens only, must start with a letter)"
|
|
@@ -93,7 +115,11 @@ var ToolMetadataSchema = z.object({
|
|
|
93
115
|
/**
|
|
94
116
|
* Replacement tool name - if provided, must be valid tool name
|
|
95
117
|
*/
|
|
96
|
-
replacedBy: ToolNameSchema.optional()
|
|
118
|
+
replacedBy: ToolNameSchema.optional(),
|
|
119
|
+
/**
|
|
120
|
+
* Tool relations - defines relationships with other tools
|
|
121
|
+
*/
|
|
122
|
+
relations: ToolRelationsSchema.optional()
|
|
97
123
|
});
|
|
98
124
|
function validateToolMetadata(metadata) {
|
|
99
125
|
return ToolMetadataSchema.safeParse(metadata);
|
|
@@ -402,13 +428,93 @@ var ToolBuilder = class {
|
|
|
402
428
|
}
|
|
403
429
|
/**
|
|
404
430
|
* Set author (optional)
|
|
405
|
-
*
|
|
431
|
+
*
|
|
406
432
|
* @param author - Tool author name
|
|
407
433
|
*/
|
|
408
434
|
author(author) {
|
|
409
435
|
this.metadata.author = author;
|
|
410
436
|
return this;
|
|
411
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Set tools that must be called before this tool (optional)
|
|
440
|
+
*
|
|
441
|
+
* @param tools - Array of tool names that are required
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* .requires(['view-file', 'search-codebase'])
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
requires(tools) {
|
|
448
|
+
if (!this.metadata.relations) {
|
|
449
|
+
this.metadata.relations = {};
|
|
450
|
+
}
|
|
451
|
+
this.metadata.relations.requires = tools;
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Set tools that work well with this tool (optional)
|
|
456
|
+
*
|
|
457
|
+
* @param tools - Array of tool names that are suggested
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* .suggests(['run-tests', 'format-code'])
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
suggests(tools) {
|
|
464
|
+
if (!this.metadata.relations) {
|
|
465
|
+
this.metadata.relations = {};
|
|
466
|
+
}
|
|
467
|
+
this.metadata.relations.suggests = tools;
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Set tools that conflict with this tool (optional)
|
|
472
|
+
*
|
|
473
|
+
* @param tools - Array of tool names that conflict
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* .conflicts(['delete-file'])
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
conflicts(tools) {
|
|
480
|
+
if (!this.metadata.relations) {
|
|
481
|
+
this.metadata.relations = {};
|
|
482
|
+
}
|
|
483
|
+
this.metadata.relations.conflicts = tools;
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Set tools this typically follows in a workflow (optional)
|
|
488
|
+
*
|
|
489
|
+
* @param tools - Array of tool names this follows
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* .follows(['search-codebase', 'view-file'])
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
follows(tools) {
|
|
496
|
+
if (!this.metadata.relations) {
|
|
497
|
+
this.metadata.relations = {};
|
|
498
|
+
}
|
|
499
|
+
this.metadata.relations.follows = tools;
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Set tools this typically precedes in a workflow (optional)
|
|
504
|
+
*
|
|
505
|
+
* @param tools - Array of tool names this precedes
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* .precedes(['run-tests'])
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
precedes(tools) {
|
|
512
|
+
if (!this.metadata.relations) {
|
|
513
|
+
this.metadata.relations = {};
|
|
514
|
+
}
|
|
515
|
+
this.metadata.relations.precedes = tools;
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
412
518
|
/**
|
|
413
519
|
* Set the input schema (required)
|
|
414
520
|
*
|
|
@@ -890,9 +996,11 @@ var ToolRegistry = class {
|
|
|
890
996
|
includeExamples = false,
|
|
891
997
|
includeNotes = false,
|
|
892
998
|
includeLimitations = false,
|
|
999
|
+
includeRelations = false,
|
|
893
1000
|
groupByCategory = false,
|
|
894
1001
|
categories,
|
|
895
|
-
maxExamplesPerTool
|
|
1002
|
+
maxExamplesPerTool,
|
|
1003
|
+
minimal = false
|
|
896
1004
|
} = options;
|
|
897
1005
|
let tools = this.getAll();
|
|
898
1006
|
if (categories && categories.length > 0) {
|
|
@@ -918,7 +1026,9 @@ var ToolRegistry = class {
|
|
|
918
1026
|
includeExamples,
|
|
919
1027
|
includeNotes,
|
|
920
1028
|
includeLimitations,
|
|
921
|
-
|
|
1029
|
+
includeRelations,
|
|
1030
|
+
maxExamplesPerTool,
|
|
1031
|
+
minimal
|
|
922
1032
|
}));
|
|
923
1033
|
}
|
|
924
1034
|
lines.push("");
|
|
@@ -929,7 +1039,9 @@ var ToolRegistry = class {
|
|
|
929
1039
|
includeExamples,
|
|
930
1040
|
includeNotes,
|
|
931
1041
|
includeLimitations,
|
|
932
|
-
|
|
1042
|
+
includeRelations,
|
|
1043
|
+
maxExamplesPerTool,
|
|
1044
|
+
minimal
|
|
933
1045
|
}));
|
|
934
1046
|
lines.push("");
|
|
935
1047
|
}
|
|
@@ -947,6 +1059,44 @@ var ToolRegistry = class {
|
|
|
947
1059
|
formatToolForPrompt(tool, options) {
|
|
948
1060
|
const { metadata } = tool;
|
|
949
1061
|
const lines = [];
|
|
1062
|
+
if (options.minimal) {
|
|
1063
|
+
lines.push(`## ${metadata.name}`);
|
|
1064
|
+
let hasContent = false;
|
|
1065
|
+
if (options.includeRelations && metadata.relations) {
|
|
1066
|
+
const relationLines = this.formatRelations(metadata.relations);
|
|
1067
|
+
if (relationLines.length > 0) {
|
|
1068
|
+
lines.push(...relationLines);
|
|
1069
|
+
hasContent = true;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (options.includeExamples && metadata.examples && metadata.examples.length > 0) {
|
|
1073
|
+
const maxExamples = options.maxExamplesPerTool || metadata.examples.length;
|
|
1074
|
+
const examples = metadata.examples.slice(0, maxExamples);
|
|
1075
|
+
for (const example of examples) {
|
|
1076
|
+
lines.push(` Example: ${example.description}`);
|
|
1077
|
+
lines.push(` Input: ${JSON.stringify(example.input)}`);
|
|
1078
|
+
if (example.explanation) {
|
|
1079
|
+
lines.push(` ${example.explanation}`);
|
|
1080
|
+
}
|
|
1081
|
+
hasContent = true;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (options.includeNotes && metadata.usageNotes) {
|
|
1085
|
+
lines.push(` Notes: ${metadata.usageNotes}`);
|
|
1086
|
+
hasContent = true;
|
|
1087
|
+
}
|
|
1088
|
+
if (options.includeLimitations && metadata.limitations && metadata.limitations.length > 0) {
|
|
1089
|
+
lines.push(` Limitations:`);
|
|
1090
|
+
for (const limitation of metadata.limitations) {
|
|
1091
|
+
lines.push(` - ${limitation}`);
|
|
1092
|
+
}
|
|
1093
|
+
hasContent = true;
|
|
1094
|
+
}
|
|
1095
|
+
if (!hasContent) {
|
|
1096
|
+
return [];
|
|
1097
|
+
}
|
|
1098
|
+
return lines;
|
|
1099
|
+
}
|
|
950
1100
|
lines.push(`- ${metadata.name}: ${metadata.description}`);
|
|
951
1101
|
const schemaShape = tool.schema._def?.shape?.();
|
|
952
1102
|
if (schemaShape) {
|
|
@@ -960,6 +1110,12 @@ var ToolRegistry = class {
|
|
|
960
1110
|
lines.push(` Parameters: ${paramDescriptions.join(", ")}`);
|
|
961
1111
|
}
|
|
962
1112
|
}
|
|
1113
|
+
if (options.includeRelations && metadata.relations) {
|
|
1114
|
+
const relationLines = this.formatRelations(metadata.relations);
|
|
1115
|
+
if (relationLines.length > 0) {
|
|
1116
|
+
lines.push(...relationLines);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
963
1119
|
if (options.includeNotes && metadata.usageNotes) {
|
|
964
1120
|
lines.push(` Notes: ${metadata.usageNotes}`);
|
|
965
1121
|
}
|
|
@@ -982,6 +1138,32 @@ var ToolRegistry = class {
|
|
|
982
1138
|
}
|
|
983
1139
|
return lines;
|
|
984
1140
|
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Format tool relations for inclusion in a prompt
|
|
1143
|
+
*
|
|
1144
|
+
* @param relations - The relations to format
|
|
1145
|
+
* @returns Array of formatted lines
|
|
1146
|
+
* @private
|
|
1147
|
+
*/
|
|
1148
|
+
formatRelations(relations) {
|
|
1149
|
+
const lines = [];
|
|
1150
|
+
if (relations.requires && relations.requires.length > 0) {
|
|
1151
|
+
lines.push(` Requires: ${relations.requires.join(", ")}`);
|
|
1152
|
+
}
|
|
1153
|
+
if (relations.suggests && relations.suggests.length > 0) {
|
|
1154
|
+
lines.push(` Suggests: ${relations.suggests.join(", ")}`);
|
|
1155
|
+
}
|
|
1156
|
+
if (relations.conflicts && relations.conflicts.length > 0) {
|
|
1157
|
+
lines.push(` Conflicts: ${relations.conflicts.join(", ")}`);
|
|
1158
|
+
}
|
|
1159
|
+
if (relations.follows && relations.follows.length > 0) {
|
|
1160
|
+
lines.push(` Follows: ${relations.follows.join(", ")}`);
|
|
1161
|
+
}
|
|
1162
|
+
if (relations.precedes && relations.precedes.length > 0) {
|
|
1163
|
+
lines.push(` Precedes: ${relations.precedes.join(", ")}`);
|
|
1164
|
+
}
|
|
1165
|
+
return lines;
|
|
1166
|
+
}
|
|
985
1167
|
};
|
|
986
1168
|
|
|
987
1169
|
// src/tools/executor.ts
|
|
@@ -3816,6 +3998,7 @@ export {
|
|
|
3816
3998
|
ToolMetadataSchema,
|
|
3817
3999
|
ToolNameSchema,
|
|
3818
4000
|
ToolRegistry,
|
|
4001
|
+
ToolRelationsSchema,
|
|
3819
4002
|
batch,
|
|
3820
4003
|
broadcast,
|
|
3821
4004
|
cache,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Core abstractions for AgentForge - production-ready deep agents 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",
|
|
@@ -64,5 +53,16 @@
|
|
|
64
53
|
},
|
|
65
54
|
"dependencies": {
|
|
66
55
|
"zod-to-json-schema": "^3.25.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
59
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
60
|
+
"test": "vitest",
|
|
61
|
+
"test:coverage": "vitest --coverage",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"lint": "eslint src",
|
|
64
|
+
"lint:fix": "eslint src --fix",
|
|
65
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
66
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|