UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

91 lines 2.08 kB
/** * Base agent interface and implementations */ import { BaseChatLLM } from '../llms/base'; import { Tool, ToolManager } from '../tools/base'; /** * Agent configuration */ export interface AgentConfig { llm: BaseChatLLM; tools: Tool[]; maxIterations?: number; verbose?: boolean; } /** * Agent action representing a tool use */ export interface AgentAction { tool: string; toolInput: string; log?: string; } /** * Agent finish representing final answer */ export interface AgentFinish { output: string; log?: string; } /** * Agent step result */ export type AgentStep = AgentAction | AgentFinish; /** * Check if step is a finish */ export declare function isAgentFinish(step: AgentStep): step is AgentFinish; /** * Agent execution context */ export interface AgentExecutionContext { input: string; steps: Array<{ action?: AgentAction; observation?: string; finish?: AgentFinish; }>; iterations: number; } /** * Base agent class */ export declare abstract class BaseAgent { protected llm: BaseChatLLM; protected toolManager: ToolManager; protected maxIterations: number; protected verbose: boolean; constructor(config: AgentConfig); /** * Plan the next action or finish */ abstract plan(context: AgentExecutionContext): Promise<AgentStep>; /** * Execute the agent with given input */ execute(input: string): Promise<string>; /** * Get available tools formatted for prompt */ protected getToolsDescription(): string; /** * Format execution history for prompt */ protected formatHistory(context: AgentExecutionContext): string; } /** * Simple agent executor for running agents */ export declare class AgentExecutor { private agent; constructor(agent: BaseAgent); /** * Run the agent with given input */ run(input: string): Promise<string>; /** * Run with multiple inputs */ runBatch(inputs: string[]): Promise<string[]>; } //# sourceMappingURL=base.d.ts.map