UNPKG

taskforce-aiagent

Version:

TaskForce is a modular, open-source, production-ready TypeScript agent framework for orchestrating AI agents, LLM-powered autonomous agents, task pipelines, dynamic toolchains, RAG workflows and memory/retrieval systems.

101 lines (100 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolRegistry = exports.ToolCategories = void 0; exports.ToolCategories = [ "search", "rag", "file", "api", "external", "vision", "langchain", "custom", ]; const toolMap = new Map(); class ToolRegistry { /** * Register a tool in the global registry. * If a tool with the same id or name exists, return. */ static register(toolInstance, category, source = "built-in") { if (toolMap.has(toolInstance.id) || toolMap.has(toolInstance.name)) { return; } toolMap.set(toolInstance.id, { id: toolInstance.id, name: toolInstance.name, instance: toolInstance, category: category || toolInstance.category, source: source || toolInstance.source, }); // (Optional) Also register by name for backward compatibility toolMap.set(toolInstance.name, { id: toolInstance.id, name: toolInstance.name, instance: toolInstance, category: category || toolInstance.category, source: source || toolInstance.source, }); } /** Remove a tool by id or name. */ static unregister(key) { toolMap.delete(key); } /** * Get all registered tools, with optional filtering by category or source. */ static getAll(filter) { let tools = Array.from(toolMap.values()).filter((t, i, arr) => arr.findIndex((other) => other.id === t.id) === i // Unique by id ); if (filter?.category) { tools = tools.filter((tool) => tool.category === filter.category); } if (filter?.source) { tools = tools.filter((tool) => tool.source === filter.source); } return tools; } /** Get a tool by id or name. */ static getByKey(key) { return toolMap.get(key); } /** Reload/replace a tool (for hot reloading, development, or plugin updates). */ static update(toolInstance, category, source) { toolMap.set(toolInstance.id, { id: toolInstance.id, name: toolInstance.name, instance: toolInstance, category: category || toolInstance.category, source: source || toolInstance.source, }); toolMap.set(toolInstance.name, { id: toolInstance.id, name: toolInstance.name, instance: toolInstance, category: category || toolInstance.category, source: source || toolInstance.source, }); } /** For external tool adapters (LangChain, CrewAI etc), mass-register tools in batch. */ static registerBatch(tools, category, source = "external") { for (const tool of tools) { this.register(tool, category, source); } } /** For auto-discovery/documentation/UI. */ static listToolSummaries() { return this.getAll().map(({ id, name, instance, category, source }) => ({ id, name, description: instance.description, examples: instance.examples, parameters: instance.parameters, inputSchema: instance.inputSchema, category: category || instance.category, source: source || instance.source, cacheable: instance.cacheable, })); } } exports.ToolRegistry = ToolRegistry;