UNPKG

@axarai/axar

Version:

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

133 lines (132 loc) 4.15 kB
import 'reflect-metadata'; import { ZodSchema } from 'zod'; import { InputOutputType, ModelConfig } from './types'; import { SchemaConstructor } from '../schema'; /** * `model` decorator to associate a model identifier and configuration with an agent. * * @param modelIdentifier - The model identifier string. List of model identifiers available at https://axar-ai.gitbook.io/axar/basics/model * @param config - Optional configuration for the model * @returns A class decorator function. * * @example * ```typescript * // Basic usage * @model('openai:gpt-4-mini') * class MyAgent extends Agent<string, string> {} * * // With configuration * @model('openai:gpt-4-mini', { * maxTokens: 100, * temperature: 0.5, * maxRetries: 3, * maxSteps: 3, * toolChoice: 'auto' * }) * class MyConfiguredAgent extends Agent<string, string> {} * ``` */ export declare function model(modelIdentifier: string, config?: ModelConfig): ClassDecorator; /** * Specifies the output schema for a class. * * @param type - The output type specification, which can be: * - A Zod schema * - A class decorated with @schema * - A primitive type (String, Number, Boolean) * * @example * ```typescript * // Using primitive * @output(String) * class StringAgent extends Agent<string, string> {} * * // Using schema-decorated class * @output(UserProfile) * class UserAgent extends Agent<string, UserProfile> {} * * // Using Zod schema directly * @output(z.boolean()) * class BooleanAgent extends Agent<string, boolean> {} * ``` */ export declare const output: (type: InputOutputType) => ClassDecorator; /** * Specifies the input schema for a class. * * @param type - The input type specification, which can be: * - A Zod schema * - A class decorated with @schema * - A primitive type (String, Number, Boolean) * * @example * ```typescript * // Using primitive * @input(Boolean) * class BooleanAgent extends Agent<boolean, string> {} * * // Using schema-decorated class * @input(UserProfile) * class UserAgent extends Agent<UserProfile, string> {} * * // Using Zod schema directly * @input(z.boolean()) * class BooleanAgent extends Agent<boolean, string> {} * ``` */ export declare const input: (type: InputOutputType) => ClassDecorator; /** * Class-level `systemPrompt` decorator. * * Use this decorator to add a static system prompt to the entire class. * The provided system prompt will be prepended to the list of system prompts for the class. * * Usage: * ```typescript * @systemPrompt("Static system prompt.") * class ExampleClass { * // Class implementation * } * ``` * * @param prompt - A static system prompt string to associate with the class. * @returns A class decorator function. */ export declare function systemPrompt(prompt: string): ClassDecorator; /** * Method-level `systemPrompt` decorator. * * Use this decorator on methods to dynamically provide a system prompt. * The method must return a string or a Promise resolving to a string, which * will be added to the list of system prompts for the class. * * Usage: * ```typescript * class ExampleClass { * @systemPrompt * async dynamicPromptMethod(): Promise<string> { * return "Dynamic system prompt from the method."; * } * } * ``` * * @returns A method decorator function. * @throws An error if applied to a property or a method that does not return a string. */ export declare function systemPrompt(): MethodDecorator; /** * `@tool` decorator to mark a method as a tool with a description and schema. * Supports both explicit ZodSchema and class-based schema derivation. * * Usage with ZodSchema: * @tool("Description", z.object({ ... })) * * Usage with class-based schema: * @tool("Description") * async method(params: ClassBasedParams): Promise<ReturnType> { ... } * * @param description - Description of the tool's functionality. * @param schemaOrClass - Optional Zod schema or class constructor. * @returns A method decorator function. */ export declare function tool(description: string, schemaOrClass?: ZodSchema<any> | SchemaConstructor): MethodDecorator;