crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
146 lines • 5.14 kB
TypeScript
/**
* Base Agent Builder
* Abstract base class for agent builders that provides a foundation for creating agents
* with optimized performance and memory usage
*/
import { BaseAgent, AgentConfig } from '../BaseAgent.js';
import { BaseTool } from '../../tools/BaseTool.js';
import { Task } from '../../task/Task.js';
import { BaseLLM } from '../../llm/BaseLLM.js';
import { BaseKnowledgeSource } from '../../knowledge/source/BaseKnowledgeSource.js';
import { AgentBuilderState } from './types/index.js';
declare class CacheHandler {
getOrCompute<T>(key: string, producer: () => Promise<T>): Promise<T>;
}
declare class ToolsHandler {
setCache(cache: CacheHandler): void;
addTool(tool: BaseTool): void;
addTools(tools: BaseTool[]): void;
}
/**
* Type for a function that can be called to validate a tool
*/
export type ToolValidator = (tool: any) => BaseTool | null;
/**
* Base Agent Builder class that provides core functionality for building agents
* Optimized for performance and memory efficiency
*/
export declare abstract class BaseAgentBuilder implements Omit<BaseAgent, 'executeTask' | 'getDelegationTools'>, AgentBuilderState {
readonly id: string;
readonly originalRole: string;
readonly originalGoal: string;
readonly originalBackstory?: string;
private _role;
private _goal;
private _backstory?;
get role(): string;
get goal(): string;
get backstory(): string | undefined;
protected _verbose: boolean;
protected _allowDelegation: boolean;
protected _maxIterations: number;
protected _maxRpm?: number;
protected _memory: boolean;
protected _cache: boolean;
protected _tools: BaseTool[];
protected _llm?: BaseLLM | string;
protected _functionCallingLlm?: BaseLLM | string;
protected _knowledgeSources?: BaseKnowledgeSource[];
protected _knowledgeStorage?: any;
protected _systemPrompt?: string;
protected _useSystemPrompt: boolean;
protected _cacheHandler?: CacheHandler;
protected _toolsHandler: ToolsHandler;
protected _logger: any;
protected _rpmController?: any;
private static _agentExecutors;
/**
* Constructor for the BaseAgentBuilder
* @param config Configuration for the agent
*/
constructor(config: AgentConfig);
/**
* Execute a task with this agent
* Abstract method to be implemented by subclasses
*/
abstract executeTask(task: Task, context?: string, tools?: BaseTool[]): Promise<any>;
/**
* Get tools for delegating tasks to other agents
* Abstract method to be implemented by subclasses
*/
abstract getDelegationTools(agents: BaseAgent[]): BaseTool[];
/**
* Set knowledge for the agent
* @param knowledge Knowledge sources or embeddings
*/
setKnowledge(knowledge: unknown): Promise<void>;
/**
* Create an agent executor for the agent
* This is lazily initialized when needed
*/
protected abstract createAgentExecutor(tools?: BaseTool[], task?: Task): Promise<any>;
/**
* Generate a unique key for this agent based on its configuration
* Used for caching purposes
*/
get key(): string;
/**
* Create a deep copy of the Agent
* Optimized to avoid unnecessary duplication of resources
*/
copy(): BaseAgentBuilder;
/**
* Interpolate inputs into the agent description and backstory
* @param inputs Values to interpolate into the agent template strings
*/
interpolateInputs(inputs: Record<string, any>): void;
/**
* Set the cache handler for the agent
* @param cacheHandler An instance of the CacheHandler class
*/
setCacheHandler(cacheHandler: CacheHandler): void;
/**
* Set the RPM controller for the agent
* @param rpmController An instance of the RPMController class
*/
setRpmController(rpmController: any): void;
/**
* Validate and process the tools provided to the agent
* Ensures each tool meets required criteria and converts non-BaseTool to BaseTool
*
* @param tools List of tools to validate
* @returns List of validated BaseTool instances
*/
protected validateTools(tools: any[]): BaseTool[];
/**
* Check if an object is a BaseTool instance
* @param obj Object to check
* @returns True if the object is a BaseTool instance
*/
private isBaseTool;
/**
* Check if an object can be converted to a BaseTool
* @param obj Object to check
* @returns True if the object can be converted to a BaseTool
*/
private canBeConvertedToTool;
/**
* Convert an object to a BaseTool instance
* @param obj Object to convert
* @returns BaseTool instance
*/
private convertToBaseTool;
/**
* Interpolate a string with values from an object
* @param str String to interpolate
* @param values Values to interpolate
* @returns Interpolated string
*/
private interpolateString;
/**
* String representation of the agent
*/
toString(): string;
}
export {};
//# sourceMappingURL=BaseAgentBuilder.d.ts.map