@opperai/agents 0.3.0 → 0.4.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/README.md +9 -5
- package/dist/index.cjs +189 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +270 -50
- package/dist/index.d.ts +270 -50
- package/dist/index.js +188 -141
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -201,6 +201,8 @@ interface ToolSuccess<TOutput> {
|
|
|
201
201
|
toolName: string;
|
|
202
202
|
output: TOutput;
|
|
203
203
|
metadata: Record<string, unknown>;
|
|
204
|
+
/** Optional usage statistics - only present for agent-as-tool, omitted for regular tools */
|
|
205
|
+
usage?: Usage;
|
|
204
206
|
startedAt?: number;
|
|
205
207
|
finishedAt?: number;
|
|
206
208
|
}
|
|
@@ -209,14 +211,31 @@ interface ToolFailure {
|
|
|
209
211
|
toolName: string;
|
|
210
212
|
error: Error | string;
|
|
211
213
|
metadata: Record<string, unknown>;
|
|
214
|
+
/** Optional usage statistics - included even on failure since partial work may have been done */
|
|
215
|
+
usage?: Usage;
|
|
212
216
|
startedAt?: number;
|
|
213
217
|
finishedAt?: number;
|
|
214
218
|
}
|
|
215
219
|
type ToolResult<TOutput = unknown> = ToolSuccess<TOutput> | ToolFailure;
|
|
220
|
+
/**
|
|
221
|
+
* Example of a tool execution with input and expected output
|
|
222
|
+
*/
|
|
223
|
+
interface ToolExample<TInput, TOutput> {
|
|
224
|
+
/** Example input to the tool */
|
|
225
|
+
input: TInput;
|
|
226
|
+
/** Expected output from the tool */
|
|
227
|
+
output: TOutput;
|
|
228
|
+
/** Optional description of what this example demonstrates */
|
|
229
|
+
description?: string;
|
|
230
|
+
}
|
|
216
231
|
interface ToolDefinition<TInput, TOutput> {
|
|
217
232
|
name: string;
|
|
218
233
|
description?: string;
|
|
219
234
|
schema?: ZodType<TInput>;
|
|
235
|
+
/** Optional schema describing the tool's output structure */
|
|
236
|
+
outputSchema?: ZodType<TOutput>;
|
|
237
|
+
/** Optional examples of tool usage to help the LLM understand expected behavior */
|
|
238
|
+
examples?: Array<ToolExample<TInput, TOutput>>;
|
|
220
239
|
execute: (input: TInput, context: ToolExecutionContext) => MaybePromise<ToolResult<TOutput>>;
|
|
221
240
|
metadata?: Record<string, unknown>;
|
|
222
241
|
timeoutMs?: number;
|
|
@@ -229,6 +248,8 @@ interface ToolProvider {
|
|
|
229
248
|
}
|
|
230
249
|
interface ToolResultInit {
|
|
231
250
|
metadata?: Record<string, unknown>;
|
|
251
|
+
/** Optional usage statistics - only for agent-as-tool */
|
|
252
|
+
usage?: Usage;
|
|
232
253
|
startedAt?: number;
|
|
233
254
|
finishedAt?: number;
|
|
234
255
|
}
|
|
@@ -247,6 +268,55 @@ declare const normalizeToolEntries: (entries: Array<Tool<unknown, unknown> | Too
|
|
|
247
268
|
providers: Array<ToolProvider>;
|
|
248
269
|
};
|
|
249
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Base usage schema without breakdown (to avoid circular reference)
|
|
273
|
+
*/
|
|
274
|
+
declare const BaseUsageSchema: z.ZodObject<{
|
|
275
|
+
requests: z.ZodDefault<z.ZodNumber>;
|
|
276
|
+
inputTokens: z.ZodDefault<z.ZodNumber>;
|
|
277
|
+
outputTokens: z.ZodDefault<z.ZodNumber>;
|
|
278
|
+
totalTokens: z.ZodDefault<z.ZodNumber>;
|
|
279
|
+
cost: z.ZodDefault<z.ZodObject<{
|
|
280
|
+
generation: z.ZodDefault<z.ZodNumber>;
|
|
281
|
+
platform: z.ZodDefault<z.ZodNumber>;
|
|
282
|
+
total: z.ZodDefault<z.ZodNumber>;
|
|
283
|
+
}, "strip", z.ZodTypeAny, {
|
|
284
|
+
generation: number;
|
|
285
|
+
platform: number;
|
|
286
|
+
total: number;
|
|
287
|
+
}, {
|
|
288
|
+
generation?: number | undefined;
|
|
289
|
+
platform?: number | undefined;
|
|
290
|
+
total?: number | undefined;
|
|
291
|
+
}>>;
|
|
292
|
+
}, "strip", z.ZodTypeAny, {
|
|
293
|
+
requests: number;
|
|
294
|
+
inputTokens: number;
|
|
295
|
+
outputTokens: number;
|
|
296
|
+
totalTokens: number;
|
|
297
|
+
cost: {
|
|
298
|
+
generation: number;
|
|
299
|
+
platform: number;
|
|
300
|
+
total: number;
|
|
301
|
+
};
|
|
302
|
+
}, {
|
|
303
|
+
requests?: number | undefined;
|
|
304
|
+
inputTokens?: number | undefined;
|
|
305
|
+
outputTokens?: number | undefined;
|
|
306
|
+
totalTokens?: number | undefined;
|
|
307
|
+
cost?: {
|
|
308
|
+
generation?: number | undefined;
|
|
309
|
+
platform?: number | undefined;
|
|
310
|
+
total?: number | undefined;
|
|
311
|
+
} | undefined;
|
|
312
|
+
}>;
|
|
313
|
+
/**
|
|
314
|
+
* Base usage type (without breakdown) - used for breakdown entries
|
|
315
|
+
*/
|
|
316
|
+
type BaseUsage = z.infer<typeof BaseUsageSchema>;
|
|
317
|
+
/**
|
|
318
|
+
* Full usage schema with optional breakdown for nested agent tracking
|
|
319
|
+
*/
|
|
250
320
|
declare const UsageSchema: z.ZodObject<{
|
|
251
321
|
requests: z.ZodDefault<z.ZodNumber>;
|
|
252
322
|
inputTokens: z.ZodDefault<z.ZodNumber>;
|
|
@@ -265,6 +335,50 @@ declare const UsageSchema: z.ZodObject<{
|
|
|
265
335
|
platform?: number | undefined;
|
|
266
336
|
total?: number | undefined;
|
|
267
337
|
}>>;
|
|
338
|
+
} & {
|
|
339
|
+
/**
|
|
340
|
+
* Optional breakdown of usage by source (agent name).
|
|
341
|
+
* Only present when nested agents are used.
|
|
342
|
+
*/
|
|
343
|
+
breakdown: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodObject<{
|
|
344
|
+
requests: z.ZodDefault<z.ZodNumber>;
|
|
345
|
+
inputTokens: z.ZodDefault<z.ZodNumber>;
|
|
346
|
+
outputTokens: z.ZodDefault<z.ZodNumber>;
|
|
347
|
+
totalTokens: z.ZodDefault<z.ZodNumber>;
|
|
348
|
+
cost: z.ZodDefault<z.ZodObject<{
|
|
349
|
+
generation: z.ZodDefault<z.ZodNumber>;
|
|
350
|
+
platform: z.ZodDefault<z.ZodNumber>;
|
|
351
|
+
total: z.ZodDefault<z.ZodNumber>;
|
|
352
|
+
}, "strip", z.ZodTypeAny, {
|
|
353
|
+
generation: number;
|
|
354
|
+
platform: number;
|
|
355
|
+
total: number;
|
|
356
|
+
}, {
|
|
357
|
+
generation?: number | undefined;
|
|
358
|
+
platform?: number | undefined;
|
|
359
|
+
total?: number | undefined;
|
|
360
|
+
}>>;
|
|
361
|
+
}, "strip", z.ZodTypeAny, {
|
|
362
|
+
requests: number;
|
|
363
|
+
inputTokens: number;
|
|
364
|
+
outputTokens: number;
|
|
365
|
+
totalTokens: number;
|
|
366
|
+
cost: {
|
|
367
|
+
generation: number;
|
|
368
|
+
platform: number;
|
|
369
|
+
total: number;
|
|
370
|
+
};
|
|
371
|
+
}, {
|
|
372
|
+
requests?: number | undefined;
|
|
373
|
+
inputTokens?: number | undefined;
|
|
374
|
+
outputTokens?: number | undefined;
|
|
375
|
+
totalTokens?: number | undefined;
|
|
376
|
+
cost?: {
|
|
377
|
+
generation?: number | undefined;
|
|
378
|
+
platform?: number | undefined;
|
|
379
|
+
total?: number | undefined;
|
|
380
|
+
} | undefined;
|
|
381
|
+
}>>>>;
|
|
268
382
|
}, "strip", z.ZodTypeAny, {
|
|
269
383
|
requests: number;
|
|
270
384
|
inputTokens: number;
|
|
@@ -275,6 +389,17 @@ declare const UsageSchema: z.ZodObject<{
|
|
|
275
389
|
platform: number;
|
|
276
390
|
total: number;
|
|
277
391
|
};
|
|
392
|
+
breakdown?: Record<string, {
|
|
393
|
+
requests: number;
|
|
394
|
+
inputTokens: number;
|
|
395
|
+
outputTokens: number;
|
|
396
|
+
totalTokens: number;
|
|
397
|
+
cost: {
|
|
398
|
+
generation: number;
|
|
399
|
+
platform: number;
|
|
400
|
+
total: number;
|
|
401
|
+
};
|
|
402
|
+
}> | undefined;
|
|
278
403
|
}, {
|
|
279
404
|
requests?: number | undefined;
|
|
280
405
|
inputTokens?: number | undefined;
|
|
@@ -285,8 +410,27 @@ declare const UsageSchema: z.ZodObject<{
|
|
|
285
410
|
platform?: number | undefined;
|
|
286
411
|
total?: number | undefined;
|
|
287
412
|
} | undefined;
|
|
413
|
+
breakdown?: Record<string, {
|
|
414
|
+
requests?: number | undefined;
|
|
415
|
+
inputTokens?: number | undefined;
|
|
416
|
+
outputTokens?: number | undefined;
|
|
417
|
+
totalTokens?: number | undefined;
|
|
418
|
+
cost?: {
|
|
419
|
+
generation?: number | undefined;
|
|
420
|
+
platform?: number | undefined;
|
|
421
|
+
total?: number | undefined;
|
|
422
|
+
} | undefined;
|
|
423
|
+
}> | undefined;
|
|
288
424
|
}>;
|
|
289
425
|
type Usage = z.infer<typeof UsageSchema>;
|
|
426
|
+
/**
|
|
427
|
+
* Create an empty usage object with all values set to 0
|
|
428
|
+
*/
|
|
429
|
+
declare function createEmptyUsage(): Usage;
|
|
430
|
+
/**
|
|
431
|
+
* Add two usage objects together, returning a new usage object
|
|
432
|
+
*/
|
|
433
|
+
declare function addUsage(a: Usage, b: Usage): Usage;
|
|
290
434
|
declare const ExecutionCycleSchema: z.ZodObject<{
|
|
291
435
|
iteration: z.ZodNumber;
|
|
292
436
|
thought: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
@@ -414,6 +558,21 @@ declare class AgentContext {
|
|
|
414
558
|
updatedAt: number;
|
|
415
559
|
constructor(options: AgentContextOptions);
|
|
416
560
|
updateUsage(delta: Usage): void;
|
|
561
|
+
/**
|
|
562
|
+
* Update usage with source tracking for nested agent aggregation.
|
|
563
|
+
* This method updates the total usage AND tracks it by source in the breakdown.
|
|
564
|
+
*
|
|
565
|
+
* @param source - The source name (typically the agent/tool name)
|
|
566
|
+
* @param delta - The usage to add
|
|
567
|
+
*/
|
|
568
|
+
updateUsageWithSource(source: string, delta: Usage): void;
|
|
569
|
+
/**
|
|
570
|
+
* Clean up the usage breakdown if it only contains the parent agent.
|
|
571
|
+
* This ensures breakdown is only present when there are nested agents.
|
|
572
|
+
*
|
|
573
|
+
* @param parentAgentName - The name of the parent agent to check for
|
|
574
|
+
*/
|
|
575
|
+
cleanupBreakdownIfOnlyParent(parentAgentName: string): void;
|
|
417
576
|
addCycle(cycle: ExecutionCycle): ExecutionCycle;
|
|
418
577
|
recordToolCall(call: Omit<ToolCallRecord, "id">): ToolCallRecord;
|
|
419
578
|
getContextSize(): number;
|
|
@@ -622,28 +781,6 @@ declare class HookManager {
|
|
|
622
781
|
}
|
|
623
782
|
declare const createHookManager: (logger?: AgentLogger) => HookManager;
|
|
624
783
|
|
|
625
|
-
declare const AgentEvents: {
|
|
626
|
-
readonly StreamStart: "stream:start";
|
|
627
|
-
readonly StreamChunk: "stream:chunk";
|
|
628
|
-
readonly StreamEnd: "stream:end";
|
|
629
|
-
readonly StreamError: "stream:error";
|
|
630
|
-
};
|
|
631
|
-
type AgentEventName = (typeof AgentEvents)[keyof typeof AgentEvents];
|
|
632
|
-
type AgentEventPayloadMap = Pick<HookPayloadMap, AgentEventName>;
|
|
633
|
-
type AgentEventPayload<E extends AgentEventName> = AgentEventPayloadMap[E];
|
|
634
|
-
type AgentEventListener<E extends AgentEventName> = (payload: AgentEventPayload<E>) => void;
|
|
635
|
-
declare class AgentEventEmitter {
|
|
636
|
-
private readonly registry;
|
|
637
|
-
private readonly logger;
|
|
638
|
-
constructor(logger?: AgentLogger);
|
|
639
|
-
on<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): () => void;
|
|
640
|
-
once<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): () => void;
|
|
641
|
-
off<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): void;
|
|
642
|
-
emit<E extends AgentEventName>(event: E, payload: AgentEventPayload<E>): void;
|
|
643
|
-
removeAllListeners(event?: AgentEventName): void;
|
|
644
|
-
listenerCount(event?: AgentEventName): number;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
784
|
/**
|
|
648
785
|
* Options for generating agent flow visualization
|
|
649
786
|
*/
|
|
@@ -719,8 +856,8 @@ declare const MemoryEntrySchema: z.ZodObject<{
|
|
|
719
856
|
updatedAt: number;
|
|
720
857
|
accessCount: number;
|
|
721
858
|
};
|
|
722
|
-
description: string;
|
|
723
859
|
key: string;
|
|
860
|
+
description: string;
|
|
724
861
|
value?: unknown;
|
|
725
862
|
}, {
|
|
726
863
|
metadata: {
|
|
@@ -728,8 +865,8 @@ declare const MemoryEntrySchema: z.ZodObject<{
|
|
|
728
865
|
updatedAt: number;
|
|
729
866
|
accessCount?: number | undefined;
|
|
730
867
|
};
|
|
731
|
-
description: string;
|
|
732
868
|
key: string;
|
|
869
|
+
description: string;
|
|
733
870
|
value?: unknown;
|
|
734
871
|
}>;
|
|
735
872
|
type MemoryEntry = z.infer<typeof MemoryEntrySchema>;
|
|
@@ -885,19 +1022,19 @@ interface BaseAgentConfig<TInput, TOutput> {
|
|
|
885
1022
|
/**
|
|
886
1023
|
* Register a handler invoked when a streaming call starts.
|
|
887
1024
|
*/
|
|
888
|
-
onStreamStart?:
|
|
1025
|
+
onStreamStart?: HookHandler<typeof HookEvents.StreamStart>;
|
|
889
1026
|
/**
|
|
890
1027
|
* Register a handler invoked for each streaming chunk.
|
|
891
1028
|
*/
|
|
892
|
-
onStreamChunk?:
|
|
1029
|
+
onStreamChunk?: HookHandler<typeof HookEvents.StreamChunk>;
|
|
893
1030
|
/**
|
|
894
1031
|
* Register a handler invoked when a streaming call ends.
|
|
895
1032
|
*/
|
|
896
|
-
onStreamEnd?:
|
|
1033
|
+
onStreamEnd?: HookHandler<typeof HookEvents.StreamEnd>;
|
|
897
1034
|
/**
|
|
898
1035
|
* Register a handler invoked when streaming encounters an error.
|
|
899
1036
|
*/
|
|
900
|
-
onStreamError?:
|
|
1037
|
+
onStreamError?: HookHandler<typeof HookEvents.StreamError>;
|
|
901
1038
|
/**
|
|
902
1039
|
* Enable memory subsystem
|
|
903
1040
|
* @default false
|
|
@@ -989,10 +1126,6 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
989
1126
|
* Hook manager for lifecycle events
|
|
990
1127
|
*/
|
|
991
1128
|
protected readonly hooks: HookManager;
|
|
992
|
-
/**
|
|
993
|
-
* Event dispatcher for runtime events (notably streaming)
|
|
994
|
-
*/
|
|
995
|
-
protected readonly events: AgentEventEmitter;
|
|
996
1129
|
/**
|
|
997
1130
|
* Registry of available tools
|
|
998
1131
|
*/
|
|
@@ -1047,11 +1180,38 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1047
1180
|
* Main entry point for agent execution.
|
|
1048
1181
|
* Orchestrates lifecycle: context initialization, hook triggering, loop execution, teardown.
|
|
1049
1182
|
*
|
|
1183
|
+
* **Note:** This method will be removed in a future update.
|
|
1184
|
+
* Consider using {@link run} instead, which returns both result and usage statistics.
|
|
1185
|
+
*
|
|
1050
1186
|
* @param input - Input to process
|
|
1051
1187
|
* @param parentSpanId - Optional parent span ID for tracing
|
|
1052
1188
|
* @returns Processed output
|
|
1053
1189
|
*/
|
|
1054
1190
|
process(input: TInput, parentSpanId?: string): Promise<TOutput>;
|
|
1191
|
+
/**
|
|
1192
|
+
* Process input and return both result and usage statistics.
|
|
1193
|
+
* This is the recommended method for agent execution.
|
|
1194
|
+
*
|
|
1195
|
+
* @param input - Input to process
|
|
1196
|
+
* @param parentSpanId - Optional parent span ID for tracing
|
|
1197
|
+
* @returns Object containing the result and usage statistics
|
|
1198
|
+
*/
|
|
1199
|
+
run(input: TInput, parentSpanId?: string): Promise<{
|
|
1200
|
+
result: TOutput;
|
|
1201
|
+
usage: Usage;
|
|
1202
|
+
}>;
|
|
1203
|
+
/**
|
|
1204
|
+
* Internal method that executes the process and returns both result and usage.
|
|
1205
|
+
* This is the core implementation shared by process() and run().
|
|
1206
|
+
*
|
|
1207
|
+
* @param input - Input to process
|
|
1208
|
+
* @param parentSpanId - Optional parent span ID for tracing
|
|
1209
|
+
* @returns Object containing the result and usage statistics
|
|
1210
|
+
*/
|
|
1211
|
+
protected executeProcess(input: TInput, parentSpanId?: string): Promise<{
|
|
1212
|
+
result: TOutput;
|
|
1213
|
+
usage: Usage;
|
|
1214
|
+
}>;
|
|
1055
1215
|
/**
|
|
1056
1216
|
* Abstract method implementing the agent's main loop logic.
|
|
1057
1217
|
* Must be implemented by concrete agent classes.
|
|
@@ -1111,6 +1271,8 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1111
1271
|
addToolProvider(provider: ToolProvider): void;
|
|
1112
1272
|
/**
|
|
1113
1273
|
* Convert this agent into a tool that can be used by other agents.
|
|
1274
|
+
* When used as a tool, the nested agent's usage statistics are propagated
|
|
1275
|
+
* back to the parent agent for aggregation.
|
|
1114
1276
|
*
|
|
1115
1277
|
* @param toolName - Optional custom name for the tool (defaults to agent name)
|
|
1116
1278
|
* @param toolDescription - Optional custom description (defaults to agent description)
|
|
@@ -1127,27 +1289,29 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1127
1289
|
registerHook<E extends HookEventName>(event: E, handler: HookHandler<E>): () => void;
|
|
1128
1290
|
/**
|
|
1129
1291
|
* Register an event listener.
|
|
1292
|
+
* This is equivalent to registerHook() - both methods use the unified hook system.
|
|
1130
1293
|
*
|
|
1131
|
-
* @param event - Event name
|
|
1294
|
+
* @param event - Event name (any HookEvents value)
|
|
1132
1295
|
* @param listener - Listener callback
|
|
1133
1296
|
* @returns Cleanup function to unregister the listener
|
|
1134
1297
|
*/
|
|
1135
|
-
on<E extends
|
|
1298
|
+
on<E extends HookEventName>(event: E, listener: HookHandler<E>): () => void;
|
|
1136
1299
|
/**
|
|
1137
1300
|
* Register a one-time event listener that removes itself after the first call.
|
|
1301
|
+
* This is equivalent to calling registerHook() with a self-removing handler.
|
|
1138
1302
|
*
|
|
1139
|
-
* @param event - Event name
|
|
1303
|
+
* @param event - Event name (any HookEvents value)
|
|
1140
1304
|
* @param listener - Listener callback
|
|
1141
1305
|
* @returns Cleanup function (no-op once listener fires)
|
|
1142
1306
|
*/
|
|
1143
|
-
once<E extends
|
|
1307
|
+
once<E extends HookEventName>(event: E, listener: HookHandler<E>): () => void;
|
|
1144
1308
|
/**
|
|
1145
1309
|
* Remove a previously registered event listener.
|
|
1146
1310
|
*
|
|
1147
|
-
* @param event - Event name
|
|
1311
|
+
* @param event - Event name (any HookEvents value)
|
|
1148
1312
|
* @param listener - Listener callback to remove
|
|
1149
1313
|
*/
|
|
1150
|
-
off<E extends
|
|
1314
|
+
off<E extends HookEventName>(event: E, listener: HookHandler<E>): void;
|
|
1151
1315
|
/**
|
|
1152
1316
|
* Trigger a hook event with a payload.
|
|
1153
1317
|
* Swallows errors to prevent hook failures from breaking agent execution.
|
|
@@ -1156,13 +1320,6 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1156
1320
|
* @param payload - Event payload
|
|
1157
1321
|
*/
|
|
1158
1322
|
protected triggerHook<E extends HookEventName>(event: E, payload: Parameters<HookHandler<E>>[0]): Promise<void>;
|
|
1159
|
-
/**
|
|
1160
|
-
* Emit a runtime event to listeners.
|
|
1161
|
-
*
|
|
1162
|
-
* @param event - Event name
|
|
1163
|
-
* @param payload - Event payload
|
|
1164
|
-
*/
|
|
1165
|
-
protected emitAgentEvent<E extends AgentEventName>(event: E, payload: AgentEventPayload<E>): void;
|
|
1166
1323
|
/**
|
|
1167
1324
|
* Execute a tool with proper context, hooks, and error handling.
|
|
1168
1325
|
*
|
|
@@ -1203,6 +1360,57 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1203
1360
|
visualizeFlow(options?: VisualizationOptions): Promise<string>;
|
|
1204
1361
|
}
|
|
1205
1362
|
|
|
1363
|
+
/**
|
|
1364
|
+
* Event system types for backwards compatibility.
|
|
1365
|
+
*
|
|
1366
|
+
* The agent.on(), agent.once(), and agent.off() methods now use the unified
|
|
1367
|
+
* hook system internally. These type aliases are provided for backwards
|
|
1368
|
+
* compatibility with existing code that imports from this module.
|
|
1369
|
+
*
|
|
1370
|
+
* @module events
|
|
1371
|
+
*/
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* AgentEvents is an alias for HookEvents.
|
|
1375
|
+
* All 17 hook events are available through agent.on() and agent.registerHook().
|
|
1376
|
+
*/
|
|
1377
|
+
declare const AgentEvents: {
|
|
1378
|
+
readonly AgentStart: "agent:start";
|
|
1379
|
+
readonly AgentEnd: "agent:end";
|
|
1380
|
+
readonly LoopStart: "loop:start";
|
|
1381
|
+
readonly LoopEnd: "loop:end";
|
|
1382
|
+
readonly LlmCall: "llm:call";
|
|
1383
|
+
readonly LlmResponse: "llm:response";
|
|
1384
|
+
readonly ThinkEnd: "think:end";
|
|
1385
|
+
readonly BeforeTool: "tool:before";
|
|
1386
|
+
readonly AfterTool: "tool:after";
|
|
1387
|
+
readonly ToolError: "tool:error";
|
|
1388
|
+
readonly MemoryRead: "memory:read";
|
|
1389
|
+
readonly MemoryWrite: "memory:write";
|
|
1390
|
+
readonly MemoryError: "memory:error";
|
|
1391
|
+
readonly StreamStart: "stream:start";
|
|
1392
|
+
readonly StreamChunk: "stream:chunk";
|
|
1393
|
+
readonly StreamEnd: "stream:end";
|
|
1394
|
+
readonly StreamError: "stream:error";
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* AgentEventName is an alias for HookEventName.
|
|
1398
|
+
*/
|
|
1399
|
+
type AgentEventName = HookEventName;
|
|
1400
|
+
/**
|
|
1401
|
+
* AgentEventPayloadMap is an alias for HookPayloadMap.
|
|
1402
|
+
*/
|
|
1403
|
+
type AgentEventPayloadMap = HookPayloadMap;
|
|
1404
|
+
/**
|
|
1405
|
+
* AgentEventPayload extracts the payload type for a specific event.
|
|
1406
|
+
*/
|
|
1407
|
+
type AgentEventPayload<E extends AgentEventName> = AgentEventPayloadMap[E];
|
|
1408
|
+
/**
|
|
1409
|
+
* AgentEventListener is an alias for HookHandler.
|
|
1410
|
+
* Handlers can return void or Promise<void>.
|
|
1411
|
+
*/
|
|
1412
|
+
type AgentEventListener<E extends AgentEventName> = HookHandler<E>;
|
|
1413
|
+
|
|
1206
1414
|
/**
|
|
1207
1415
|
* Streaming chunk payload from Opper SSE responses.
|
|
1208
1416
|
*/
|
|
@@ -2128,7 +2336,7 @@ declare const createStreamAssembler: (options?: StreamAssemblerOptions) => Strea
|
|
|
2128
2336
|
/**
|
|
2129
2337
|
* Options for creating a tool from a function
|
|
2130
2338
|
*/
|
|
2131
|
-
interface ToolOptions<TInput> {
|
|
2339
|
+
interface ToolOptions<TInput, TOutput = unknown> {
|
|
2132
2340
|
/**
|
|
2133
2341
|
* Tool name (defaults to function name)
|
|
2134
2342
|
*/
|
|
@@ -2141,6 +2349,14 @@ interface ToolOptions<TInput> {
|
|
|
2141
2349
|
* Input validation schema
|
|
2142
2350
|
*/
|
|
2143
2351
|
schema?: ZodType<TInput>;
|
|
2352
|
+
/**
|
|
2353
|
+
* Output schema describing what the tool returns (exposed to LLM)
|
|
2354
|
+
*/
|
|
2355
|
+
outputSchema?: ZodType<TOutput>;
|
|
2356
|
+
/**
|
|
2357
|
+
* Examples of tool usage to help the LLM understand expected behavior
|
|
2358
|
+
*/
|
|
2359
|
+
examples?: Array<ToolExample<TInput, TOutput>>;
|
|
2144
2360
|
/**
|
|
2145
2361
|
* Execution timeout in milliseconds
|
|
2146
2362
|
*/
|
|
@@ -2172,11 +2388,15 @@ type ToolMethodDecorator<TInput, TOutput> = {
|
|
|
2172
2388
|
* {
|
|
2173
2389
|
* name: "add",
|
|
2174
2390
|
* description: "Add two numbers",
|
|
2175
|
-
* schema: z.object({ a: z.number(), b: z.number() })
|
|
2391
|
+
* schema: z.object({ a: z.number(), b: z.number() }),
|
|
2392
|
+
* outputSchema: z.number(),
|
|
2393
|
+
* examples: [
|
|
2394
|
+
* { input: { a: 2, b: 3 }, output: 5, description: "Basic addition" },
|
|
2395
|
+
* ],
|
|
2176
2396
|
* }
|
|
2177
2397
|
* );
|
|
2178
2398
|
*/
|
|
2179
|
-
declare function createFunctionTool<TInput, TOutput>(fn: ToolFunction<TInput, TOutput>, options?: ToolOptions<TInput>): Tool<TInput, TOutput>;
|
|
2399
|
+
declare function createFunctionTool<TInput, TOutput>(fn: ToolFunction<TInput, TOutput>, options?: ToolOptions<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
2180
2400
|
/**
|
|
2181
2401
|
* Decorator factory for creating tools from methods.
|
|
2182
2402
|
* Can be used with or without arguments.
|
|
@@ -2192,7 +2412,7 @@ declare function createFunctionTool<TInput, TOutput>(fn: ToolFunction<TInput, TO
|
|
|
2192
2412
|
* }
|
|
2193
2413
|
* }
|
|
2194
2414
|
*/
|
|
2195
|
-
declare function tool<TInput = unknown, TOutput = unknown>(options?: ToolOptions<TInput>): ToolMethodDecorator<TInput, TOutput>;
|
|
2415
|
+
declare function tool<TInput = unknown, TOutput = unknown>(options?: ToolOptions<TInput, TOutput>): ToolMethodDecorator<TInput, TOutput>;
|
|
2196
2416
|
/**
|
|
2197
2417
|
* Extract all tools defined via @tool decorator from a class instance
|
|
2198
2418
|
*
|
|
@@ -2310,4 +2530,4 @@ declare class ToolRunner {
|
|
|
2310
2530
|
};
|
|
2311
2531
|
}
|
|
2312
2532
|
|
|
2313
|
-
export { Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema,
|
|
2533
|
+
export { Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema, type AgentEventListener, type AgentEventName, type AgentEventPayload, type AgentEventPayloadMap, AgentEvents, type AgentLogger, BaseAgent, type BaseAgentConfig, type BaseUsage, BaseUsageSchema, ConsoleLogger, type CreateSpanOptions, DEFAULT_MODEL, DEFAULT_RETRY_CONFIG, type ExecutionCycle, ExecutionCycleSchema, type Failure, type HookEventName, HookEvents, type HookHandler, HookManager, type HookPayload, type HookPayloadMap, type HookRegistration, InMemoryStore, type IterationSummary, type JsonSchemaOptions, LogLevel, MCPClient, type MCPClientOptions, type MCPServerConfig, type MCPServerConfigInput, MCPServerConfigSchema, type MCPTool, MCPToolProvider, type MCPToolProviderOptions, MCPconfig, type MaybePromise, type Memory, type MemoryCatalogEntry, type MemoryEntry, type MemoryEntryMetadata, MemoryEntryMetadataSchema, MemoryEntrySchema, type MemoryUpdate, MemoryUpdateSchema, type OpperCallOptions, type OpperCallResponse, OpperClient, type OpperClientConfig, type OpperSpan, type OpperStreamChunk, type OpperStreamEvent, type OpperStreamResponse, Result, type RetryConfig, STREAM_ROOT_PATH, type Schema, SchemaValidationError, type SchemaValidationOptions, SilentLogger, StreamAssembler, type StreamAssemblerOptions, type StreamFeedResult, type StreamFinalizeResult, type Success, type Thought, ThoughtSchema, type Tool, type ToolCall, type ToolCallRecord, ToolCallRecordSchema, ToolCallSchema, type ToolDefinition, type ToolExample, type ToolExecutionContext, type ToolExecutionSummary, ToolExecutionSummarySchema, type ToolFailure, type ToolFunction, ToolMetadataSchema, type ToolOptions, type ToolProvider, type ToolResult, type ToolResultData, ToolResultFactory, ToolResultFailureSchema, type ToolResultInit, ToolResultSchema, ToolResultSuccessSchema, type ToolRunOptions, ToolRunner, type ToolSuccess, type UnregisterHook, type Usage, UsageSchema, type VisualizationOptions, addUsage, coerceToolDefinition, createAgentDecisionWithOutputSchema, createEmptyUsage, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, createToolCallRecord, err, extractTools, generateAgentFlowDiagram, getDefaultLogger, getSchemaDefault, isSchemaValid, isToolProvider, mcp, mergeSchemaDefaults, normalizeToolEntries, ok, schemaToJson, setDefaultLogger, tool, validateSchema, validateToolInput, zodSchemaToJsonSchema };
|