`filterActiveTools()`
filterActiveTools()
filterActiveTools 는 실험적 기능이에요.
filterActiveTools 는 tool 세트를 activeTools 에 나열된 문자열 tool 이름만 남도록 필터링해요. activeTools 가 undefined 면 원래 tool 세트를 반환해요. tools 가 undefined 면 undefined 를 반환해요.
filterActiveTools 는 특정 단계에서 모델에 보내는 tools를 제한하는 데 유용해요.
import { experimental_filterActiveTools as filterActiveTools, tool } from 'ai';
import { z } from 'zod';
const tools = {
weather: tool({
description: 'Get the weather for a city',
inputSchema: z.object({ city: z.string() }),
}),
time: tool({
description: 'Get the current time for a city',
inputSchema: z.object({ city: z.string() }),
}),
};
const activeTools = ['weather'] as const;
const filteredTools = filterActiveTools({
tools,
activeTools,
});
출처: 문서
본문
Import
<Snippet
text={import { experimental_filterActiveTools as filterActiveTools } from "ai"}
prompt={false}
/>
API 시그니처
매개변수 (Parameters)
<PropertiesTable
content={[
{
name: 'tools',
type: 'ToolSet | undefined',
description: 'The tool set to filter.',
},
{
name: 'activeTools',
type: 'ActiveTools
반환값 (Returns)
필터링된 tool 세트, 또는 tools 가 undefined 면 undefined.
activeTools 가 ["weather"] as const 같은 리터럴 배열로 제공되면 TypeScript는 반환 타입을 그 tool 하위 집합으로 좁혀요.
타입 (Types)
ActiveTools
type ActiveTools<TOOLS extends ToolSet> =
| ReadonlyArray<keyof TOOLS & string>
| undefined;
ActiveTools 는 tool 이름이 런타임에서 문자열이므로 tool 세트의 문자열 키만 받아요.
더 알아보기 (Learn more)
- generateText
- streamText
- embed
- embedMany
- rerank
- generateImage
- experimental_streamTranscribe
- experimental_streamTranslate
- transcribe
- generateSpeech
- experimental_generateVideo
- experimental_evaluate
- uploadFile
- uploadSkill
- Agent (Interface)
- ToolLoopAgent
- createAgentUIStream
- createAgentUIStreamResponse
- pipeAgentUIStreamToResponse
- experimental_startBatch
- tool
- experimental_getBatchStatus
- dynamicTool
- experimental_getBatchResults
- experimental_cancelBatch
- createMCPClient
- experimental_getRealtimeToolDefinitions
- toolSearch
- experimental_listBatches
- MCP Apps
- Experimental_StdioMCPTransport
- jsonSchema
- zodSchema
- valibotSchema
- Output
- filterActiveTools
- ModelMessage
- UIMessage
- validateUIMessages
- safeValidateUIMessages
- Experimental_SandboxSession
- createProviderRegistry
- customProvider
- cosineSimilarity
- wrapLanguageModel
- wrapImageModel
- LanguageModelV4Middleware
- extractReasoningMiddleware
- simulateStreamingMiddleware
- defaultInstructionsMiddleware
- defaultSettingsMiddleware
- addToolInputExamplesMiddleware
- extractJsonMiddleware
- isStepCount
- hasToolCall
- isLoopFinished
- simulateReadableStream
- smoothStream
- generateId
- createIdGenerator
- DefaultGeneratedFile