跳至主要內容

Mastra.getTool()

.getTool() 方法按註冊鍵從 Mastra 層級的登錄中擷取 Tool。

使用範例
使用範例 的直接連結

weather 鍵註冊 Tool,然後使用該鍵擷取它。

src/mastra/index.ts
import { Mastra } from '@mastra/core/mastra'
import { weatherTool } from './tools/weather-tool'

export const mastra = new Mastra({
tools: {
weather: weatherTool,
},
})

const tool = mastra.getTool('weather')

參數
參數 的直接連結

name:

TToolName extends keyof TTools
Tool 在 Mastra tools 登錄中的註冊鍵。