UNPKG

@axarai/axar

Version:

TypeScript-based agent framework for building agentic applications powered by LLMs

99 lines (98 loc) 4.09 kB
import { z, ZodSchema } from 'zod'; import { SchemaConstructor } from '../schema'; import { CoreTool, StreamTextResult, DeepPartial, Output, CoreMessage, LanguageModelV1 } from 'ai'; /** * Union type representing all possible input/output type specifications. * Can be a Zod schema, a schema constructor, or a primitive constructor. * Used to define the shape and validation rules for agent inputs and outputs. */ export type InputOutputType = ZodSchema | SchemaConstructor | StringConstructor | NumberConstructor | BooleanConstructor; /** * Metadata for tool annotation */ export type ToolMetadata = Readonly<{ name: string; description: string; method: string; parameters: z.ZodObject<any>; /** Whether the parameter is a primitive type wrapped in { value: T } */ isPrimitiveParam?: boolean; }>; /** * Type helper for processed stream output that handles both string and object types. * For string types, it returns string directly. * For object types, it returns a deep partial version of the type, allowing for partial objects during streaming. * * @typeParam T - The type to process. Can be string or any object type. */ export type StreamOutput<T> = T extends string ? string : DeepPartial<T>; /** * Stream result that provides both processed and raw stream access */ export interface StreamResult<TOutput> { /** * Processed stream that automatically handles TOutput type. * For string outputs, provides string chunks. * For object outputs, provides partial objects as they stream. */ stream: AsyncIterable<StreamOutput<TOutput>>; /** Raw stream access for advanced usage */ raw: StreamTextResult<Record<string, CoreTool>, TOutput>; } /** * Type alias for the experimental output configuration returned by Output.object */ export type ExperimentalOutput = ReturnType<typeof Output.object>; /** * Configuration for agent output handling */ export interface OutputConfig { model: LanguageModelV1; messages: CoreMessage[]; tools: Record<string, CoreTool>; maxSteps: number; /** Maximum number of tokens to generate */ maxTokens?: number; /** Sampling temperature between 0 and 1 */ temperature?: number; /** Nucleus sampling - sample from the smallest set of tokens whose cumulative probability exceeds topP */ topP?: number; /** Only sample from the top K options for each subsequent token */ topK?: number; /** Penalize tokens based on their presence in the prompt and generated text so far */ presencePenalty?: number; /** Penalize tokens based on their frequency in the generated text so far */ frequencyPenalty?: number; /** Maximum number of retries for failed requests */ maxRetries?: number; /** Tool choice mode - 'auto' or 'none' */ toolChoice?: 'auto' | 'none'; experimental_telemetry: { isEnabled: boolean; functionId: string; }; experimental_output?: ExperimentalOutput; } /** * Configuration options for the language model. */ export interface ModelConfig { /** Maximum number of tokens to generate */ maxTokens?: number; /** Sampling temperature between 0 and 1. Use either temperature or topP, not both. */ temperature?: number; /** Nucleus sampling - sample from the smallest set of tokens whose cumulative probability exceeds topP. Use either temperature or topP, not both. */ topP?: number; /** Only sample from the top K options for each subsequent token. Recommended for advanced use cases only. */ topK?: number; /** Penalize tokens based on their presence in the prompt and generated text so far. Value between -2.0 and 2.0. */ presencePenalty?: number; /** Penalize tokens based on their frequency in the generated text so far. Value between -2.0 and 2.0. */ frequencyPenalty?: number; /** Maximum number of retries for failed requests */ maxRetries?: number; /** Maximum number of steps in a conversation */ maxSteps?: number; /** Tool choice mode - 'auto' or 'none' */ toolChoice?: 'auto' | 'none'; }