はじめに
本記事では、Azure AI Foundry のエージェントから Azure Logic Apps をツールとして呼び出す、最小構成のサンプルを解説します。
主に 「get-newsapi-org-data」 という Logic App をエージェントに登録し、ニュースデータを取得する流れを説明します。
補足
ニュースデータを Blob Storage に定期的に格納する別途の Logic App(例:fetch-data-from-data
)は付録として後述します。
全体の構成
黄色で示した部分が記事のメインのトピックです。
前提条件
- ニュースデータが Blob Storage に保存されていること
- Azure AI Foundry にエージェントが定義済みであること
"Agent856" という名前のエージェントが"MyFirstAiProject" というAzure AI Foundry プロジェクトに定義されています。
1. Logic Apps コネクション設定
カスタムキー接続 を Connected resources に登録します。概念図の (f) に相当します。
-
Azure AI Foundry ポータルで Hub(または Project) の「Connected resources」画面を開きます。
-
Hub に登録すると、他プロジェクトでも同じ接続情報を使い回せます。
-
任意の名前を付けます(例:
LogicApps_Tool_Connection_getnewsapiorgdata
)。 -
Key name に
sig
、Value に Logic App のトリガー URL 内のsig
クエリ文字列を貼り付けて保存します。- Logic App 側:「When a HTTP request is received」アクションの URL に
?sig=xxxx
が含まれていますので、この値をコピーします。
- Logic App 側:「When a HTTP request is received」アクションの URL に
2. エージェントに OpenAPI 3.0 接続(Action)を登録
概念図での (g) を (h) に登録する部分を設定します
-
Tool type に OpenAPI3.0 specification tool を選び、
-
Name:任意(例:
GetNewsApiOrgData
) -
Description:エージェントに表示される説明文
を入力します。
-
Name:任意(例:
以下のような最小サンプルをベースに、実際の 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"
}
}
}
}
注目する点
-
servers の
url
はロジックアップのHTTPトリガーのエンドポイントなのでロジックアップからコピーします。 -
security で
sig
を使うことを定義しています。この値はカスタムキー接続に指定したものが実際には送信されます。 -
requestBody は Logic App 側の「Request BODY JSON Schema」に合わせて調整可能(例では
location
のみ)。例えばエージェント側からブロブ名などを指定できます。 - default プロパティが指定してある要素はエージェント側から渡す必要はない(定数として理解してかまわない)。
3. Agent Playground で動作確認
概念図のエージェント (h) に対しての要求が、アクション(g)に委任され、Logic Apps (e) がストレージからデータを読み取り結果を返し、エージェントが最終的に結果をユーザに返す流れに相当します。
-
Azure AI Foundry の Agent Playground を開き、対象エージェントを選択。
-
チャットプロンプトに例として以下を入力します。
ニュースの要約を取得するツールを使ってください。
- エージェントが登録済みの Action を呼び出し、Logic App 経由で Blob Storage からニュースデータを取得して返してくれることを確認します。
付録:fetch-data-from-data
Logic Apps の設定手順
-
NewsAPI で API キーを取得(無料プランあり)
-
Azure Key Vault に API キーをシークレットとして登録
-
Logic Apps のマネージド ID (System-assigned managed identity)を有効化
-
ストレージアカウントの「Storage Blob Contributor」ロールを Logic Apps のマネージド ID に付与
-
Key Vault のシークレット取得権限(Get,List)を Logic Apps のマネージド ID に付与
-
Logic Apps に以下アクションを追加
- Get secret(Key Vault から API キー取得)
-
HTTP(NewsAPI のエンドポイントを呼び出し、
X-Api-Key
ヘッダーにキーを設定) - Create blob (V2)(HTTP レスポンスを Blob Storage に保存)