filterActiveTools
filterActiveTools filters a tool set to only the string tool names listed in activeTools.
If activeTools is undefined, it returns the original tool set.
If tools is undefined, it returns undefined.
filterActiveTools is useful for limiting which tools are sent to a model in a particular step.
Import
import { filterActiveTools } from "ai"
API Signature
Parameters
tools:
ToolSet | undefined
The tool set to filter.
activeTools:
ActiveTools<TOOLS>
The names of the tools that should remain active. When omitted, all tools are returned.
Returns
The filtered tool set, or undefined when tools is undefined.
When activeTools is provided as a literal array such as ["weather"] as const,
TypeScript narrows the return type to only that subset of tools.
Types
ActiveTools
ActiveTools only accepts string keys from the tool set because tool names are strings at runtime.