@opperai/agents 0.2.0 → 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/dist/index.d.cts CHANGED
@@ -1013,6 +1013,28 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
1013
1013
  * Opper client configuration
1014
1014
  */
1015
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
+ */
1016
1038
  constructor(config: BaseAgentConfig<TInput, TOutput>);
1017
1039
  /**
1018
1040
  * Initialize memory subsystem with graceful degradation
@@ -1290,6 +1312,7 @@ interface CreateSpanOptions {
1290
1312
  name: string;
1291
1313
  input?: unknown;
1292
1314
  parentSpanId?: string;
1315
+ type?: string;
1293
1316
  }
1294
1317
  /**
1295
1318
  * Retry configuration
@@ -1344,6 +1367,10 @@ declare class OpperClient {
1344
1367
  */
1345
1368
  updateSpan(spanId: string, output: unknown, options?: {
1346
1369
  error?: string;
1370
+ startTime?: Date;
1371
+ endTime?: Date;
1372
+ meta?: Record<string, unknown>;
1373
+ name?: string;
1347
1374
  }): Promise<void>;
1348
1375
  /**
1349
1376
  * Get the underlying Opper client
@@ -1375,7 +1402,33 @@ declare function createOpperClient(apiKey?: string, options?: {
1375
1402
  }): OpperClient;
1376
1403
 
1377
1404
  /**
1378
- * 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
1379
1432
  */
1380
1433
  interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput> {
1381
1434
  /**
@@ -1383,22 +1436,86 @@ interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput>
1383
1436
  */
1384
1437
  opperClient?: OpperClient;
1385
1438
  /**
1386
- * Logger instance
1439
+ * Logger instance for debugging and monitoring
1387
1440
  */
1388
1441
  logger?: AgentLogger;
1389
1442
  /**
1390
- * Verbose logging
1443
+ * Enable verbose logging (default: false)
1391
1444
  */
1392
1445
  verbose?: boolean;
1393
1446
  }
1394
1447
  /**
1395
1448
  * Core Agent implementation with "while tools > 0" loop.
1396
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
+ * ```
1397
1489
  */
1398
1490
  declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInput, TOutput> {
1399
1491
  private readonly opperClient;
1400
1492
  private readonly logger;
1401
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
+ */
1402
1519
  constructor(config: AgentConfig<TInput, TOutput>);
1403
1520
  /**
1404
1521
  * Serialize input for passing to LLM or spans
@@ -1534,6 +1651,10 @@ declare const AgentDecisionSchema: z.ZodObject<{
1534
1651
  * Agent's internal reasoning
1535
1652
  */
1536
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>;
1537
1658
  /**
1538
1659
  * Tool calls to execute (if any)
1539
1660
  * Empty array signals task completion
@@ -1589,6 +1710,16 @@ declare const AgentDecisionSchema: z.ZodObject<{
1589
1710
  metadata?: Record<string, unknown> | undefined;
1590
1711
  description?: string | undefined;
1591
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>;
1592
1723
  }, "strip", z.ZodTypeAny, {
1593
1724
  toolCalls: {
1594
1725
  id: string;
@@ -1596,12 +1727,15 @@ declare const AgentDecisionSchema: z.ZodObject<{
1596
1727
  arguments?: unknown;
1597
1728
  }[];
1598
1729
  reasoning: string;
1730
+ userMessage: string;
1599
1731
  memoryReads: string[];
1600
1732
  memoryUpdates: Record<string, {
1601
1733
  value?: unknown;
1602
1734
  metadata?: Record<string, unknown> | undefined;
1603
1735
  description?: string | undefined;
1604
1736
  }>;
1737
+ isComplete: boolean;
1738
+ finalResult?: unknown;
1605
1739
  }, {
1606
1740
  reasoning: string;
1607
1741
  toolCalls?: {
@@ -1609,14 +1743,28 @@ declare const AgentDecisionSchema: z.ZodObject<{
1609
1743
  toolName: string;
1610
1744
  arguments?: unknown;
1611
1745
  }[] | undefined;
1746
+ userMessage?: string | undefined;
1612
1747
  memoryReads?: string[] | undefined;
1613
1748
  memoryUpdates?: Record<string, {
1614
1749
  value?: unknown;
1615
1750
  metadata?: Record<string, unknown> | undefined;
1616
1751
  description?: string | undefined;
1617
1752
  }> | undefined;
1753
+ isComplete?: boolean | undefined;
1754
+ finalResult?: unknown;
1618
1755
  }>;
1619
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>;
1620
1768
  /**
1621
1769
  * Schema for tool execution result summary
1622
1770
  */
@@ -2156,4 +2304,4 @@ declare class ToolRunner {
2156
2304
  };
2157
2305
  }
2158
2306
 
