Skip to content

Lab 4🧪Grounding with Bing Search

はじめに

Bingによる会話のグラウンディングは、Azure AI Agent Service によって提供される複数のツールのひとつです。Bingによるグラウンディングを使用すると、アプリは、会話に関連し、かつベクトルストアや SQL DB でエージェントに事前に提供できない情報を検索できるようになります。
例として、競合製品情報を検索したい場合などです。

本ラボでは Grounding with Bing Search サービスの作成が必要です。このサービスは、ご利用の Azure サブスクリプションでは利用できない可能性があります。
アクセス権があるか確認するには、ラボの手順にしたがってリソースを作成してください。アクセス権がない場合は、エラーメッセージが表示されます。
たとえサービスを使用できなくても、Grounding with Bing Search がどのように機能するかを理解するため、ラボ全体を必ず読んでください。

Lab Exercise

本ラボでは、Contoso の製品とカテゴリの競合売上分析を行うために、Bing Grounding を有効にします。

Grounding with Bing Search リソースを作成する

Azure ポータルで Grounding with Bing Search Service リソースを作成して、それを Azure AI Foundry ポータルに接続する必要があります。

Grounding with Bing Search Resource を作成するには、以下の手順にしたがってください。

  1. Grounding with Bing Search の作成をクリックします。

    Warning

    Azure ポータルにアクセスするには、Azure アカウントにサインインするか、またはようこそ画面を閉じる必要がある場合があります。

  2. Create をクリックします。

  3. ドロップダウンリストからリソースグループ: rg-agent-workshop を選択します。
  4. Nameは以下にします:

    groundingwithbingsearch
    
  5. Grounding with Bing Search pricing tier を選択します。

  6. I confirm I have read and understood the notice above (上記の注意事項を読み、理解したことを確認します) にチェックを入れます。
  7. Review + create をクリックします。
  8. SCreate を選択します。
  9. デプロイの完了を待機し、その後 "Go to Resource" をクリックします。
  10. サイドバーメニューから "Overview" (概要) を選択します。
  11. Go to Azure AI Foundry Portal をクリックします。

AI Foundry でBing Search Connection を作成する

に、Azure AI Foundry ポータルで Bing Search の Connection を作成します。 この Connection により、エージェントアプリはエージェント Grounding with Bing Search を使用して Bing Search サービスにアクセスできるようになります。

Azure AI Foundry ポータルで Bing Search の Connection を作成するには、以下の手順に従います。

  1. プロジェクト Agent-Service-Workshop が選択されていることを確認します。
  2. サイドバーメニューから Management Center ボタンをクリックします。このボタンはサイドバーの一番下にピン留めされています。
  3. サイドバーメニューから Connected resources を選択します。
  4. + New connection をクリックします。
  5. Knowledge セクションまでスクロールし、Grounding with Bing Search を選択します。
  6. あなたの groundingwithbingsearch リソースの右にある Add connection ボタンをクリックします。
  7. Close をクリックします。

詳細については、Grounding with Bing Search ドキュメントをご覧ください。

