|  | 
|  | 1 | +--- | 
|  | 2 | +"@voltagent/core": minor | 
|  | 3 | +--- | 
|  | 4 | + | 
|  | 5 | +## Introducing Toolkits for Better Tool Management | 
|  | 6 | + | 
|  | 7 | +Managing related tools and their instructions is now simpler with `Toolkit`s. | 
|  | 8 | + | 
|  | 9 | +**Motivation:** | 
|  | 10 | + | 
|  | 11 | +- Defining shared instructions for multiple related tools was cumbersome. | 
|  | 12 | +- The logic for deciding which instructions to add to the agent's system prompt could become complex. | 
|  | 13 | +- We wanted a cleaner way to group tools logically. | 
|  | 14 | + | 
|  | 15 | +**What's New: The `Toolkit`** | 
|  | 16 | + | 
|  | 17 | +A `Toolkit` bundles related tools and allows defining shared `instructions` and an `addInstructions` flag _at the toolkit level_. | 
|  | 18 | + | 
|  | 19 | +```typescript | 
|  | 20 | +// packages/core/src/tool/toolkit.ts | 
|  | 21 | +export type Toolkit = { | 
|  | 22 | +  /** | 
|  | 23 | +   * Unique identifier name for the toolkit. | 
|  | 24 | +   */ | 
|  | 25 | +  name: string; | 
|  | 26 | +  /** | 
|  | 27 | +   * A brief description of what the toolkit does. Optional. | 
|  | 28 | +   */ | 
|  | 29 | +  description?: string; | 
|  | 30 | +  /** | 
|  | 31 | +   * Shared instructions for the LLM on how to use the tools within this toolkit. | 
|  | 32 | +   * Optional. | 
|  | 33 | +   */ | 
|  | 34 | +  instructions?: string; | 
|  | 35 | +  /** | 
|  | 36 | +   * Whether to automatically add the toolkit's `instructions` to the agent's system prompt. | 
|  | 37 | +   * Defaults to false. | 
|  | 38 | +   */ | 
|  | 39 | +  addInstructions?: boolean; | 
|  | 40 | +  /** | 
|  | 41 | +   * An array of Tool instances that belong to this toolkit. | 
|  | 42 | +   */ | 
|  | 43 | +  tools: Tool<any>[]; | 
|  | 44 | +}; | 
|  | 45 | +``` | 
|  | 46 | + | 
|  | 47 | +**Key Changes to Core:** | 
|  | 48 | + | 
|  | 49 | +1.  **`ToolManager` Upgrade:** Now manages both `Tool` and `Toolkit` objects. | 
|  | 50 | +2.  **`AgentOptions` Update:** The `tools` option accepts `(Tool<any> | Toolkit)[]`. | 
|  | 51 | +3.  **Simplified Instruction Handling:** `Agent` now only adds instructions from `Toolkit`s where `addInstructions` is true. | 
|  | 52 | + | 
|  | 53 | +This change leads to a clearer separation of concerns, simplifies the agent's internal logic, and makes managing tool instructions more predictable and powerful. | 
|  | 54 | + | 
|  | 55 | +### New `createToolkit` Helper | 
|  | 56 | + | 
|  | 57 | +We've also added a helper function, `createToolkit`, to simplify the creation of toolkits. It provides default values and basic validation: | 
|  | 58 | + | 
|  | 59 | +```typescript | 
|  | 60 | +// packages/core/src/tool/toolkit.ts | 
|  | 61 | +export const createToolkit = (options: Toolkit): Toolkit => { | 
|  | 62 | +  if (!options.name) { | 
|  | 63 | +    throw new Error("Toolkit name is required"); | 
|  | 64 | +  } | 
|  | 65 | +  if (!options.tools || options.tools.length === 0) { | 
|  | 66 | +    console.warn(`Toolkit '${options.name}' created without any tools.`); | 
|  | 67 | +  } | 
|  | 68 | + | 
|  | 69 | +  return { | 
|  | 70 | +    name: options.name, | 
|  | 71 | +    description: options.description || "", // Default empty description | 
|  | 72 | +    instructions: options.instructions, | 
|  | 73 | +    addInstructions: options.addInstructions || false, // Default to false | 
|  | 74 | +    tools: options.tools || [], // Default to empty array | 
|  | 75 | +  }; | 
|  | 76 | +}; | 
|  | 77 | +``` | 
|  | 78 | + | 
|  | 79 | +**Example Usage:** | 
|  | 80 | + | 
|  | 81 | +```typescript | 
|  | 82 | +import { createTool, createToolkit } from "@voltagent/core"; | 
|  | 83 | +import { z } from "zod"; | 
|  | 84 | + | 
|  | 85 | +// Define some tools first | 
|  | 86 | +const getWeather = createTool({ | 
|  | 87 | +  name: "getWeather", | 
|  | 88 | +  description: "Gets the weather for a location.", | 
|  | 89 | +  schema: z.object({ location: z.string() }), | 
|  | 90 | +  run: async ({ location }) => ({ temperature: "25C", condition: "Sunny" }), | 
|  | 91 | +}); | 
|  | 92 | + | 
|  | 93 | +const searchWeb = createTool({ | 
|  | 94 | +  name: "searchWeb", | 
|  | 95 | +  description: "Searches the web for a query.", | 
|  | 96 | +  schema: z.object({ query: z.string() }), | 
|  | 97 | +  run: async ({ query }) => ({ results: ["Result 1", "Result 2"] }), | 
|  | 98 | +}); | 
|  | 99 | + | 
|  | 100 | +// Create a toolkit using the helper | 
|  | 101 | +const webInfoToolkit = createToolkit({ | 
|  | 102 | +  name: "web_information", | 
|  | 103 | +  description: "Tools for getting information from the web.", | 
|  | 104 | +  instructions: "Use these tools to find current information online.", | 
|  | 105 | +  addInstructions: true, // Add the instructions to the system prompt | 
|  | 106 | +  tools: [getWeather, searchWeb], | 
|  | 107 | +}); | 
|  | 108 | + | 
|  | 109 | +console.log(webInfoToolkit); | 
|  | 110 | +/* | 
|  | 111 | +Output: | 
|  | 112 | +{ | 
|  | 113 | +  name: 'web_information', | 
|  | 114 | +  description: 'Tools for getting information from the web.', | 
|  | 115 | +  instructions: 'Use these tools to find current information online.', | 
|  | 116 | +  addInstructions: true, | 
|  | 117 | +  tools: [ [Object Tool: getWeather], [Object Tool: searchWeb] ] | 
|  | 118 | +} | 
|  | 119 | +*/ | 
|  | 120 | +``` | 
0 commit comments