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/03/18

AI Agent開発日記 2025/03/18

2025 3/21
AI_Agent Agent開発
2025年3月18日2025年3月21日
目次

この記事について

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

やりたいこと

Agent Builder を用いたデータストア参照型対話エージェントの作成において、
データストアのファイル数が増加することで回答率が低下する問題への対処を進める。

前回の調査日記

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

ToolのOpenAPIでユーザーのクエリを持たせたままfunctionにリクエストさせる方法を調査する。

  • やりたいこと
    • ToolのOpenAPIでユーザーのクエリを保持したまま関数にリクエストを送る方法を調査中に、同様の検証を行っている以下の記事を発見した。
      記事と全く同じ設定で実行するとtoolのputputが空になるため原因を調査。
  • 結果
    • 下記の記事と同じ設定でコードを実行したが、Tool の output が空で返ってきた。
    • 原因は、Cloud Run にデプロイした FastAPI アプリで warehouseId をパスの一部として受け取る API を作成し、指定された ID の倉庫の住所を返すようにしたことにあった。
    • リクエスト URL は https://url.us-central1.run.app/warehouses/1/address のような形式。
    • しかし、記事の形式をそのまま参考にしたところ、warehouseId にリクエストオブジェクト全体が入ってしまい、期待する動作をしなかった。
    • 対策として、warehouseId に格納されたリクエストオブジェクトからクエリの部分を適切に抽出し、正しく処理できるように設定しtoolを適切に動かす事に成功した

参照記事

修正前コード(記事に載っているままの状態)

#tool OpenAPIのスキーマ
openapi: 3.0.0
info:
  title: Warehouse Address API
  version: v1
servers:
  - url: 'https://my-warehouse-api-zycua53bta-uc.a.run.app'
paths:
  /warehouses/{warehouseId}/address:
    get:
      summary: Get Warehouse Address
      description: Retrieves the address of a warehouse by its ID.
      parameters:
        - in: path
          name: warehouseId
          schema:
            type: integer
            format: int64
          required: true
          description: The ID of the warehouse.
      responses:
        '200':
          description: Successful response with the warehouse address.
          content:
            application/json:
              schema:
                type: string
                description: The full address of the warehouse.
        '404':
          description: Warehouse not found.

#コード
from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route('/warehouses/<int:warehouseId>/address', methods=['GET'])
def get_warehouse_address(warehouseId):
    """
    Retrieves the address of a warehouse by its ID.
    :param warehouseId: The ID of the warehouse.
    :type warehouseId: int
    :return: The full address of the warehouse.
    :rtype: str
    """
    warehouse_data = {
        1: "123 Main Street, Anytown, CA 12345",
        2: "456 Oak Avenue, Springfield, IL 67890",
        3: "789 Pine Lane, Sunnyville, TX 54321",
        4: "1011 Maple Drive, Willow Creek, NY 98765",
        5: "1213 Cedar Road, Evergreen, CO 01234",
        6: "1415 Birch Street, Riverton, FL 76543",
        7: "1617 Elm Avenue, Mountain View, WA 23456",
        8: "1819 Oakwood Way, Lake City, OR 87654",
        9: "2021 Willow Creek Lane, Forest Hills, PA 12345",
        10: "2223 Pinewood Drive, Sunnyside, CA 98765"
    }


    if warehouseId in warehouse_data:
        return jsonify(warehouse_data[warehouseId])
    else:
        return jsonify({'error': 'Warehouse not found'}), 404

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)

修正後コード

#tool OpenAPIのスキーマ
openapi: 3.0.0
info:
  title: Warehouse Address API
  version: v1
servers:
  - url: 'https://url.us-central1.run.app'
paths:
  /warehouses/address:
    get:
      summary: Get Warehouse Address
      description: Retrieves the address of a warehouse by its ID.
      parameters:
        - in: query
          name: warehouseId
          schema:
            type: integer
            format: int64
          required: true
          description: The ID of the warehouse.
      responses:
        '200':
          description: Successful response with the warehouse address.
          content:
            application/json:
              schema:
                type: object
                properties:
                  address:
                    type: string
                    description: The full address of the warehouse.
        '404':
          description: Warehouse not found.

#コード
from fastapi import FastAPI, HTTPException
import functions_framework

app = FastAPI()

warehouse_data = {
    1: "123 Main Street, Anytown, CA 12345",
    2: "456 Oak Avenue, Springfield, IL 67890",
    3: "789 Pine Lane, Sunnyville, TX 54321",
    4: "1011 Maple Drive, Willow Creek, NY 98765",
    5: "1213 Cedar Road, Evergreen, CO 01234",
    6: "1415 Birch Street, Riverton, FL 76543",
    7: "1617 Elm Avenue, Mountain View, WA 23456",
    8: "1819 Oakwood Way, Lake City, OR 87654",
    9: "2021 Willow Creek Lane, Forest Hills, PA 12345",
    10: "2223 Pinewood Drive, Sunnyside, CA 98765"
}

@functions_framework.http
def get_warehouse_address(request):
    warehouseId = request.args.get("warehouseId")  


    if warehouseId is not None:        
        try:
          warehouseId = int(warehouseId)
          if warehouseId in warehouse_data:            
              return {"address": warehouse_data[warehouseId]}              
          else:
              raise HTTPException(status_code=404, detail="倉庫が見つかりません")
        except ValueError:
            raise HTTPException(status_code=400, detail="warehouseId must be an integer")
    else:    
       raise HTTPException(status_code=400, detail="warehouseId is required")

人気記事

  • 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)
  • 当ブログのコーディング実行環境設定 (2)
目次