エージェントアプリで Grounding with Bing Search を有効にする

  1. main.py を開きます。

    1. "# " 文字を削除して、次の行のコメントを解除します。
    # INSTRUCTIONS_FILE = "instructions/bing_grounding.txt"
    
    # bing_connection = project_client.connections.get(connection_name=BING_CONNECTION_NAME)
    # bing_grounding = BingGroundingTool(bing_connection)
    # toolset.add(bing_grounding)
    

    Warning

    「#」文字を削除する際には、その直後にあるスペースも必ず削除してください。

  2. Review the code in the main.py file.

    After uncommenting, your code should look like this:

    INSTRUCTIONS_FILE = "instructions/function_calling.txt"
    INSTRUCTIONS_FILE = "instructions/file_search.txt"
    INSTRUCTIONS_FILE = "instructions/code_interpreter.txt"
    INSTRUCTIONS_FILE = "instructions/bing_grounding.txt"
    # INSTRUCTIONS_FILE = "instructions/code_interpreter_multilingual.txt"
    
    
    
    async def add_agent_tools() -> None:
        """Add tools for the agent."""
        font_file_info = None
    
        # Add the functions tool
        toolset.add(functions)
    
        # Add the code interpreter tool
        code_interpreter = CodeInterpreterTool()
        toolset.add(code_interpreter)
    
        # Add the tents data sheet to a new vector data store
        vector_store = await utilities.create_vector_store(
            project_client,
            files=[TENTS_DATA_SHEET_FILE],
            vector_store_name="Contoso Product Information Vector Store",
        )
        file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
        toolset.add(file_search_tool)
    
        # Bing grounding ツールを追加
        bing_connection = await project_client.connections.get(connection_name=BING_CONNECTION_NAME)
        bing_grounding = BingGroundingTool(connection_id=bing_connection.id)
        toolset.add(bing_grounding)
    
        # コードインタープリターに多言語サポートを追加
        # font_file_info = await utilities.upload_file(project_client, utilities.shared_files_path / FONTS_ZIP)
        # code_interpreter.add_file(file_id=font_file_info.id)
    
        return font_file_info
    

指示の確認

  1. shared/instructions/bing_grounding.txt ファイルを開きます。このファイルは、前回のラボで使用した指示を置き換えるものです。
  2. Tools & Data Access セクションに、"Competitive Insights for Products and Categories Tool" (製品およびカテゴリの競合インサイト) 機能が含まれるようになりました。これにより Agent は以下が可能になります:
    • Bing Search を使用して、競合製品名、会社名、価格を収集する。
    • 応答をアウトドアキャンプ用品およびスポーツ用品に関連するトピックに制限する。
    • 検索結果が簡潔で、クエリに直接関連していることを確実にする。

Run the Agent App

まず、以前と同様にターミナルからアプリを起動します。

  1. F5 キーをおして、Agent App を実行します。

Agent との会話を開始する

Agent は Contoso 売上データベース、テントデータシート、および Bing Search からのデータを組み合わせて包括的な応答を提供するため、結果はクエリによって異なります。

  1. 初心者向けテントはなにを販売していますか?

    Info

    この情報は主に、ベクトル情報ストアで提供したファイルから取得されます。

  2. 競合他社はどの初心者向けテントを販売していますか?価格も含めて

    Info

    この情報はインターネットから取得され、実世界の製品名と価格が含まれています。

  3. 棒グラフで表示して

    Info

    AI Agent Service は再びコードインタープリターを使用してグラフを作成しますが、今回は前のクエリで取得した実世界のデータを使用します。以前と同様に、グラフを表示するには shared/files を確認してください。

  4. 競合他社の初心者向けテントと価格が同程度の、地域別に販売している当社のテントを表示して

    Info

    このクエリは、基盤となる大規模言語モデルの推論能力と、関数呼び出しによって返されたデータに依存しています。

  5. データを人間が読める JSON ファイルとしてダウンロードして

    Info

    このクエリは再び、前のクエリのコンテキストからファイルを作成するためにコードインタープリターに依存しています。

Agentアプリの停止

  1. save と入力して Agent アプリの状態を保存します。これにより、状態を削除せずに Agent app が停止し、Azure AI Foundry の Agents プレイグラウンドで Agent を探索できるようになります。

  2. SHIFT+F5 を押して Agent app のデバッグを停止します。

  3. ターミナル出力から Agent ID をコピーします。Agent ID は、Azure AI Foundry ポータルで Agent を探索するために必要です。Agent ID は次のような形式になります:

    Agent ID: asst_pskNeFYuoCPogDnmfaqIUwoU
    

Azure AI Foundry で Agent を探索する

Azure AI Foundry には、Agentアプリと対話し、さまざまなクエリに対する応答をテストできるプレイグラウンドが含まれています。このプレイグラウンドは完全なチャットボット体験ではなく、テストツールであることに注意してください。また、Contoso 売上データベースリソースはローカルでのみ利用可能なため、リアルタイムアクセスはできません。

  1. ブラウザから Azure AI Foundry ポータル に移動します。
  2. 今回作成した AI Project で、左側のナビゲーションから Playgrounds を選択します。
  3. Try the Agents playground を選択します。
  4. 先ほどコピーしたAgent IDAgent id フィールドに貼り付けます。

