MENU
  • HOME
  • 取引実績
  • 会社概要
  • 資料DL
  • お問い合わせ
  • FAQ
  • BigQuery記事
  • Struccle記事
データ流通、検索エンジン開発のプロフェッショナル
DataStructor
  • HOME
  • 取引実績
  • 会社概要
  • 資料DL
  • お問い合わせ
  • FAQ
  • BigQuery記事
  • Struccle記事
DataStructor
  • HOME
  • 取引実績
  • 会社概要
  • 資料DL
  • お問い合わせ
  • FAQ
  • BigQuery記事
  • Struccle記事
  1. ホーム
  2. AI_Agent
  3. Agent開発
  4. AI Agent開発日記 2025/05/08

AI Agent開発日記 2025/05/08

2025 5/08
AI_Agent Agent開発
2025年5月8日
目次

この記事について

本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。

やりたいこと

Agent Builder を用いたデータストア参照型対話エージェントの作成において、
既存のデータストア機能だとデータ数増加により回答率の低下が発生する為、elastic + dataflow + bigqueryで作成した検索が可能なデータストアを実装したい。

前回の調査日記

あわせて読みたい
AI Agent開発日記 2025/05/07 この記事について 本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。 やりたいこと Agent Builder を用いたデータス...

今まで作成してきたplaybookやtool設定を元にそれらの設定をAIを駆使して自動生成できないか検証したい

  • やりたいこと
    • 毎回データに合わせてPlaybookやToolのスキーマ設定を作成するのが手間なので、自分用にWebのGeminiに入力して使えるプロンプトを作成したい
  • 現状
    • 下記プロンプトを使うことによってgemini2.0flash環境でデータ型に合わせたelastic検索をする用のtoolのopenapiスキーマの自動生成が可能になった。

プロンプト

**【プロンプト本文】**

あなたはOpenAPIスキーマを生成する専門家です。
以下に、Elasticsearch検索ToolとしてAgent Builderで使用するためのOpenAPI 3.0スキーマのテンプレートと、新しいインデックスの情報(インデックス名とドキュメントのJSONデータ例)を提供します。提供された情報に基づいて、テンプレートスキーマの**特定の部分**を修正・拡張し、新しいインデックスに対応した完全なOpenAPIスキーマ(**JSON標準に完全に準拠し、コメントを一切含まない形式**)を生成してください。

**生成対象:**
Elasticsearchの特定インデックスに対する `_search` API (POSTメソッド) を呼び出すためのOpenAPI 3.0スキーマ。

**生成ルール:**

1.  **テンプレートスキーマ全体を使用します。** 生成されるJSON出力には、JSON標準で許可されていないいかなる形式のコメント(`//`, `/* ... */` など)も**一切含めないでください**。
2.  以下のプレースホルダー部分を、提供する「新しいElasticsearchインデックス名」で置き換えてください。
    *   `paths: /新しいインデックス名/_search` の `新しいインデックス名` 部分
    *   `operationId: search[新しいインデックス名PascalCase]Post` の `新しいインデックス名PascalCase` 部分(例: `my_data_index` -> `MyDataIndex`)。インデックス名がPascalCaseに変換できない文字を含む場合は、適切な識別子に変換してください。
    *   `description` 内でインデックス名に言及している箇所(あれば)
3.  最も重要かつ変更が大きい箇所は、**`responses.'200'.content.'application/json'.schema.properties.hits.properties.hits.items.properties._source.properties`** の内容です。
    *   この `_source.properties` の中身を、提供する「新しいインデックスのドキュメントJSONデータ例」を解析して生成してください。
    *   JSONデータ例に含まれる各ドキュメントのフィールド名とその値のデータ型を推測し、それらを元にOpenAPIスキーマの `properties` を定義します。
    *   **JSONデータ型の推測ルール:**
        *   JSONの文字列 (`"..."`) -> `type: string`
        *   JSONの整数 (`123`) -> `type: integer`
        *   JSONの浮動小数点数 (`123.45`) -> `type: number`
        *   JSONの真偽値 (`true`, `false`) -> `type: boolean`
        *   JSONのオブジェクト (`{...}`) -> `type: object` (その中のフィールドも再帰的に推測して `properties` に定義)
        *   JSONの配列 (`[...]`) -> `type: array` (配列の要素の型を推測し `items` に定義。要素の型が混在する場合は、可能な限り最も一般的な型または `{}` (任意の型) を `items` に使用してください。)
        *   JSONのnull (`null`) -> そのフィールドが存在する場合、スキーマに `nullable: true` を含めることを検討してください(必須ではありません)。
    *   JSON例からフィールドの必須(`required`)や説明(`description`)は判断できないため、`required`リストや各プロパティの`description`は含めなくて構いません。プロパティ名と `type` の定義のみでOKです。
4.  上記以外のテンプレートスキーマの箇所(`info`, `servers`, `requestBody`, `components`, `security` など)は、**一切変更しないでください**。テンプレートの内容をそのまま維持してください。
5.  出力は**JSON形式**で、コードブロックで囲んでください。生成されるJSON文字列全体に、JSON標準で許可されていないコメントを**絶対に含めないでください**。

**提供情報:**

---

**Elasticsearchインデックス名:**

```
ここにインデックス名を記入(例: my_data_index)
```

---

**新しいインデックスのドキュメントJSONデータ例 (JSON配列形式):**

```json
[
ここに、そのインデックスに格納されている実際のドキュメントのJSON例をいくつか貼り付けてください
理想的には、異なる構造を持つ可能性のあるドキュメントを複数含めると、より正確なスキーマが生成できます。
提供された例をそのまま貼り付けてもOKです。
]
```

