Adding a Built-In Tool
このコンテンツはまだ日本語訳がありません。
How to add a tool the model can call during the tool loop. toolInitializer.ts discovers it at
startup, so there is no registration step.
- Create a file in
src/tools/functionCalls/exporting a class that extendsBaseTool. - Define
name(unique across all tools),description(shown to the model, in English),category,parameters(JSON Schema), andexecute(). - Add optional members as needed:
requiresFeatureFlag(see Adding a Feature-Flagged Tool),requiresPermissions, andrequiresFollowUpwhen the result needs another generation turn. - Pass
context.abortSignalto every HTTP call:signalforfetch,externalSignalforsafeDownload, and any helper option that takes anAbortSignal. Otherwise/killstops the turn but the request keeps running. - If the tool posts its own output (an attachment, a webhook message), check
context.abortSignal?.abortedimmediately before posting and return a failure instead./killstops the tool loop from awaiting the tool. The tool can keep running when a backend ignores the signal, so without this check a killed tool can still post. If it generates billable media, also add its name to the matching image, video, or voice group insrc/utils/tools/deliberateToolMode.ts; those groups feedMEDIA_GENERATION_TOOL_NAMES, which is how/killknows to warn about the leftover job.
Verify
Section titled “Verify”Run bun run check and bun run lint, then prompt the bot so it calls the tool and check the
tool-loop logs. How tools are dispatched: Tool loop.