Agent の指示を確認する

instructions_bing_grounding.txt ファイルからの指示であることがわかります。これらの指示は、クエリに応答する際にAgentをガイドするために使用されます。

プレイグラウンドでAgentとの会話を開始する

プレイグラウンドを使用してさまざまなクエリをテストし、Agent がどのように応答するかを観察します。ターミナルと同じクエリを再利用したり、新しいクエリを試したりできます。Agent はテントデータシートと Bing Search から情報を取得しますが、ローカルアプリのバージョンとは異なり、Contoso 売上データベースにはアクセスできないことに注意してください。

Azure AI Foundry Playground

Grounding with Bing Search


Warning

こちらはアメリカのシアトルで開催の Microsoft Build 2025 に参加している方向けのページです。

🚧通常のワークショップに参加している方は "Self-Guided Learners" のコンテンツをご利用ください。🚧


This lab requires the Grounding with Bing Search service. Follow the lab instructions to create the resource and connect it to the given Azure AI project. ,

Lab Exercise

In this lab, you'll enable Bing Grounding to provide competitive sales analysis of Contoso products and categories.

Create a Grounding with Bing Search resource

Follow these steps to create a Grounding with Bing Search Resource:

  1. Click to create a Grounding with Bing Search Resource.

    Warning

    You may need to sign in to Azure and/or clear the welcome screen to access the Azure portal. Always use the Azure credentials provided in the Resources tab of the lab instructions.

  2. Select Create.

  3. Select the rg-agent-workshop resource group from the drop-down list.
  4. Name the resource as follows:

    groundingwithbingsearch
    
  5. Select the Grounding with Bing Search pricing tier.

  6. Confirm I confirm I have read and understood the notice above.
  7. Select Review + create.
  8. Select Create.
  9. Wait for deployment to complete, then click Go to resource.
  10. Click on the resource you just created.
  11. Select Overview from the side-bar menu.
  12. Select the Go to Azure AI Foundry Portal button.

Create a Bing Search Connection in AI Foundry

Next, we will create a Bing Search connection in the Azure AI Foundry portal. This connection enables the agent app to access the Bing Search service using the agent Grounding-with-Bing-Search.

To create a Bing Search connection in the Azure AI Foundry portal, follow these steps:

  1. Verify that your hub - whose name starts with aip-ai - is selected.
  2. From the sidebar menu, click the Management Center button. The button is pinned at the bottom of the sidebar.
  3. From the side-bar menu, select Connected resources.
  4. Click + New connection.
  5. Scroll to the Knowledge section and select Grounding with Bing Search.
  6. Click the Add connection button to the right of your groundingwithbingsearch resource.
  7. Click Close
  8. Verify that the new API Key connection is listed among the connected resources (you might need to Refresh to view changes).

For more information, visit the Grounding with Bing Search documentation.

