diff --git a/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx b/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx index e1570836..f7de590e 100644 --- a/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx +++ b/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiPlugin - + diff --git a/apps/website/docs/api-reference/ai/variables/default-tools.mdx b/apps/website/docs/api-reference/ai/variables/default-tools.mdx new file mode 100644 index 00000000..9bd6a9e7 --- /dev/null +++ b/apps/website/docs/api-reference/ai/variables/default-tools.mdx @@ -0,0 +1,42 @@ +--- +title: "DefaultTools" +isDefaultIndex: false +generated: true +--- + +import MemberInfo from '@site/src/components/MemberInfo'; +import GenerationInfo from '@site/src/components/GenerationInfo'; +import MemberDescription from '@site/src/components/MemberDescription'; + + + + +## defaultTools + + + +A record of all built-in tools provided by the AI plugin. +These tools are automatically available to the AI unless `disableBuiltInTools` is set to `true`. + +You can use this to selectively include specific built-in tools when `disableBuiltInTools` is enabled: + + + +*Example* + +```ts +import { configureAI, defaultTools } from '@commandkit/ai'; + +configureAI({ + disableBuiltInTools: true, + selectAiModel: async (ctx, message) => ({ + model: google.languageModel('gemini-2.0-flash'), + // Only include specific built-in tools + tools: { + getAvailableCommands: defaultTools.getAvailableCommands, + getUserById: defaultTools.getUserById, + }, + }), +}); +``` + diff --git a/apps/website/docs/guide/05-official-plugins/01-commandkit-ai.mdx b/apps/website/docs/guide/05-official-plugins/01-commandkit-ai.mdx index a399e635..10422cd1 100644 --- a/apps/website/docs/guide/05-official-plugins/01-commandkit-ai.mdx +++ b/apps/website/docs/guide/05-official-plugins/01-commandkit-ai.mdx @@ -258,8 +258,12 @@ CommandKit provides built-in tools that the AI can use automatically: - **`getCurrentClientInfo`** - Gets information about the bot - **`getGuildById`** - Fetches server information by ID - **`getUserById`** - Fetches user information by ID +- **`getMemberById`** - Fetches guild member information by ID +- **`createEmbed`** - Creates and sends an embed message -You can disable these tools if needed: +### Disabling built-in tools + +You can disable all built-in tools if needed: ```ts configureAI({ @@ -268,6 +272,46 @@ configureAI({ }); ``` +### Selectively enabling built-in tools + +In many cases, you may not need all built-in tools. You can selectively enable +specific tools by disabling built-in tools and then manually adding only the +ones you need using the exported `defaultTools` record: + +```ts title="src/ai.ts" +import { createGoogleGenerativeAI } from '@ai-sdk/google'; +import { configureAI, defaultTools } from '@commandkit/ai'; + +const google = createGoogleGenerativeAI({ + apiKey: process.env.GOOGLE_API_KEY, +}); + +configureAI({ + // Disable all built-in tools + disableBuiltInTools: true, + + selectAiModel: async (ctx, message) => ({ + model: google.languageModel('gemini-2.0-flash'), + maxSteps: 5, + temperature: 0.7, + // Manually add only the tools you need + tools: { + getAvailableCommands: defaultTools.getAvailableCommands, + getUserById: defaultTools.getUserById, + getGuildById: defaultTools.getGuildById, + // Omit tools you don't want, like createEmbed + }, + }), + + messageFilter: async (commandkit, message) => { + return message.mentions.users.has(message.client.user.id); + }, +}); +``` + +This approach gives you full control over which built-in tools are available to +the AI, making your implementation cleaner and more intentional. + ## Creating custom tools Extend the AI's capabilities by creating custom tools: diff --git a/apps/website/vercel.json b/apps/website/vercel.json index e189741d..f82a76fc 100644 --- a/apps/website/vercel.json +++ b/apps/website/vercel.json @@ -1,15 +1,15 @@ { - "$schema": "https://openapi.vercel.sh/vercel.json", - "redirects": [ - { - "source": "/discord", - "destination": "https://discord.gg/T4faJeH84A", - "permanent": true - }, - { - "source": "/github", - "destination": "https://github.com/neplextech/commandkit", - "permanent": true - } - ] -} \ No newline at end of file + "$schema": "https://openapi.vercel.sh/vercel.json", + "redirects": [ + { + "source": "/discord", + "destination": "https://discord.gg/T4faJeH84A", + "permanent": true + }, + { + "source": "/github", + "destination": "https://github.com/neplextech/commandkit", + "permanent": true + } + ] +} diff --git a/packages/ai/src/plugin.ts b/packages/ai/src/plugin.ts index f75ee633..60ea4c40 100644 --- a/packages/ai/src/plugin.ts +++ b/packages/ai/src/plugin.ts @@ -30,7 +30,30 @@ export interface AiConfig { inputSchema: T; } -const defaultTools: Record = { +/** + * A record of all built-in tools provided by the AI plugin. + * These tools are automatically available to the AI unless `disableBuiltInTools` is set to `true`. + * + * You can use this to selectively include specific built-in tools when `disableBuiltInTools` is enabled: + * + * @example + * ```ts + * import { configureAI, defaultTools } from '@commandkit/ai'; + * + * configureAI({ + * disableBuiltInTools: true, + * selectAiModel: async (ctx, message) => ({ + * model: google.languageModel('gemini-2.0-flash'), + * // Only include specific built-in tools + * tools: { + * getAvailableCommands: defaultTools.getAvailableCommands, + * getUserById: defaultTools.getUserById, + * }, + * }), + * }); + * ``` + */ +export const defaultTools: Record = { getAvailableCommands, getChannelById, getCurrentClientInfo, @@ -43,7 +66,7 @@ const defaultTools: Record = { export class AiPlugin extends RuntimePlugin { public readonly name = 'AiPlugin'; private toolsRecord: Record = {}; - private defaultTools = defaultTools; + private builtInTools = defaultTools; private onMessageFunc: ((message: Message) => Promise) | null = null; public constructor(options: AiPluginOptions) { @@ -125,7 +148,7 @@ export class AiPlugin extends RuntimePlugin { ...modelOptions, tools: { // Include built-in least significant tools if not disabled - ...(!disableBuiltInTools && this.defaultTools), + ...(!disableBuiltInTools && this.builtInTools), // include tools added by configureAI() // this should be able to override built-in tools ...modelOptions.tools,