@opperai/agents 0.1.3 → 0.3.0-beta
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 +32 -0
- package/dist/index.cjs +901 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +330 -4
- package/dist/index.d.ts +330 -4
- package/dist/index.js +896 -28
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -508,6 +508,10 @@ declare const HookEvents: {
|
|
|
508
508
|
readonly MemoryRead: "memory:read";
|
|
509
509
|
readonly MemoryWrite: "memory:write";
|
|
510
510
|
readonly MemoryError: "memory:error";
|
|
511
|
+
readonly StreamStart: "stream:start";
|
|
512
|
+
readonly StreamChunk: "stream:chunk";
|
|
513
|
+
readonly StreamEnd: "stream:end";
|
|
514
|
+
readonly StreamError: "stream:error";
|
|
511
515
|
};
|
|
512
516
|
type HookEventName = (typeof HookEvents)[keyof typeof HookEvents];
|
|
513
517
|
interface HookPayloadMap {
|
|
@@ -533,6 +537,7 @@ interface HookPayloadMap {
|
|
|
533
537
|
context: AgentContext;
|
|
534
538
|
callType: string;
|
|
535
539
|
response: unknown;
|
|
540
|
+
parsed?: unknown;
|
|
536
541
|
};
|
|
537
542
|
[HookEvents.ThinkEnd]: {
|
|
538
543
|
context: AgentContext;
|
|
@@ -570,6 +575,31 @@ interface HookPayloadMap {
|
|
|
570
575
|
operation: "read" | "write" | "delete" | "clear";
|
|
571
576
|
error: unknown;
|
|
572
577
|
};
|
|
578
|
+
[HookEvents.StreamStart]: {
|
|
579
|
+
context: AgentContext;
|
|
580
|
+
callType: string;
|
|
581
|
+
};
|
|
582
|
+
[HookEvents.StreamChunk]: {
|
|
583
|
+
context: AgentContext;
|
|
584
|
+
callType: string;
|
|
585
|
+
chunkData: {
|
|
586
|
+
delta: unknown;
|
|
587
|
+
jsonPath?: string | null;
|
|
588
|
+
chunkType?: string | null;
|
|
589
|
+
};
|
|
590
|
+
accumulated: string;
|
|
591
|
+
fieldBuffers: Record<string, string>;
|
|
592
|
+
};
|
|
593
|
+
[HookEvents.StreamEnd]: {
|
|
594
|
+
context: AgentContext;
|
|
595
|
+
callType: string;
|
|
596
|
+
fieldBuffers: Record<string, string>;
|
|
597
|
+
};
|
|
598
|
+
[HookEvents.StreamError]: {
|
|
599
|
+
context: AgentContext;
|
|
600
|
+
callType: string;
|
|
601
|
+
error: unknown;
|
|
602
|
+
};
|
|
573
603
|
}
|
|
574
604
|
type HookPayload<E extends HookEventName> = HookPayloadMap[E];
|
|
575
605
|
type HookHandler<E extends HookEventName> = (payload: HookPayload<E>) => void | Promise<void>;
|
|
@@ -592,6 +622,28 @@ declare class HookManager {
|
|
|
592
622
|
}
|
|
593
623
|
declare const createHookManager: (logger?: AgentLogger) => HookManager;
|
|
594
624
|
|
|
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
|
+
|
|
595
647
|
/**
|
|
596
648
|
* Options for generating agent flow visualization
|
|
597
649
|
*/
|
|
@@ -825,6 +877,27 @@ interface BaseAgentConfig<TInput, TOutput> {
|
|
|
825
877
|
* Output schema for validation (Zod schema)
|
|
826
878
|
*/
|
|
827
879
|
outputSchema?: ZodType<TOutput>;
|
|
880
|
+
/**
|
|
881
|
+
* Enable Opper streaming APIs for LLM calls
|
|
882
|
+
* @default false
|
|
883
|
+
*/
|
|
884
|
+
enableStreaming?: boolean;
|
|
885
|
+
/**
|
|
886
|
+
* Register a handler invoked when a streaming call starts.
|
|
887
|
+
*/
|
|
888
|
+
onStreamStart?: AgentEventListener<typeof HookEvents.StreamStart>;
|
|
889
|
+
/**
|
|
890
|
+
* Register a handler invoked for each streaming chunk.
|
|
891
|
+
*/
|
|
892
|
+
onStreamChunk?: AgentEventListener<typeof HookEvents.StreamChunk>;
|
|
893
|
+
/**
|
|
894
|
+
* Register a handler invoked when a streaming call ends.
|
|
895
|
+
*/
|
|
896
|
+
onStreamEnd?: AgentEventListener<typeof HookEvents.StreamEnd>;
|
|
897
|
+
/**
|
|
898
|
+
* Register a handler invoked when streaming encounters an error.
|
|
899
|
+
*/
|
|
900
|
+
onStreamError?: AgentEventListener<typeof HookEvents.StreamError>;
|
|
828
901
|
/**
|
|
829
902
|
* Enable memory subsystem
|
|
830
903
|
* @default false
|
|
@@ -900,6 +973,10 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
900
973
|
* Whether memory is enabled
|
|
901
974
|
*/
|
|
902
975
|
readonly enableMemory: boolean;
|
|
976
|
+
/**
|
|
977
|
+
* Whether streaming is enabled
|
|
978
|
+
*/
|
|
979
|
+
readonly enableStreaming: boolean;
|
|
903
980
|
/**
|
|
904
981
|
* Memory instance for persistent storage (null if disabled or initialization failed)
|
|
905
982
|
*/
|
|
@@ -912,6 +989,10 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
912
989
|
* Hook manager for lifecycle events
|
|
913
990
|
*/
|
|
914
991
|
protected readonly hooks: HookManager;
|
|
992
|
+
/**
|
|
993
|
+
* Event dispatcher for runtime events (notably streaming)
|
|
994
|
+
*/
|
|
995
|
+
protected readonly events: AgentEventEmitter;
|
|
915
996
|
/**
|
|
916
997
|
* Registry of available tools
|
|
917
998
|
*/
|
|
@@ -932,6 +1013,28 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
932
1013
|
* Opper client configuration
|
|
933
1014
|
*/
|
|
934
1015
|
protected readonly opperConfig: OpperClientConfig;
|
|
1016
|
+
/**
|
|
1017
|
+
* Creates a new BaseAgent instance
|
|
1018
|
+
*
|
|
1019
|
+
* @param config - Agent configuration object
|
|
1020
|
+
* @param config.name - Unique name identifying this agent (required)
|
|
1021
|
+
* @param config.description - Human-readable description of the agent's purpose
|
|
1022
|
+
* @param config.instructions - System instructions guiding agent behavior
|
|
1023
|
+
* @param config.tools - Array of tools or tool providers available to the agent
|
|
1024
|
+
* @param config.maxIterations - Maximum iterations before terminating the agent loop (default: 25)
|
|
1025
|
+
* @param config.model - Model identifier(s). Single model or array for fallback (default: "gcp/gemini-flash-latest")
|
|
1026
|
+
* @param config.inputSchema - Zod schema for input validation
|
|
1027
|
+
* @param config.outputSchema - Zod schema for output validation
|
|
1028
|
+
* @param config.enableStreaming - Enable Opper streaming APIs for LLM calls (default: false)
|
|
1029
|
+
* @param config.enableMemory - Enable memory subsystem (default: false)
|
|
1030
|
+
* @param config.memory - Custom memory implementation (defaults to InMemoryStore if enableMemory is true)
|
|
1031
|
+
* @param config.metadata - Additional metadata for the agent
|
|
1032
|
+
* @param config.opperConfig - Opper API configuration containing apiKey and baseUrl
|
|
1033
|
+
* @param config.onStreamStart - Handler invoked when a streaming call starts
|
|
1034
|
+
* @param config.onStreamChunk - Handler invoked for each streaming chunk
|
|
1035
|
+
* @param config.onStreamEnd - Handler invoked when a streaming call ends
|
|
1036
|
+
* @param config.onStreamError - Handler invoked when streaming encounters an error
|
|
1037
|
+
*/
|
|
935
1038
|
constructor(config: BaseAgentConfig<TInput, TOutput>);
|
|
936
1039
|
/**
|
|
937
1040
|
* Initialize memory subsystem with graceful degradation
|
|
@@ -1022,6 +1125,29 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1022
1125
|
* @returns Cleanup function to unregister the hook
|
|
1023
1126
|
*/
|
|
1024
1127
|
registerHook<E extends HookEventName>(event: E, handler: HookHandler<E>): () => void;
|
|
1128
|
+
/**
|
|
1129
|
+
* Register an event listener.
|
|
1130
|
+
*
|
|
1131
|
+
* @param event - Event name
|
|
1132
|
+
* @param listener - Listener callback
|
|
1133
|
+
* @returns Cleanup function to unregister the listener
|
|
1134
|
+
*/
|
|
1135
|
+
on<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): () => void;
|
|
1136
|
+
/**
|
|
1137
|
+
* Register a one-time event listener that removes itself after the first call.
|
|
1138
|
+
*
|
|
1139
|
+
* @param event - Event name
|
|
1140
|
+
* @param listener - Listener callback
|
|
1141
|
+
* @returns Cleanup function (no-op once listener fires)
|
|
1142
|
+
*/
|
|
1143
|
+
once<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): () => void;
|
|
1144
|
+
/**
|
|
1145
|
+
* Remove a previously registered event listener.
|
|
1146
|
+
*
|
|
1147
|
+
* @param event - Event name
|
|
1148
|
+
* @param listener - Listener callback to remove
|
|
1149
|
+
*/
|
|
1150
|
+
off<E extends AgentEventName>(event: E, listener: AgentEventListener<E>): void;
|
|
1025
1151
|
/**
|
|
1026
1152
|
* Trigger a hook event with a payload.
|
|
1027
1153
|
* Swallows errors to prevent hook failures from breaking agent execution.
|
|
@@ -1030,6 +1156,13 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1030
1156
|
* @param payload - Event payload
|
|
1031
1157
|
*/
|
|
1032
1158
|
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;
|
|
1033
1166
|
/**
|
|
1034
1167
|
* Execute a tool with proper context, hooks, and error handling.
|
|
1035
1168
|
*
|
|
@@ -1070,6 +1203,31 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
|
|
|
1070
1203
|
visualizeFlow(options?: VisualizationOptions): Promise<string>;
|
|
1071
1204
|
}
|
|
1072
1205
|
|
|
1206
|
+
/**
|
|
1207
|
+
* Streaming chunk payload from Opper SSE responses.
|
|
1208
|
+
*/
|
|
1209
|
+
interface OpperStreamChunk {
|
|
1210
|
+
delta?: string | number | boolean | null | undefined;
|
|
1211
|
+
jsonPath?: string | null | undefined;
|
|
1212
|
+
spanId?: string | null | undefined;
|
|
1213
|
+
chunkType?: string | null | undefined;
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Server-sent event emitted during streaming calls.
|
|
1217
|
+
*/
|
|
1218
|
+
interface OpperStreamEvent {
|
|
1219
|
+
id?: string;
|
|
1220
|
+
event?: string;
|
|
1221
|
+
retry?: number;
|
|
1222
|
+
data?: OpperStreamChunk;
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Structured response returned by Opper stream endpoints.
|
|
1226
|
+
*/
|
|
1227
|
+
interface OpperStreamResponse {
|
|
1228
|
+
headers: Record<string, string[]>;
|
|
1229
|
+
result: AsyncIterable<OpperStreamEvent>;
|
|
1230
|
+
}
|
|
1073
1231
|
/**
|
|
1074
1232
|
* Opper call response
|
|
1075
1233
|
*/
|
|
@@ -1133,6 +1291,10 @@ interface OpperCallOptions<TInput = unknown, TOutput = unknown> {
|
|
|
1133
1291
|
* Parent span ID for tracing
|
|
1134
1292
|
*/
|
|
1135
1293
|
parentSpanId?: string;
|
|
1294
|
+
/**
|
|
1295
|
+
* Abort signal used to cancel the underlying HTTP request.
|
|
1296
|
+
*/
|
|
1297
|
+
signal?: AbortSignal;
|
|
1136
1298
|
}
|
|
1137
1299
|
/**
|
|
1138
1300
|
* Span information
|
|
@@ -1150,6 +1312,7 @@ interface CreateSpanOptions {
|
|
|
1150
1312
|
name: string;
|
|
1151
1313
|
input?: unknown;
|
|
1152
1314
|
parentSpanId?: string;
|
|
1315
|
+
type?: string;
|
|
1153
1316
|
}
|
|
1154
1317
|
/**
|
|
1155
1318
|
* Retry configuration
|
|
@@ -1191,6 +1354,10 @@ declare class OpperClient {
|
|
|
1191
1354
|
* Make a call to Opper with retry logic
|
|
1192
1355
|
*/
|
|
1193
1356
|
call<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperCallResponse<TOutput>>;
|
|
1357
|
+
/**
|
|
1358
|
+
* Stream a call to Opper with retry logic
|
|
1359
|
+
*/
|
|
1360
|
+
stream<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperStreamResponse>;
|
|
1194
1361
|
/**
|
|
1195
1362
|
* Create a span for tracing
|
|
1196
1363
|
*/
|
|
@@ -1200,6 +1367,10 @@ declare class OpperClient {
|
|
|
1200
1367
|
*/
|
|
1201
1368
|
updateSpan(spanId: string, output: unknown, options?: {
|
|
1202
1369
|
error?: string;
|
|
1370
|
+
startTime?: Date;
|
|
1371
|
+
endTime?: Date;
|
|
1372
|
+
meta?: Record<string, unknown>;
|
|
1373
|
+
name?: string;
|
|
1203
1374
|
}): Promise<void>;
|
|
1204
1375
|
/**
|
|
1205
1376
|
* Get the underlying Opper client
|
|
@@ -1231,7 +1402,33 @@ declare function createOpperClient(apiKey?: string, options?: {
|
|
|
1231
1402
|
}): OpperClient;
|
|
1232
1403
|
|
|
1233
1404
|
/**
|
|
1234
|
-
* Configuration for the core Agent
|
|
1405
|
+
* Configuration for the core Agent.
|
|
1406
|
+
*
|
|
1407
|
+
* Extends {@link BaseAgentConfig} with additional options for Opper client, logging, and verbosity.
|
|
1408
|
+
*
|
|
1409
|
+
* @template TInput - The expected input type for the agent
|
|
1410
|
+
* @template TOutput - The expected output type from the agent
|
|
1411
|
+
*
|
|
1412
|
+
* @property {string} name - Unique name identifying this agent (required)
|
|
1413
|
+
* @property {string} [description] - Human-readable description of the agent's purpose
|
|
1414
|
+
* @property {string} [instructions] - System instructions guiding agent behavior
|
|
1415
|
+
* @property {Array<Tool<any, any> | ToolProvider>} [tools] - Tools available to the agent
|
|
1416
|
+
* @property {number} [maxIterations=25] - Maximum iterations before terminating
|
|
1417
|
+
* @property {string | readonly string[]} [model='gcp/gemini-flash-latest'] - Model identifier(s)
|
|
1418
|
+
* @property {ZodType<TInput>} [inputSchema] - Zod schema for input validation
|
|
1419
|
+
* @property {ZodType<TOutput>} [outputSchema] - Zod schema for output validation
|
|
1420
|
+
* @property {boolean} [enableStreaming=false] - Enable streaming for LLM calls
|
|
1421
|
+
* @property {boolean} [enableMemory=false] - Enable memory subsystem
|
|
1422
|
+
* @property {Memory} [memory] - Custom memory implementation
|
|
1423
|
+
* @property {Record<string, unknown>} [metadata] - Additional metadata
|
|
1424
|
+
* @property {OpperClientConfig} [opperConfig] - Opper API configuration (apiKey, baseUrl)
|
|
1425
|
+
* @property {OpperClient} [opperClient] - Custom Opper client instance
|
|
1426
|
+
* @property {AgentLogger} [logger] - Logger instance for debugging
|
|
1427
|
+
* @property {boolean} [verbose=false] - Enable verbose logging
|
|
1428
|
+
* @property {Function} [onStreamStart] - Handler invoked when streaming starts
|
|
1429
|
+
* @property {Function} [onStreamChunk] - Handler invoked for each streaming chunk
|
|
1430
|
+
* @property {Function} [onStreamEnd] - Handler invoked when streaming ends
|
|
1431
|
+
* @property {Function} [onStreamError] - Handler invoked on streaming errors
|
|
1235
1432
|
*/
|
|
1236
1433
|
interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput> {
|
|
1237
1434
|
/**
|
|
@@ -1239,22 +1436,86 @@ interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput>
|
|
|
1239
1436
|
*/
|
|
1240
1437
|
opperClient?: OpperClient;
|
|
1241
1438
|
/**
|
|
1242
|
-
* Logger instance
|
|
1439
|
+
* Logger instance for debugging and monitoring
|
|
1243
1440
|
*/
|
|
1244
1441
|
logger?: AgentLogger;
|
|
1245
1442
|
/**
|
|
1246
|
-
*
|
|
1443
|
+
* Enable verbose logging (default: false)
|
|
1247
1444
|
*/
|
|
1248
1445
|
verbose?: boolean;
|
|
1249
1446
|
}
|
|
1250
1447
|
/**
|
|
1251
1448
|
* Core Agent implementation with "while tools > 0" loop.
|
|
1252
1449
|
* Implements think → tool execution → memory handling cycle.
|
|
1450
|
+
*
|
|
1451
|
+
* @template TInput - The expected input type for the agent
|
|
1452
|
+
* @template TOutput - The expected output type from the agent
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* import { Agent } from 'opperai-agent-sdk-node';
|
|
1457
|
+
*
|
|
1458
|
+
* const agent = new Agent({
|
|
1459
|
+
* name: 'my-agent',
|
|
1460
|
+
* instructions: 'You are a helpful assistant',
|
|
1461
|
+
* model: 'gpt-4',
|
|
1462
|
+
* tools: [myTool],
|
|
1463
|
+
* maxIterations: 10,
|
|
1464
|
+
* enableMemory: true,
|
|
1465
|
+
* });
|
|
1466
|
+
*
|
|
1467
|
+
* const result = await agent.process('Hello!');
|
|
1468
|
+
* ```
|
|
1469
|
+
*
|
|
1470
|
+
* @example
|
|
1471
|
+
* ```typescript
|
|
1472
|
+
* // With typed input/output and schemas
|
|
1473
|
+
* import { Agent } from 'opperai-agent-sdk-node';
|
|
1474
|
+
* import { z } from 'zod';
|
|
1475
|
+
*
|
|
1476
|
+
* const inputSchema = z.object({ query: z.string() });
|
|
1477
|
+
* const outputSchema = z.object({ answer: z.string(), confidence: z.number() });
|
|
1478
|
+
*
|
|
1479
|
+
* const agent = new Agent<
|
|
1480
|
+
* z.infer<typeof inputSchema>,
|
|
1481
|
+
* z.infer<typeof outputSchema>
|
|
1482
|
+
* >({
|
|
1483
|
+
* name: 'typed-agent',
|
|
1484
|
+
* instructions: 'Answer questions with confidence scores',
|
|
1485
|
+
* inputSchema,
|
|
1486
|
+
* outputSchema,
|
|
1487
|
+
* });
|
|
1488
|
+
* ```
|
|
1253
1489
|
*/
|
|
1254
1490
|
declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInput, TOutput> {
|
|
1255
1491
|
private readonly opperClient;
|
|
1256
1492
|
private readonly logger;
|
|
1257
1493
|
private readonly verbose;
|
|
1494
|
+
/**
|
|
1495
|
+
* Creates a new Agent instance
|
|
1496
|
+
*
|
|
1497
|
+
* @param config - Agent configuration object
|
|
1498
|
+
* @param config.name - Unique name identifying this agent (required)
|
|
1499
|
+
* @param config.description - Human-readable description of the agent's purpose
|
|
1500
|
+
* @param config.instructions - System instructions guiding agent behavior
|
|
1501
|
+
* @param config.tools - Array of tools or tool providers available to the agent
|
|
1502
|
+
* @param config.maxIterations - Maximum iterations before terminating (default: 25)
|
|
1503
|
+
* @param config.model - Model identifier(s) as string or array for fallback (default: "gcp/gemini-flash-latest")
|
|
1504
|
+
* @param config.inputSchema - Zod schema for input validation
|
|
1505
|
+
* @param config.outputSchema - Zod schema for output validation
|
|
1506
|
+
* @param config.enableStreaming - Enable streaming for LLM calls (default: false)
|
|
1507
|
+
* @param config.enableMemory - Enable memory subsystem (default: false)
|
|
1508
|
+
* @param config.memory - Custom memory implementation (defaults to InMemoryStore if enableMemory is true)
|
|
1509
|
+
* @param config.metadata - Additional metadata for the agent
|
|
1510
|
+
* @param config.opperConfig - Opper API configuration (apiKey, baseUrl)
|
|
1511
|
+
* @param config.opperClient - Custom Opper client instance (for testing or custom configuration)
|
|
1512
|
+
* @param config.logger - Logger instance for debugging
|
|
1513
|
+
* @param config.verbose - Enable verbose logging (default: false)
|
|
1514
|
+
* @param config.onStreamStart - Handler invoked when streaming starts
|
|
1515
|
+
* @param config.onStreamChunk - Handler invoked for each streaming chunk
|
|
1516
|
+
* @param config.onStreamEnd - Handler invoked when streaming ends
|
|
1517
|
+
* @param config.onStreamError - Handler invoked on streaming errors
|
|
1518
|
+
*/
|
|
1258
1519
|
constructor(config: AgentConfig<TInput, TOutput>);
|
|
1259
1520
|
/**
|
|
1260
1521
|
* Serialize input for passing to LLM or spans
|
|
@@ -1268,6 +1529,7 @@ declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInpu
|
|
|
1268
1529
|
* Think step: Call LLM to decide next action
|
|
1269
1530
|
*/
|
|
1270
1531
|
private think;
|
|
1532
|
+
private thinkStreaming;
|
|
1271
1533
|
/**
|
|
1272
1534
|
* Build static instructions for the think step
|
|
1273
1535
|
*/
|
|
@@ -1289,6 +1551,8 @@ declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInpu
|
|
|
1289
1551
|
* Generate final result based on execution history
|
|
1290
1552
|
*/
|
|
1291
1553
|
private generateFinalResult;
|
|
1554
|
+
private generateFinalResultStreaming;
|
|
1555
|
+
private trackStreamingUsageBySpan;
|
|
1292
1556
|
/**
|
|
1293
1557
|
* Log helper
|
|
1294
1558
|
*/
|
|
@@ -1387,6 +1651,10 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1387
1651
|
* Agent's internal reasoning
|
|
1388
1652
|
*/
|
|
1389
1653
|
reasoning: z.ZodString;
|
|
1654
|
+
/**
|
|
1655
|
+
* Status message for the user (e.g., "Searching for information...", "Processing results...")
|
|
1656
|
+
*/
|
|
1657
|
+
userMessage: z.ZodDefault<z.ZodString>;
|
|
1390
1658
|
/**
|
|
1391
1659
|
* Tool calls to execute (if any)
|
|
1392
1660
|
* Empty array signals task completion
|
|
@@ -1442,6 +1710,16 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1442
1710
|
metadata?: Record<string, unknown> | undefined;
|
|
1443
1711
|
description?: string | undefined;
|
|
1444
1712
|
}>>>;
|
|
1713
|
+
/**
|
|
1714
|
+
* Whether the task is complete and finalResult is available
|
|
1715
|
+
* (single LLM call pattern)
|
|
1716
|
+
*/
|
|
1717
|
+
isComplete: z.ZodDefault<z.ZodBoolean>;
|
|
1718
|
+
/**
|
|
1719
|
+
* The final result when isComplete=true
|
|
1720
|
+
* Should match outputSchema if specified
|
|
1721
|
+
*/
|
|
1722
|
+
finalResult: z.ZodOptional<z.ZodUnknown>;
|
|
1445
1723
|
}, "strip", z.ZodTypeAny, {
|
|
1446
1724
|
toolCalls: {
|
|
1447
1725
|
id: string;
|
|
@@ -1449,12 +1727,15 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1449
1727
|
arguments?: unknown;
|
|
1450
1728
|
}[];
|
|
1451
1729
|
reasoning: string;
|
|
1730
|
+
userMessage: string;
|
|
1452
1731
|
memoryReads: string[];
|
|
1453
1732
|
memoryUpdates: Record<string, {
|
|
1454
1733
|
value?: unknown;
|
|
1455
1734
|
metadata?: Record<string, unknown> | undefined;
|
|
1456
1735
|
description?: string | undefined;
|
|
1457
1736
|
}>;
|
|
1737
|
+
isComplete: boolean;
|
|
1738
|
+
finalResult?: unknown;
|
|
1458
1739
|
}, {
|
|
1459
1740
|
reasoning: string;
|
|
1460
1741
|
toolCalls?: {
|
|
@@ -1462,14 +1743,28 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1462
1743
|
toolName: string;
|
|
1463
1744
|
arguments?: unknown;
|
|
1464
1745
|
}[] | undefined;
|
|
1746
|
+
userMessage?: string | undefined;
|
|
1465
1747
|
memoryReads?: string[] | undefined;
|
|
1466
1748
|
memoryUpdates?: Record<string, {
|
|
1467
1749
|
value?: unknown;
|
|
1468
1750
|
metadata?: Record<string, unknown> | undefined;
|
|
1469
1751
|
description?: string | undefined;
|
|
1470
1752
|
}> | undefined;
|
|
1753
|
+
isComplete?: boolean | undefined;
|
|
1754
|
+
finalResult?: unknown;
|
|
1471
1755
|
}>;
|
|
1472
1756
|
type AgentDecision = z.infer<typeof AgentDecisionSchema>;
|
|
1757
|
+
/**
|
|
1758
|
+
* Create an AgentDecision schema with typed finalResult field.
|
|
1759
|
+
*
|
|
1760
|
+
* When outputSchema is provided, the finalResult field will be typed
|
|
1761
|
+
* to that schema, allowing Opper to enforce the correct structure.
|
|
1762
|
+
* When finalResult is undefined/null, it passes through without validation.
|
|
1763
|
+
*
|
|
1764
|
+
* @param outputSchema - Optional Zod schema for the final result
|
|
1765
|
+
* @returns AgentDecision schema (original or dynamically created variant)
|
|
1766
|
+
*/
|
|
1767
|
+
declare function createAgentDecisionWithOutputSchema<T>(outputSchema?: z.ZodType<T>): z.ZodObject<z.ZodRawShape>;
|
|
1473
1768
|
/**
|
|
1474
1769
|
* Schema for tool execution result summary
|
|
1475
1770
|
*/
|
|
@@ -1793,6 +2088,37 @@ declare const schemaToJson: (schema: ZodTypeAny, options?: JsonSchemaOptions) =>
|
|
|
1793
2088
|
declare const getSchemaDefault: <T>(schema: Schema<T>) => T | undefined;
|
|
1794
2089
|
declare const mergeSchemaDefaults: <T extends Record<string, unknown>>(schema: Schema<T>, value: Partial<T>) => T;
|
|
1795
2090
|
|
|
2091
|
+
declare const STREAM_ROOT_PATH = "_root";
|
|
2092
|
+
interface StreamAssemblerOptions {
|
|
2093
|
+
schema?: ZodTypeAny;
|
|
2094
|
+
}
|
|
2095
|
+
interface StreamFeedResult {
|
|
2096
|
+
path: string;
|
|
2097
|
+
accumulated: string;
|
|
2098
|
+
snapshot: Record<string, string>;
|
|
2099
|
+
}
|
|
2100
|
+
interface StreamFinalizeResult {
|
|
2101
|
+
type: "root" | "structured" | "empty";
|
|
2102
|
+
rootText?: string;
|
|
2103
|
+
structured?: unknown;
|
|
2104
|
+
}
|
|
2105
|
+
declare class StreamAssembler {
|
|
2106
|
+
private readonly displayBuffers;
|
|
2107
|
+
private readonly valueBuffers;
|
|
2108
|
+
private readonly schema;
|
|
2109
|
+
constructor(options?: StreamAssemblerOptions);
|
|
2110
|
+
feed(chunk: {
|
|
2111
|
+
delta?: unknown;
|
|
2112
|
+
jsonPath?: string | null | undefined;
|
|
2113
|
+
}): StreamFeedResult | null;
|
|
2114
|
+
snapshot(): Record<string, string>;
|
|
2115
|
+
hasStructuredFields(): boolean;
|
|
2116
|
+
finalize(): StreamFinalizeResult;
|
|
2117
|
+
getFieldBuffers(): Map<string, string>;
|
|
2118
|
+
private reconstructStructured;
|
|
2119
|
+
}
|
|
2120
|
+
declare const createStreamAssembler: (options?: StreamAssemblerOptions) => StreamAssembler;
|
|
2121
|
+
|
|
1796
2122
|
/**
|
|
1797
2123
|
* Options for creating a tool from a function
|
|
1798
2124
|
*/
|
|
@@ -1978,4 +2304,4 @@ declare class ToolRunner {
|
|
|
1978
2304
|
};
|
|
1979
2305
|
}
|
|
1980
2306
|
|
|
1981
|
-
export { Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema, type AgentLogger, BaseAgent, type BaseAgentConfig, 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, Result, type RetryConfig, type Schema, SchemaValidationError, type SchemaValidationOptions, SilentLogger, type Success, type Thought, ThoughtSchema, type Tool, type ToolCall, type ToolCallRecord, ToolCallRecordSchema, ToolCallSchema, type ToolDefinition, 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, coerceToolDefinition, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createToolCallRecord, err, extractTools, generateAgentFlowDiagram, getDefaultLogger, getSchemaDefault, isSchemaValid, isToolProvider, mcp, mergeSchemaDefaults, normalizeToolEntries, ok, schemaToJson, setDefaultLogger, tool, validateSchema, validateToolInput };
|
|
2307
|
+
export { Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema, AgentEventEmitter, type AgentEventListener, type AgentEventName, type AgentEventPayload, type AgentEventPayloadMap, AgentEvents, type AgentLogger, BaseAgent, type BaseAgentConfig, 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 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, coerceToolDefinition, createAgentDecisionWithOutputSchema, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, createToolCallRecord, err, extractTools, generateAgentFlowDiagram, getDefaultLogger, getSchemaDefault, isSchemaValid, isToolProvider, mcp, mergeSchemaDefaults, normalizeToolEntries, ok, schemaToJson, setDefaultLogger, tool, validateSchema, validateToolInput };
|