2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure AI Foundry のエージェントから Azure Logic Apps をツールとして呼び出す

Last updated at Posted at 2025-05-26

はじめに

本記事では、Azure AI Foundry のエージェントから Azure Logic Apps をツールとして呼び出す、最小構成のサンプルを解説します。
主に 「get-newsapi-org-data」 という Logic App をエージェントに登録し、ニュースデータを取得する流れを説明します。

補足
ニュースデータを Blob Storage に定期的に格納する別途の Logic App(例:fetch-data-from-data)は付録として後述します。

全体の構成

黄色で示した部分が記事のメインのトピックです。

image.png

前提条件

  1. ニュースデータが Blob Storage に保存されていること
  2. Azure AI Foundry にエージェントが定義済みであること

ブログコンテナーにBlobが保存されている状態。
image.png

"Agent856" という名前のエージェントが"MyFirstAiProject" というAzure AI Foundry プロジェクトに定義されています。
image.png

1. Logic Apps コネクション設定

カスタムキー接続 を Connected resources に登録します。概念図の (f) に相当します。

  1. Azure AI Foundry ポータルで Hub(または Project) の「Connected resources」画面を開きます。
    image.png

  2. Hub に登録すると、他プロジェクトでも同じ接続情報を使い回せます。

  3. 「+ New connection」から Custom keys を選択します。
    image.png

  4. 任意の名前を付けます(例:LogicApps_Tool_Connection_getnewsapiorgdata)。

  5. Key namesigValue に Logic App のトリガー URL 内の sig クエリ文字列を貼り付けて保存します。

    • Logic App 側:「When a HTTP request is received」アクションの URL に ?sig=xxxx が含まれていますので、この値をコピーします。

image.png

image.png


2. エージェントに OpenAPI 3.0 接続(Action)を登録

概念図での (g) を (h) に登録する部分を設定します

  1. Azure AI Foundry ポータルで対象エージェントを開き、「Add Action」を選択。
    image.png

  2. Tool typeOpenAPI3.0 specification tool を選び、

    • Name:任意(例:GetNewsApiOrgData
    • Description:エージェントに表示される説明文
      を入力します。

image.png

image.png

  1. Authentication method に先ほど作成した カスタムキー接続 を指定します。
    image.png

  2. OpenAPI 3.0 スキーマを定義
    image.png

以下のような最小サンプルをベースに、実際の Logic App の構成に合わせて調整してください。

{
  "openapi": "3.0.3",
  "info": {
    "version": "1.0.0.0",
    "title": "Get NewAPI data from storage",
    "description": "Get NewAPI data from storage"
  },
  "servers": [
    {
      "url": "https://prod-123.westus.logic.azure.com:443/workflows/aaaaaaaa0a544cf482e1570cf516d19b/triggers/When_a_HTTP_request_is_received/paths"
    }
  ],
  "security": [
    {
      "sig": []
    }
  ],
  "paths": {
    "/invoke": {
      "post": {
        "description": "Get NewAPI data from storage",
        "operationId": "When_a_HTTP_request_is_received-invoke",
        "parameters": [
          {
            "name": "api-version",
            "in": "query",
            "description": "`2016-10-01` is the most common generally available version",
            "required": true,
            "schema": {
              "type": "string",
              "default": "2016-10-01"
            },
            "example": "2016-10-01"
          },
          {
            "name": "sv",
            "in": "query",
            "description": "The version number",
            "required": true,
            "schema": {
              "type": "string",
              "default": "1.0"
            },
            "example": "1.0"
          },
          {
            "name": "sp",
            "in": "query",
            "description": "The permissions",
            "required": true,
            "schema": {
              "type": "string",
              "default": "%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun"
            },
            "example": "%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun"
          }
        ],
        "responses": {
          "200": {
            "description": "The Logic App Response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "The Logic App Response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "deprecated": false,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "location": {
                    "description": "Location for the news",
                    "type": "string",
                    "default": "none"
                  }
                }
              }
            }
          },
          "required": true
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sig": {
        "type": "apiKey",
        "description": "The SHA 256 hash of the entire request URI with an internal key.",
        "name": "sig",
        "in": "query"
      }
    }
  }
}

注目する点

  • serversurl はロジックアップのHTTPトリガーのエンドポイントなのでロジックアップからコピーします。
  • securitysig を使うことを定義しています。この値はカスタムキー接続に指定したものが実際には送信されます。
  • requestBody は Logic App 側の「Request BODY JSON Schema」に合わせて調整可能(例では location のみ)。例えばエージェント側からブロブ名などを指定できます。
  • default プロパティが指定してある要素はエージェント側から渡す必要はない(定数として理解してかまわない)。

3. Agent Playground で動作確認

概念図のエージェント (h) に対しての要求が、アクション(g)に委任され、Logic Apps (e) がストレージからデータを読み取り結果を返し、エージェントが最終的に結果をユーザに返す流れに相当します。

  1. Azure AI Foundry の Agent Playground を開き、対象エージェントを選択。

  2. チャットプロンプトに例として以下を入力します。

ニュースの要約を取得するツールを使ってください。
  1. エージェントが登録済みの Action を呼び出し、Logic App 経由で Blob Storage からニュースデータを取得して返してくれることを確認します。

image.png


付録:fetch-data-from-data Logic Apps の設定手順

  1. NewsAPI で API キーを取得(無料プランあり)

  2. Azure Key Vault に API キーをシークレットとして登録

  3. Logic Apps のマネージド ID (System-assigned managed identity)を有効化

  4. ストレージアカウントの「Storage Blob Contributor」ロールを Logic Apps のマネージド ID に付与

  5. Key Vault のシークレット取得権限(Get,List)を Logic Apps のマネージド ID に付与

  6. Logic Apps に以下アクションを追加

    1. Get secret(Key Vault から API キー取得)
    2. HTTP(NewsAPI のエンドポイントを呼び出し、X-Api-Key ヘッダーにキーを設定)
    3. Create blob (V2)(HTTP レスポンスを Blob Storage に保存)
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?