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


AI Agent開発日記 2025/05/03
この記事について 本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。 やりたいこと Agent Builder を用いたデータス...
agentbuilderのデータストアtoolとしてElastic Cloudで検索できるよう設定する。
- やりたいこと
- 対話型での検証を行っていなかったため、Tool Description や playbook を整備し、チャット経由でも正常に検索できるか確認したい。
- 現状
- playbookに下記のような設定をし、対話型でのelastic検索に成功した。
playbook設定
*goalの設定
toolを使ってユーザーからのクエリを元にElasticで検索をし、出力フォーマットに沿った形式で検索結果を返します。
*instructionsの設定
- フィールド指定検索(インデックス[famous-song] + フィールド名:キーワード)
- - 形式: 「[famous-song] インデックスで [フィールド名]:[検索キーワード] を検索して」
- - 処理: 指定フィールドを `${TOOL:有名な曲検索}` で検索し、結果を楽曲情報として整形して表示する。
- 出力フォーマット
- - 「[famous-song] インデックスで [検索条件] を検索した結果、[件数] 件の曲が見つかりました。
- - - ID: [_id]
- - - 曲名: [famous_song]
- - - 作曲家名: [name]
- - - 他に条件があれば教えてください。」
- インデックス全体の検索
- - 形式: 「[famous-song] インデックス全体を検索して」
- - 処理: インデックス内のすべての楽曲データを `${TOOL:有名な曲検索}` で検索し、上位の曲を抜粋して表示する。
- - 出力フォーマット
- - - 「[famous-song] インデックス全体を検索した結果、[件数] 件の曲が見つかりました。
- - - 上位10件を表示:
- - - - ID: [_id]
- - - - 曲名: [famous_song]
- - - - 作曲家名: [name]
- - - 全件表示が必要な場合は、お知らせください。」
- 検索エラーが発生した場合
- - 形式: 「Elasticsearch でエラーが発生した場合」
- - 処理: エラー内容を解析し、ユーザーにとってわかりやすい形で解決策を提示する。
- - 出力フォーマット:
- - - 「検索中にエラーが発生しました。[エラー内容]」
- - - 「もう一度検索するか、内容をご確認ください。それでも解決しない場合は、管理者にご連絡ください。」
- Elasticsearchツールの指定が必要な場合
- - 形式: 「明確な検索指示がない、または検索フォーマットが不適切な場合」
- - 処理: 適切な検索例を提示して、ユーザーに再入力を促す。
- - 出力フォーマット:
- - - 「検索の指定方法が不明確です。次のように入力してください:
- - - `famous-song` インデックスで `name:モーツァルト` を検索して
- - - `famous-song` インデックスで `famous_song:交響曲` を検索して
- - - もう一度ご入力をお願いします。」
toolのスキーマ設定
openapi: 3.0.0
info:
title: Elasticsearch Search API
version: v1
servers:
- url: 'elasticのデプロイurl'
paths:
/famous-song/_search:
post:
summary: Search documents in Elasticsearch using POST
description: Executes a search query against the 'famous-song' index using POST request with query in the body. Requires ApiKey authentication via Header.
operationId: searchFamousSongsPost
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
query:
type: object
description: Query in Elasticsearch Query DSL format. Example - {"match_all":{}}
size:
type: integer
description: Number of hits to return.
default: 10
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
hits:
type: object
properties:
total:
type: object
max_score:
type: number
hits:
type: array
items:
type: object
properties:
_index:
type: string
_id:
type: string
_score:
type: number
_source:
type: object
properties:
famous_song:
type: string
name:
type: string
id:
type: string
required:
- famous_song
- name
- id
'400':
description: Bad Request. Invalid request body or query syntax.
'401':
description: Unauthorized. Invalid API Key or authentication setup.
'404':
description: Not Found. Index 'famous-song' not found.
'500':
description: Internal Server Error. Elasticsearch error.
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: []