目次
この記事について
本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。
やりたいこと
Agent Builder を用いたデータストア参照型対話エージェントの作成において、
既存のデータストア機能だとデータ数増加により回答率の低下が発生する為、elastic + dataflow + bigqueryで作成した検索が可能なデータストアを実装したい。
前回の調査日記
あわせて読みたい


AI Agent開発日記 2025/04/30
この記事について 本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。 やりたいこと Agent Builder を用いたデータス...
agentbuilderのデータストアtoolとしてElastic Cloudで検索できるよう設定する。
- やりたいこと
- Agent Builderで作成した「Tool」を使って、指定したElasticsearchクラスターにあるfamous-songインデックスのデータを検索できるようにしたい。
- 認証方式は「API キー」を使いたい。
- 試したこと
- Python(Jupyter)での検証
- 指定したElasticsearchのURLとAPI キーを使って、pythonを使ってjupyterでfamous-song インデックスの検索 (GET /_search を使用) が成功することを確認してURLとAPI キー自体は有効という事が分かった。
- openAPIスキーマ作成
- Pythonでの検証結果に基づき、Agent Builder用のOpenAPIスキーマを作成した。
- スキーマには、APIキー認証(Authorization ヘッダー)が必要であることも記述(components と security セクションを追加)
- Agent Builderへの設定
- 作成したOpenAPIスキーマをAgent BuilderのTool設定に貼り付けた
- Toolの認証設定で、APIキー情報を入力した (プレフィックス ApiKey を付ける/付けない、両方のパターンを試した)。
- Agent Builder でのテスト
- toolの「Test tool」機能を使って、設定したToolの動作確認を試みた
- Python(Jupyter)での検証
- 現状
- 進展
- 「Test tool」画面で、実行するActionとして、OpenAPI スキーマで定義した正しいGET操作 (searchElasticsearchGet)を選択できるようになった
- 現在の課題
- 依然としてテスト実行時に 401 認証エラー が発生しているように見える(または、テスト実行に必要な設定が不完全)。
- 「Test tool」画面の Tool Input (パラメータ入力) の設定が適切でない。
- 正しい Action (GET) が選択されているにも関わらず、その Action が必要とする検索パラメータ (index や source など) が入力されておらず、代わりに不要な requestBody が選択されている状態。
- 根本的な問題
- 401エラーは認証が通っていないことを示すが、Agent Builderが正しいパラメータで完全なリクエストを組み立てて送信しない限り、設定した API キー認証が実際に試される段階に至らない可能性がある。
- 進展
- 次のステップ
- 「Test tool」画面で正しいパラメータを入力し、完全なリクエストを送信できるようにする
現在のスキーマ
openapi: 3.0.0
info:
title: Elasticsearch Search API (via GET)
version: v1
servers:
- url: 'エンドポイントurl'
paths:
/_search:
get:
summary: Search documents in Elasticsearch using GET
description: Executes a search query against an Elasticsearch index using GET request. Requires ApiKey authentication via Header.
operationId: searchElasticsearchGet # Agent Builder がオペレーションを識別するためのID
parameters:
- in: query
name: index
schema:
type: string
required: true
description: The name of the Elasticsearch index to search. Example - famous-song
- in: query
name: q
schema:
type: string
required: false
description: Query in Lucene query string syntax. Example - artist:Queen
- in: query
name: source
schema:
type: string
required: false
description: Query in Query DSL format (JSON String, URL-encoded). Example - {"query":{"match_all":{}}}
- in: query
name: source_content_type
schema:
type: string
enum: ["application/json"]
default: "application/json"
required: false
description: Content type of the 'source' parameter. Must be 'application/json'.
- in: query
name: size
schema:
type: integer
default: 10
required: false
description: Number of hits to return.
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
hits:
type: object
properties:
total:
type: object
max_score:
type: number
hits:
type: array
items:
type: object
'400':
description: Bad Request. Invalid query parameters or syntax.
'401':
description: Unauthorized. Invalid API Key or authentication setup.
'404':
description: Not Found. Index not found.
'500':
description: Internal Server Error. Elasticsearch error.
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: Authorization # 使用するヘッダー名 (Elasticsearch の ApiKey 認証はこれ)
description: "Elasticsearch API Key authentication. The value should be the complete string 'ApiKey YOUR_BASE64_ENCODED_ID:API_KEY'. Provide this full value in the Agent Builder authentication settings."
security:
- ApiKeyAuth: [] # この securitySchemes (ApiKeyAuth) を API 全体で有効にする