---

**ベースとなるOpenAPIスキーマテンプレート:**

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Elasticsearch Search API",
    "version": "v1",
    "description": "API to search documents in a specific Elasticsearch index via POST."
  },
  "servers": [
    {
      "url": "https://your-elasticsearch-endpoint:443"
    }
  ],
  "paths": {
    "/インデックス名/_search": {
      "post": {
        "summary": "Search documents in Elasticsearch using POST",
        "description": "Executes a search query against the '新しいインデックス名' index using POST request with query in the body. Requires ApiKey authentication via Header.",
        "operationId": "search新しいインデックス名PascalCasePost",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "object",
                    "description": "Query in Elasticsearch Query DSL format. Example - {\"match_all\":{}}",
                    "nullable": true
                  },
                  "size": {
                    "type": "integer",
                    "description": "Number of hits to return.",
                    "default": 10
                  },
                   "from": {
                    "type": "integer",
                    "description": "Starting document offset for pagination.",
                    "default": 0
                  },
                  "_source": {
                    "description": "Controls what fields are returned in _source. Set to true to return all, false to return none, or an array of specific field names.",
                    "oneOf": [
                      { "type": "boolean" },
                      { "type": "array", "items": { "type": "string" } }
                    ],
                    "nullable": true
                  },
                  "sort": {
                    "description": "Sort order for search results.",
                     "oneOf": [
                       { "type": "string" },
                       { "type": "array", "items": { "oneOf": [{ "type": "string" }, { "type": "object" }] } },
                       { "type": "object" }
                    ],
                    "nullable": true
                  }
                },
                "required": [
                  "query"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response with search results.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "took": { "type": "integer" },
                    "timed_out": { "type": "boolean" },
                    "_shards": {
                      "type": "object",
                      "properties": {
                        "total": { "type": "integer" },
                        "successful": { "type": "integer" },
                        "skipped": { "type": "integer" },
                        "failed": { "type": "integer" }
                      },
                       "additionalProperties": true
                    },
                    "hits": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "object",
                          "properties": {
                            "value": { "type": "integer" },
                            "relation": { "type": "string" }
                          },
                          "additionalProperties": true
                        },
                        "max_score": { "type": "number", "nullable": true },
                        "hits": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "_index": { "type": "string" },
                              "_id": { "type": "string" },
                              "_score": { "type": "number", "nullable": true },
                              "_source": {
                                "type": "object",
                                "properties": {
                                  // ↓↓↓ --- ここが提供されたJSONデータ例に基づいて生成されます --- ↓↓↓
                                  // ↑↑↑ --- ここが提供されたJSONデータ例に基づいて生成されます --- ↑↑↑
                                },
                                "additionalProperties": true
                              },
                                "fields": {
                                    "type": "object",
                                    "additionalProperties": {
                                        "oneOf": [
                                            { "type": "string" },
                                            { "type": "integer" },
                                            { "type": "number" },
                                            { "type": "boolean" },
                                            { "type": "array", "items": {} },
                                            { "type": "object" }
                                        ]
                                    },
                                    "nullable": true
                                }
                            },
                            "additionalProperties": true
                          }
                        }
                      },
                      "additionalProperties": true
                    },
                    "aggregations": {
                        "type": "object",
                        "additionalProperties": true,
                        "nullable": true
                    },
                    "suggest": {
                         "type": "object",
                         "additionalProperties": true,
                         "nullable": true
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Bad Request. Invalid request body or query syntax.",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          },
          "401": {
            "description": "Unauthorized. Invalid API Key or authentication setup."
          },
           "403": {
            "description": "Forbidden. API Key lacks necessary permissions."
          },
          "404": {
            "description": "Not Found. The specified index or resource was not found."
          },
          "500": {
            "description": "Internal Server Error. Elasticsearch error.",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Elasticsearch API Key authentication. Value should be 'ApiKey YOUR_BASE64_ENCODED_ID:API_KEY'. Provide this full value in Agent Builder auth settings."
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ]
}
```

人気記事

  • BigQueryの無料枠を活用しよう!制限と注意点、活用方法を解説
  • BigQueryでエラー解決!よくあるエラーと対処法
  • BigQueryのレベル別学習リソースまとめ!初心者から上級者まで役立つ情報源
  • 【SUUMOスクレイピング】Struccleで物件データを全件収集
  • BigQuery入門!無料データでSQLの基本文字列関数をマスター
AI_Agent Agent開発
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次
カテゴリー
  • AI_Agent (110)
    • Agent開発 (110)
  • BigQuery (100)
    • BigQueryTips (11)
    • BigQueryでデータ分析 (49)
    • BigQueryのFAQ (1)
    • BigQuery入門 (8)
    • BigQuery学習教材 (22)
    • BigQuery導入ガイド (3)
    • BigQuery最新情報 (3)
    • BigQuery活用事例 (4)
  • Struccle (153)
    • Struccleでスクレイピング (10)
      • suumoの物件データを収集&分析 (1)
      • アニマルジョブの電話番号、メールアドレスを全件収集 (1)
      • データ集計 (6)
      • ホットペッパービューティーのヘアサロンデータを収集&分析 (1)
      • 食べログの飲食店データを収集&分析 (1)
    • Struccleデータ料金事例 (142)
      • 商品分析 (15)
      • 営業リスト (88)
      • 競合分析&市場調査 (58)
      • 自動車 (11)
      • 自社活用 (7)
    • Struccle活用企業様の紹介 (1)
  • 当ブログのコーディング実行環境設定 (1)
目次