2159
- 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, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, 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 };
package/dist/index.d.ts CHANGED
@@ -1013,6 +1013,28 @@ declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> {
1013
1013
  * Opper client configuration
1014
1014
  */
1015
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
+ */
1016
1038
  constructor(config: BaseAgentConfig<TInput, TOutput>);
1017
1039
  /**
1018
1040
  * Initialize memory subsystem with graceful degradation
@@ -1290,6 +1312,7 @@ interface CreateSpanOptions {
1290
1312
  name: string;
1291
1313
  input?: unknown;
1292
1314
  parentSpanId?: string;
1315
+ type?: string;
1293
1316
  }
1294
1317
  /**
1295
1318
  * Retry configuration
@@ -1344,6 +1367,10 @@ declare class OpperClient {
1344
1367
  */
1345
1368
  updateSpan(spanId: string, output: unknown, options?: {
1346
1369
  error?: string;
1370
+ startTime?: Date;
1371
+ endTime?: Date;
1372
+ meta?: Record<string, unknown>;
1373
+ name?: string;
1347
1374
  }): Promise<void>;
1348
1375
  /**
1349
1376
  * Get the underlying Opper client
@@ -1375,7 +1402,33 @@ declare function createOpperClient(apiKey?: string, options?: {
1375
1402
  }): OpperClient;
1376
1403
 
1377
1404
  /**
1378
- * 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
1379
1432
  */
1380
1433
  interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput> {
1381
1434
  /**
@@ -1383,22 +1436,86 @@ interface AgentConfig<TInput, TOutput> extends BaseAgentConfig<TInput, TOutput>
1383
1436
  */
1384
1437
  opperClient?: OpperClient;
1385
1438
  /**
1386
- * Logger instance
1439
+ * Logger instance for debugging and monitoring
1387
1440
  */
1388
1441
  logger?: AgentLogger;
1389
1442
  /**
1390
- * Verbose logging
1443
+ * Enable verbose logging (default: false)
1391
1444
  */
1392
1445
  verbose?: boolean;
1393
1446
  }
1394
1447
  /**
1395
1448
  * Core Agent implementation with "while tools > 0" loop.
1396
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
+ * ```
1397
1489
  */
1398
1490
  declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInput, TOutput> {
1399
1491
  private readonly opperClient;
1400
1492
  private readonly logger;
1401
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
+ */
1402
1519
  constructor(config: AgentConfig<TInput, TOutput>);
1403
1520
  /**
1404
1521
  * Serialize input for passing to LLM or spans
@@ -1534,6 +1651,10 @@ declare const AgentDecisionSchema: z.ZodObject<{
1534
1651
  * Agent's internal reasoning
1535
1652
  */
1536
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>;
1537
1658
  /**
1538
1659
  * Tool calls to execute (if any)
1539
1660
  * Empty array signals task completion
@@ -1589,6 +1710,16 @@ declare const AgentDecisionSchema: z.ZodObject<{
1589
1710
  metadata?: Record<string, unknown> | undefined;
1590
1711
  description?: string | undefined;
1591
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>;
1592
1723
  }, "strip", z.ZodTypeAny, {
1593
1724
  toolCalls: {
1594
1725
  id: string;
@@ -1596,12 +1727,15 @@ declare const AgentDecisionSchema: z.ZodObject<{
1596
1727
  arguments?: unknown;
1597
1728
  }[];
1598
1729
  reasoning: string;
1730
+ userMessage: string;
1599
1731
  memoryReads: string[];
1600
1732
  memoryUpdates: Record<string, {
1601
1733
  value?: unknown;
1602
1734
  metadata?: Record<string, unknown> | undefined;
1603
1735
  description?: string | undefined;
1604
1736
  }>;
1737
+ isComplete: boolean;
1738
+ finalResult?: unknown;
1605
1739
  }, {
1606
1740
  reasoning: string;
1607
1741
  toolCalls?: {
@@ -1609,14 +1743,28 @@ declare const AgentDecisionSchema: z.ZodObject<{
1609
1743
  toolName: string;
1610
1744
  arguments?: unknown;
1611
1745
  }[] | undefined;
1746
+ userMessage?: string | undefined;
1612
1747
  memoryReads?: string[] | undefined;
1613
1748
  memoryUpdates?: Record<string, {
1614
1749
  value?: unknown;
1615
1750
  metadata?: Record<string, unknown> | undefined;
1616
1751
  description?: string | undefined;
1617
1752
  }> | undefined;
1753
+ isComplete?: boolean | undefined;
1754
+ finalResult?: unknown;
1618
1755
  }>;
1619
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>;
1620
1768
  /**
1621
1769
  * Schema for tool execution result summary
1622
1770
  */
@@ -2156,4 +2304,4 @@ declare class ToolRunner {
2156
2304
  };
2157
2305
  }
2158
2306
 
2159
- 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, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, 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 };