@obayd/agentic
Version:
A powerful agent framework for LLMs.
65 lines (51 loc) • 1.68 kB
JavaScript
// src/Toolpack.js
import { Tool } from './Tool.js';
export class Toolpack {
name = "";
#description = "";
#tools = [];
constructor(name) {
if (typeof name !== "string" || !name.trim())
throw new Error("Toolpack name must be a non-empty string");
if (!/^[a-zA-Z0-9_]+$/.test(name))
throw new Error(
`Invalid toolpack name: "${name}". Use only letters, numbers, and underscores.`
);
this.name = name;
}
static make(name) {
return new this(name);
}
description(description) {
if (typeof description !== "string")
throw new Error("Toolpack description must be a string");
this.#description = description;
return this;
}
desc(description) {
return this.description(description);
}
addTool(tool) {
if (!(tool instanceof Tool))
throw new Error("Can only add Tool instances to a Toolpack");
this.#tools.push(tool);
return this;
}
add(...tools) {
if(Array.isArray(tools[0])) {
tools = tools[0];
}
tools.forEach((tool) => this.addTool(tool));
return this;
}
getTools() {
return [...this.#tools];
}
buildPromptString(isEnabled) {
const toolNames =
this.#tools.map((t) => t.name).join(", ") || "No tools listed";
return `- ${this.name} ${isEnabled ? "(enabled)" : "(disabled)"}: ${
this.#description || "No description provided."
} (Provides: ${toolNames})`;
}
}