Enable Grounding with Bing Search in the Agent App

  1. Open the file main.py.

  2. Uncomment the following lines by removing the "# " characters

    # INSTRUCTIONS_FILE = "instructions/bing_grounding.txt"
    
    # bing_connection = project_client.connections.get(connection_name=BING_CONNECTION_NAME)
    # bing_grounding = BingGroundingTool(bing_connection)
    # toolset.add(bing_grounding)
    

    Warning

    The lines to be uncommented are not adjacent. When removing the # character, ensure you also delete the space that follows it.

  3. Review the code in the main.py file.

    After uncommenting, your code should look like this:

    INSTRUCTIONS_FILE = "instructions/function_calling.txt"
    INSTRUCTIONS_FILE = "instructions/file_search.txt"
    INSTRUCTIONS_FILE = "instructions/code_interpreter.txt"
    INSTRUCTIONS_FILE = "instructions/bing_grounding.txt"
    # INSTRUCTIONS_FILE = "instructions/code_interpreter_multilingual.txt"
    
    
    async def add_agent_tools() -> None:
        """Add tools for the agent."""
        font_file_info = None
    
        # Add the functions tool
        toolset.add(functions)
    
        # Add the code interpreter tool
        code_interpreter = CodeInterpreterTool()
        toolset.add(code_interpreter)
    
        # Add the tents data sheet to a new vector data store
        vector_store = await utilities.create_vector_store(
            project_client,
            files=[TENTS_DATA_SHEET_FILE],
            vector_store_name="Contoso Product Information Vector Store",
        )
        file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
        toolset.add(file_search_tool)
    
        # Add multilingual support to the code interpreter
        # font_file_info = await utilities.upload_file(project_client, utilities.shared_files_path / FONTS_ZIP)
        # code_interpreter.add_file(file_id=font_file_info.id)
    
        # Add the Bing grounding tool
        bing_connection = await project_client.connections.get(connection_name=BING_CONNECTION_NAME)
        bing_grounding = BingGroundingTool(connection_id=bing_connection.id)
        toolset.add(bing_grounding)
    
        return font_file_info
    

Review the Instructions

  1. Open the shared/instructions/bing_grounding.txt file. This file replaces the instructions used in the previous lab.
  2. The Tools section now includes a “Competitive Insights for Products and Categories” capability, enabling the agent to:

    • Use Bing Search to gather competitor product names, company names, and prices.
    • Restrict responses to topics related to outdoor camping and sports gear.
    • Ensure search results are concise and directly relevant to the query.

Run the Agent App

First, launch the app from the terminal as before:

  1. Press F5 to run the app.

Start a Conversation with the Agent

The agent combines data from the Contoso sales database, the Tents Data Sheet, and Bing Search to provide comprehensive responses, so the results will vary depending on the query.

  1. What beginner tents do we sell?

    Info

    This information mainly comes from the file we provided in the vector information store.

  2. What beginner tents do our competitors sell? Include prices.

    Info

    This information comes from the internet, and includes real-world product names and prices.

  3. Show as a bar chart

    Info

    AI Agent Service is again using Code Interpreter to create the chart, but this time with real-world data sourced in the previous query. As before, look in shared/files to view the chart.

  4. Show the tents we sell by region that are a similar price to our competitors beginner tents.

    Info

    This query relies on the reasoning capabilities of the underlying large language model, along with the data returned by function calling.

  5. Download the data as a human-readable JSON file

    Info

    This query again relies on Code Interpreter to create the file from the context in the previous queries.

Stop the Agent App

  1. Type save to save the agent app state. This stops the agent app without deleting its state, allowing you to explore the agent in the Azure AI Foundry’s Agents playground.
  2. Press Shift+F5 to stop debugging the agent app.
  3. Copy the Agent ID from the terminal output. The Agent ID is required to explore the agent in the Azure AI Foundry portal. The Agent ID will look similar to this example:

    Agent ID: asst_pskNeFYuoCPogDnmfaqIUwoU
    

Explore the Agent in Azure AI Foundry

The Azure AI Foundry includes a playground that lets you interact with the agent app and test how it responds to various queries. Keep in mind that this playground is not a full chatbot experience—it’s a testing tool. Also, you won’t have real-time access to the Contoso sales database, as that resource is available only locally.

  1. From your browser, navigate to the Azure AI Foundry portal.
  2. Select Playgrounds from the left-hand navigation.
  3. Select Try the Agents playground.
  4. Select the recommended Azure OpenAI Service resource from the dropdown menu - which is the one connected to your project. Click on Let's go.
  5. Verify that the Agent ID you copied earlier is the same you see into the Agent id field.

Review the Agent's Instructions

You'll recognize the instructions from the instructions_bing_grounding.txt file. These instructions are used to guide the agent in responding to queries.

Start a Conversation with the Agent in the Playground

Use the playground to test different queries and observe how the agent responds. You can reuse the same queries from the terminal or try new ones. Keep in mind that the agent pulls information from the Tents Data Sheet and Bing Search, but unlike the local app version, it does not have access to the Contoso sales database.

Azure AI Foundry Playground