> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Perplexity tools `@mastra/perplexity` パッケージは、[Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart) をMastra互換のToolとしてラップします。このパッケージは、[`createTool()`](https://mastra.zisheng.pro/ja/reference/tools/create-tool) で作成されたToolと完全なZod入出力スキーマを返すファクトリ関数を公開します。 Perplexityを利用したチャット補完やエージェント型Workflowには、Mastra組み込みの[PerplexityモデルProvider](https://mastra.zisheng.pro/ja/models/providers/perplexity)または[Perplexity Agent Provider](https://mastra.zisheng.pro/ja/models/providers/perplexity-agent)を使用してください。これらは、このSearch Toolとは別のものです。 ## インストール Zodと一緒にパッケージをインストールします。 **npm**: ```sh npm install @mastra/perplexity zod ``` **pnpm**: ```sh pnpm add @mastra/perplexity zod ``` **Yarn**: ```sh yarn add @mastra/perplexity zod ``` **Bun**: ```sh bun add @mastra/perplexity zod ``` ## 使用例 次の例では、デフォルト設定でSearch Toolを作成します。デフォルトでは、Toolは環境から `PERPLEXITY_API_KEY`(フォールバックとして `PPLX_API_KEY`)を読み取ります。上書きするには `{ apiKey }` を明示的に渡します。 ```typescript import { createPerplexitySearchTool } from '@mastra/perplexity' const searchTool = createPerplexitySearchTool() ``` APIキーを明示的に渡すには、次のようにします。 ```typescript import { createPerplexitySearchTool } from '@mastra/perplexity' const searchTool = createPerplexitySearchTool({ apiKey: 'pplx-...' }) ``` ## 設定 すべてのファクトリ関数は `PerplexityClientOptions` オブジェクトを受け取ります。 **apiKey** (`string`): Perplexity APIキー。PERPLEXITY\_API\_KEY、次にPPLX\_API\_KEY環境変数へフォールバックします。 **baseUrl** (`string`): APIのベースURLを上書きします。 (Default: `'https://api.perplexity.ai'`) **fetch** (`typeof fetch`): カスタムfetch実装。テスト、再試行、計測に役立ちます。 ## メソッド ### ファクトリ関数 #### `createPerplexityTools(config?)` 指定された設定を共有するすべてのPerplexity Toolを含むオブジェクトを返します。 ```typescript import { createPerplexityTools } from '@mastra/perplexity' const tools = createPerplexityTools({ apiKey: 'pplx-...' }) // tools.perplexitySearch ``` 戻り値: `{ perplexitySearch }` #### `createPerplexitySearchTool(config?)` Perplexity Search APIを使用してWebを検索するToolを作成します。タイトル、URL、スニペット、および任意の公開日を含む、順位付けされた結果を返します。 ToolはID `perplexity-search` で登録されます。 ```typescript import { createPerplexitySearchTool } from '@mastra/perplexity' const searchTool = createPerplexitySearchTool() ``` ##### 入力 **query** (`string`): 検索クエリ。 **maxResults** (`number`): 返す結果の最大数(1〜20)。 **searchDomainFilter** (`string[]`): ドメインによって結果を限定(または除外)します。除外するにはドメインの先頭に-を付けます(例: -pinterest.com)。同じ呼び出しで許可リストと拒否リストのエントリを混在させないでください。 **searchRecencyFilter** (`'hour' | 'day' | 'week' | 'month' | 'year'`): 指定した直近期間内の結果のみを返します。 **searchAfterDateFilter** (`string`): この日付以降に公開された結果のみを返します。形式: m/d/yyyy。 **searchBeforeDateFilter** (`string`): この日付以前に公開された結果のみを返します。形式: m/d/yyyy。 ##### 出力 **query** (`string`): 元の検索クエリ。 **results** (`SearchResult[]`): 検索結果の配列。 **results.title** (`string`): 結果のタイトル。 **results.url** (`string`): 結果のURL。 **results.snippet** (`string`): 内容のスニペット。 **results.date** (`string`): 取得できる場合は公開日。 ## Agentの例 次の例では、回答前に最新のWeb検索結果を取得できるよう、Search ToolをAgentに登録します。 ```typescript import { Agent } from '@mastra/core/agent' import { createPerplexitySearchTool } from '@mastra/perplexity' const agent = new Agent({ id: 'research-agent', name: 'Research Agent', model: 'anthropic/claude-sonnet-4-6', instructions: 'You are a research assistant. Use the perplexity-search tool to find up-to-date information from the web before answering.', tools: { search: createPerplexitySearchTool(), }, }) ``` ## 環境変数 | 変数 | 説明 | | -------------------- | -------------------------------------------------------- | | `PERPLEXITY_API_KEY` | Perplexity APIキー。ファクトリ関数に`apiKey`を渡さない場合のデフォルトとして使用されます。 | | `PPLX_API_KEY` | `PERPLEXITY_API_KEY`が設定されていない場合に使用されるフォールバック。 | ## 関連情報 - [`createTool()`](https://mastra.zisheng.pro/ja/reference/tools/create-tool) - [Perplexity Searchクイックスタート](https://docs.perplexity.ai/docs/search/quickstart) - [Perplexity Agentクイックスタート](https://docs.perplexity.ai/docs/agent/quickstart) - [PerplexityモデルProvider](https://mastra.zisheng.pro/ja/models/providers/perplexity) - [Perplexity Agent Provider](https://mastra.zisheng.pro/ja/models/providers/perplexity-agent)