UNPKG

openagentic

Version:

A TypeScript framework for building AI agents with self-contained tool orchestration capabilities

502 lines (473 loc) 17 kB
import { z } from 'zod'; import { Tool } from 'ai'; declare const AIModelSchema: z.ZodObject<{ provider: z.ZodEnum<["openai", "anthropic", "google", "google-vertex", "perplexity", "xai", "custom"]>; model: z.ZodString; apiKey: z.ZodOptional<z.ZodString>; baseURL: z.ZodOptional<z.ZodString>; temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>; maxTokens: z.ZodOptional<z.ZodNumber>; topP: z.ZodOptional<z.ZodNumber>; project: z.ZodOptional<z.ZodString>; location: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { provider: "custom" | "openai" | "anthropic" | "google" | "google-vertex" | "perplexity" | "xai"; model: string; temperature: number; apiKey?: string | undefined; baseURL?: string | undefined; maxTokens?: number | undefined; topP?: number | undefined; project?: string | undefined; location?: string | undefined; }, { provider: "custom" | "openai" | "anthropic" | "google" | "google-vertex" | "perplexity" | "xai"; model: string; apiKey?: string | undefined; baseURL?: string | undefined; temperature?: number | undefined; maxTokens?: number | undefined; topP?: number | undefined; project?: string | undefined; location?: string | undefined; }>; type AIModel = z.infer<typeof AIModelSchema>; declare const MessageSchema: z.ZodObject<{ role: z.ZodEnum<["system", "user", "assistant", "tool"]>; content: z.ZodString; toolCallId: z.ZodOptional<z.ZodString>; toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{ toolCallId: z.ZodString; toolName: z.ZodString; args: z.ZodRecord<z.ZodString, z.ZodAny>; }, "strip", z.ZodTypeAny, { toolCallId: string; toolName: string; args: Record<string, any>; }, { toolCallId: string; toolName: string; args: Record<string, any>; }>, "many">>; }, "strip", z.ZodTypeAny, { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }, { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }>; type Message = z.infer<typeof MessageSchema>; type ApiKeyMap = Record<string, string> & { awsAccessKeyId?: string; awsSecretAccessKey?: string; awsRegion?: string; awsS3Bucket?: string; bedrockAccessKeyId?: string; bedrockSecretAccessKey?: string; bedrockRegion?: string; }; interface CoreMessage { role: 'system' | 'user' | 'assistant' | 'tool'; content: string | Array<any>; toolCallId?: string; toolCalls?: Array<{ toolCallId: string; toolName: string; args: Record<string, any>; }>; } type LogLevel = 'none' | 'basic' | 'detailed'; interface LoggingConfig { enableDebugLogging?: boolean; logLevel?: LogLevel; enableStepLogging?: boolean; enableToolLogging?: boolean; enableTimingLogging?: boolean; enableStatisticsLogging?: boolean; } interface ExecutionStats { totalDuration: number; stepsExecuted: number; toolCallsExecuted: number; tokensUsed?: number; averageStepDuration: number; averageToolCallDuration: number; } interface StepInfo { stepIndex: number; stepType: string; duration: number; toolCalls: string[]; errors: string[]; startTime: number; endTime: number; } type ToolDetails = { toolId: string; name: string; useCases: string[]; logo: string; internal?: boolean; }; type OpenAgenticTool = Tool & ToolDetails; declare const ExecutionResultSchema: z.ZodObject<{ success: z.ZodBoolean; result: z.ZodOptional<z.ZodAny>; error: z.ZodOptional<z.ZodString>; messages: z.ZodArray<z.ZodObject<{ role: z.ZodEnum<["system", "user", "assistant", "tool"]>; content: z.ZodString; toolCallId: z.ZodOptional<z.ZodString>; toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{ toolCallId: z.ZodString; toolName: z.ZodString; args: z.ZodRecord<z.ZodString, z.ZodAny>; }, "strip", z.ZodTypeAny, { toolCallId: string; toolName: string; args: Record<string, any>; }, { toolCallId: string; toolName: string; args: Record<string, any>; }>, "many">>; }, "strip", z.ZodTypeAny, { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }, { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }>, "many">; iterations: z.ZodNumber; toolCallsUsed: z.ZodArray<z.ZodString, "many">; executionStats: z.ZodOptional<z.ZodObject<{ totalDuration: z.ZodNumber; stepsExecuted: z.ZodNumber; toolCallsExecuted: z.ZodNumber; tokensUsed: z.ZodOptional<z.ZodNumber>; averageStepDuration: z.ZodNumber; averageToolCallDuration: z.ZodNumber; }, "strip", z.ZodTypeAny, { totalDuration: number; stepsExecuted: number; toolCallsExecuted: number; averageStepDuration: number; averageToolCallDuration: number; tokensUsed?: number | undefined; }, { totalDuration: number; stepsExecuted: number; toolCallsExecuted: number; averageStepDuration: number; averageToolCallDuration: number; tokensUsed?: number | undefined; }>>; usage: z.ZodOptional<z.ZodObject<{ totalTokens: z.ZodNumber; promptTokens: z.ZodNumber; completionTokens: z.ZodNumber; }, "strip", z.ZodTypeAny, { totalTokens: number; promptTokens: number; completionTokens: number; }, { totalTokens: number; promptTokens: number; completionTokens: number; }>>; }, "strip", z.ZodTypeAny, { success: boolean; messages: { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }[]; iterations: number; toolCallsUsed: string[]; result?: any; error?: string | undefined; executionStats?: { totalDuration: number; stepsExecuted: number; toolCallsExecuted: number; averageStepDuration: number; averageToolCallDuration: number; tokensUsed?: number | undefined; } | undefined; usage?: { totalTokens: number; promptTokens: number; completionTokens: number; } | undefined; }, { success: boolean; messages: { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string | undefined; toolCalls?: { toolCallId: string; toolName: string; args: Record<string, any>; }[] | undefined; }[]; iterations: number; toolCallsUsed: string[]; result?: any; error?: string | undefined; executionStats?: { totalDuration: number; stepsExecuted: number; toolCallsExecuted: number; averageStepDuration: number; averageToolCallDuration: number; tokensUsed?: number | undefined; } | undefined; usage?: { totalTokens: number; promptTokens: number; completionTokens: number; } | undefined; }>; type ExecutionResult = z.infer<typeof ExecutionResultSchema>; /** * Supported orchestrator types */ type OrchestratorType = 'prompt-based' | 'custom-logic'; /** * Context object passed to orchestrator execute methods */ interface OrchestratorContext { model: AIModel; tools: OpenAgenticTool[]; messages: Message[]; iterations: number; maxIterations: number; loggingConfig: LoggingConfig; orchestratorParams?: Record<string, any>; } /** * Base interface for all orchestrators */ interface BaseOrchestrator { /** Unique identifier for the orchestrator */ id: string; /** Human-readable name */ name: string; /** Description of what this orchestrator does */ description: string; /** Type of orchestrator */ type: OrchestratorType; /** Execute the orchestration logic */ execute(input: string | CoreMessage[], context: OrchestratorContext): Promise<ExecutionResult>; /** Get the orchestrator name */ getName(): string; /** Get the orchestrator description */ getDescription(): string; /** Get the orchestrator type */ getType(): OrchestratorType; /** Optional validation method for inputs */ validate?(input: string | CoreMessage[], context: OrchestratorContext): Promise<boolean>; /** Optional initialization method */ initialize?(context: OrchestratorContext): Promise<void>; /** Optional cleanup method */ cleanup?(context: OrchestratorContext): Promise<void>; } /** * Orchestrator that uses system prompts and standard LLM interaction */ interface PromptBasedOrchestrator extends BaseOrchestrator { type: 'prompt-based'; /** System prompt used for orchestration */ systemPrompt: string; /** Get the system prompt */ getSystemPrompt(): string; /** Optional method to modify system prompt based on context */ buildSystemPrompt?(context: OrchestratorContext): string; } /** * Orchestrator that uses custom logic instead of standard LLM flow */ interface CustomLogicOrchestrator extends BaseOrchestrator { type: 'custom-logic'; /** Custom logic function for orchestration */ customLogic(input: string | CoreMessage[], context: OrchestratorContext): Promise<any>; /** Optional method to determine if custom logic should be used */ shouldUseCustomLogic?(input: string | CoreMessage[], context: OrchestratorContext): boolean; } /** * Options for creating orchestrator-enabled agents */ interface OrchestratorOptions { /** Orchestrator instance or ID to use */ orchestrator?: string | BaseOrchestrator; /** Alternative parameter name for orchestrator ID */ orchestratorId?: string; /** Parameters to pass to the orchestrator */ orchestratorParams?: Record<string, any>; /** Whether to allow orchestrator to override system prompt */ allowOrchestratorPromptOverride?: boolean; /** Whether to allow orchestrator to modify tool execution */ allowOrchestratorToolControl?: boolean; } declare const openaiTool: OpenAgenticTool; declare const openaiImageTool: OpenAgenticTool; declare const openaiVectorStoreTool: OpenAgenticTool; declare const geminiImageTool: OpenAgenticTool; declare const anthropicTool: OpenAgenticTool; declare const cohereTool: OpenAgenticTool; declare const geminiTool: OpenAgenticTool; declare const githubTool: OpenAgenticTool; declare const grokTool: OpenAgenticTool; declare const llamaTool: OpenAgenticTool; declare const mistralTool: OpenAgenticTool; declare const newsdataTool: OpenAgenticTool; declare const perplexityTool: OpenAgenticTool; declare const qrcodeTool: OpenAgenticTool; declare const websearchTool: OpenAgenticTool; declare const elevenlabsTool: OpenAgenticTool; declare const videoGenerationTool: OpenAgenticTool; declare const geminiTtsTool: OpenAgenticTool; declare const inceptionLabsTool: OpenAgenticTool; declare const htmlComposerTool: OpenAgenticTool; /** * Unsplash Image Search Tool * * Searches for high-quality free photos from Unsplash using keywords. * Returns photo URLs, photographer attribution, and metadata. * * Features: * - Search by keyword/query * - Filter by orientation (landscape, portrait, squarish) * - Filter by color * - Configurable result count (1-10 photos) * - Proper photographer attribution * - Multiple image sizes available * * Requirements: * - UNSPLASH_ACCESS_KEY environment variable * - Photos must be attributed according to Unsplash License * * @example * ```typescript * // Search for nature photos * const result = await unsplashTool.execute({ * query: "nature landscape", * count: 3, * orientation: "landscape" * }); * * // Use the regular size URL for display * const imageUrl = result.photos[0].urls.regular; * ``` */ declare const unsplashTool: OpenAgenticTool; declare const slackPosterTool: OpenAgenticTool; declare const groqTool: OpenAgenticTool; declare const lumaImageTool: OpenAgenticTool; /** * Convert a LangChain Tool to OpenAgentic format * @param lcTool - LangChain Tool or StructuredTool instance * @param opts - Optional configuration * @returns OpenAgentic compatible tool */ declare function convertLangchainTool(lcTool: any, opts?: { toolId?: string; useCases?: string[]; logo?: string; paramsSchema?: z.ZodType<any>; }): Promise<OpenAgenticTool>; /** * Helper function to add a custom toolId to an AI SDK tool * This provides better identification and debugging capabilities * * @param tool - AI SDK tool created with tool() function, see ai's ToolParameters type for more details * @param toolId - Unique identifier for the tool * @returns Tool with toolId property for better identification */ declare function toOpenAgenticTool(tool: Tool, details: ToolDetails): OpenAgenticTool; declare const aiTools: OpenAgenticTool[]; declare const utilityTools: OpenAgenticTool[]; declare const allTools: OpenAgenticTool[]; /** * Lightweight tool description interface for metadata-only use cases */ interface ToolDescription extends ToolDetails { description: string; category: 'utility' | 'ai' | 'custom'; parametersCount: number; parameterNames: string[]; internal?: boolean; } /** * Lightweight descriptions of all tools for metadata-only imports. * This export excludes heavy execute functions and parameter schemas, * making it perfect for UI components, documentation, or tool selection interfaces. * * @example * ```typescript * import { allToolDescriptions } from 'openagentic/tools'; * * // Display available tools in a UI * allToolDescriptions.forEach(tool => { * console.log(`${tool.name}: ${tool.description}`); * console.log(`Parameters: ${tool.parameterNames.join(', ')}`); * console.log(`Use cases: ${tool.useCases.join(', ')}`); * }); * * // Filter tools by category * const utilityTools = allToolDescriptions.filter(t => t.category === 'utility'); * const aiTools = allToolDescriptions.filter(t => t.category === 'ai'); * ``` */ declare const allToolDescriptions: ToolDescription[]; /** * Categorized tool descriptions for easier filtering */ declare const toolDescriptionsByCategory: { readonly utility: ToolDescription[]; readonly ai: ToolDescription[]; readonly all: ToolDescription[]; }; /** * Get tool description by tool ID */ declare function getToolDescription(toolId: string): ToolDescription | undefined; /** * Get tool descriptions by category */ declare function getToolDescriptionsByCategory(category: 'utility' | 'ai' | 'custom'): ToolDescription[]; /** * Search tool descriptions by name or description */ declare function searchToolDescriptions(query: string): ToolDescription[]; export { type ToolDetails as $, type AIModel as A, type BaseOrchestrator as B, type CoreMessage as C, perplexityTool as D, type ExecutionResult as E, qrcodeTool as F, websearchTool as G, elevenlabsTool as H, videoGenerationTool as I, geminiTtsTool as J, inceptionLabsTool as K, type LogLevel as L, type Message as M, htmlComposerTool as N, type OrchestratorOptions as O, type PromptBasedOrchestrator as P, unsplashTool as Q, slackPosterTool as R, groqTool as S, type ToolDescription as T, lumaImageTool as U, toOpenAgenticTool as V, AIModelSchema as W, MessageSchema as X, type LoggingConfig as Y, type ExecutionStats as Z, type StepInfo as _, type OpenAgenticTool as a, ExecutionResultSchema as a0, type ApiKeyMap as b, type OrchestratorType as c, type OrchestratorContext as d, type CustomLogicOrchestrator as e, convertLangchainTool as f, aiTools as g, allTools as h, allToolDescriptions as i, getToolDescription as j, getToolDescriptionsByCategory as k, openaiImageTool as l, openaiVectorStoreTool as m, geminiImageTool as n, openaiTool as o, anthropicTool as p, cohereTool as q, geminiTool as r, searchToolDescriptions as s, toolDescriptionsByCategory as t, utilityTools as u, githubTool as v, grokTool as w, llamaTool as x, mistralTool as y, newsdataTool as z };