import { z } from "zod"; import { Chat, AskOptions } from "../chat/Chat.js"; import { ChatOptions } from "../chat/ChatOptions.js"; import { ChatResponseString } from "../chat/ChatResponse.js"; import { ToolResolvable } from "../chat/Tool.js"; import { ThinkingConfig, ThinkingResult } from "../providers/Provider.js"; import { Schema } from "../schema/Schema.js"; import { NodeLLMCore } from "../llm.js"; import { Middleware } from "../types/Middleware.js"; /** * A value that can be a static T or a function that returns T based on inputs. */ export type LazyValue> = T | ((inputs: I) => T); /** * Configuration options for Agent. */ export interface AgentConfig> { /** The model ID to use (e.g., "gpt-4o") */ model?: string; /** The provider to use (e.g., "openai") */ provider?: string; /** System instructions for the agent (can be lazy) */ instructions?: LazyValue; /** Tools available to the agent (can be lazy) */ tools?: LazyValue; /** Temperature for response generation (0.0 - 1.0) */ temperature?: number; /** Extended thinking configuration */ thinking?: ThinkingConfig; /** Output schema for structured responses */ schema?: z.ZodType | Schema | Record; /** Provider-specific parameters */ params?: Record; /** Custom headers for requests */ headers?: Record; /** Maximum tokens in response */ maxTokens?: number; /** Maximum tool call iterations */ maxToolCalls?: number; /** Assume model exists without validation */ assumeModelExists?: boolean; /** Optional LLM instance to use instead of global NodeLLM */ llm?: NodeLLMCore; /** Optional initial inputs to resolve lazy config immediately */ inputs?: I; /** Middlewares for the agent's chat instance */ middlewares?: Middleware[]; } /** * Base class for creating reusable, class-configured agents. */ export declare abstract class Agent = Record, S extends Record = Record> { static model?: string; static provider?: string; static instructions?: LazyValue>; static tools?: LazyValue>; static temperature?: number; static thinking?: ThinkingConfig; static schema?: z.ZodType | Schema | Record; static params?: Record; static headers?: Record; static maxTokens?: number; static maxToolCalls?: number; static assumeModelExists?: boolean; static middlewares?: Middleware[]; /** * Explicitly declare which inputs this agent expects. * Useful for introspection and validation. */ static inputs?: string[]; /** * Hook called when the agent starts a new session (ask/stream). */ static onStart(_context: { messages: unknown[]; }): void | Promise; static onThinking(_thinking: ThinkingResult, _result: ChatResponseString): void | Promise; static onToolStart(_toolCall: unknown): void | Promise; static onToolEnd(_toolCall: unknown, _result: unknown): void | Promise; static onToolError(_toolCall: unknown, _error: Error): void | Promise; static onComplete(_result: ChatResponseString): void | Promise; /** * Run the agent immediately with a prompt. */ static ask, S extends Record>(this: new (overrides?: Partial & ChatOptions>) => Agent, message: string, options?: AskOptions & { inputs?: I; }): Promise; /** * Stream the agent response immediately. */ static stream, S extends Record>(this: new (overrides?: Partial & ChatOptions>) => Agent, message: string, options?: AskOptions & { inputs?: I; }): import("../index.js").Stream; /** The underlying Chat instance */ protected readonly chat: Chat; /** Private reference to configuration overrides for lazy resolution */ private readonly config; /** * Create a new agent instance. * @param overrides - Optional configuration to override static properties */ constructor(overrides?: Partial & ChatOptions>); /** * Helper to resolve lazy instructions and tools based on inputs. */ private resolveLazyConfig; /** * Add instructions to the agent (replaces or appends). */ withInstructions(instructions: string, options?: { replace?: boolean; }): this; /** * Add tools to the agent. */ withTools(tools: ToolResolvable[], options?: { replace?: boolean; }): this; /** * Alias for withTools([tool]). */ use(tool: ToolResolvable): this; /** * Send a message to the agent and get a response. */ ask(message: string, options?: AskOptions & { inputs?: I; }): Promise; /** * Hook called when a tool call starts. */ onToolCallStart(handler: (toolCall: unknown) => void | Promise): this; /** * Hook called when a tool call ends. */ onToolCallEnd(handler: (toolCall: unknown, result: unknown) => void | Promise): this; /** * Hook called when a tool call errors. */ onToolCallError(handler: (toolCall: unknown, error: Error) => "STOP" | "CONTINUE" | "RETRY" | void | Promise<"STOP" | "CONTINUE" | "RETRY" | void>): this; /** * Hook called before a request. */ beforeRequest(handler: (messages: unknown[]) => Promise): this; /** * Hook called after a response. */ afterResponse(handler: (response: ChatResponseString) => Promise): this; /** * Alias for ask() */ say(message: string, options?: AskOptions & { inputs?: I; }): Promise; /** * Stream a response from the agent. */ stream(message: string, options?: AskOptions & { inputs?: I; }): import("../index.js").Stream; /** * Get the conversation history. */ get history(): readonly import("../index.js").Message[]; /** * Get the model ID being used. */ get modelId(): string; /** * Get aggregate token usage across the conversation. */ get totalUsage(): import("../providers/Provider.js").Usage; /** * Access the underlying Chat instance for advanced operations. */ get underlyingChat(): Chat; } /** * Helper function to define an agent inline without creating a class. */ export declare function defineAgent = Record, S extends Record = Record>(config: AgentConfig): new (overrides?: Partial & ChatOptions>) => Agent; //# sourceMappingURL=Agent.d.ts.map