🔄

Semantic KernelとAzure AI Foundryによるハイブリッドアプローチ

に公開

はじめに

Azure AI Foundryを使ったMulti-AgentのアーキテクチャとAI Foundryでどんな感じでエージェントを管理できるのか試してみようかと。

Multi-Agent Custom Automation Engine Solution Accelerator
というMicrosoftのリポジトリがあったので、試してみます。

GitHubのCodeSpaceでデプロイしたのですが、そこで作成してもらったデプロイ手順は最後にそのまま載せます。

ソリューションアーキテクチャ

Container AppsからAzure AI Foundryを呼んでいます。
Semantic KernelがOrchestratorとなっていて、実際のAgentはAzure AI Foundryにいるみたいです。

エージェントアーキテクチャ

この図でいうとPlanner Agentが実行計画を立てて、
Group Chat Manager AgentがExecutorというか、実行を管理しているAgentになるみたいです。

実際デプロイしてみるとこんな感じのエージェントができていました。

Planner Agentのシステムプロンプト

            You are the Planner, an AI orchestrator that manages a group of AI agents to accomplish tasks.

            For the given objective, come up with a simple step-by-step plan.
            This plan should involve individual tasks that, if executed correctly, will yield the correct answer. Do not add any superfluous steps.
            The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.

            These actions are passed to the specific agent. Make sure the action contains all the information required for the agent to execute the task.

            Your objective is:
            {{$objective}}

            The agents you have access to are:
            {{$agents_str}}

            These agents have access to the following functions:
            {{$tools_str}}

            The first step of your plan should be to ask the user for any additional information required to progress the rest of steps planned.

            Only use the functions provided as part of your plan. If the task is not possible with the agents and tools provided, create a step with the agent of type Human and mark the overall status as completed.

            Do not add superfluous steps - only take the most direct path to the solution, with the minimum number of steps. Only do the minimum necessary to complete the goal.

            If there is a single function call that can directly solve the task, only generate a plan with a single step. For example, if someone asks to be granted access to a database, generate a plan with only one step involving the grant_database_access function, with no additional steps.

            When generating the action in the plan, frame the action as an instruction you are passing to the agent to execute. It should be a short, single sentence. Include the function to use. For example, "Set up an Office 365 Account for Jessica Smith. Function: set_up_office_365_account"

            Ensure the summary of the plan and the overall steps is less than 50 words.

            Identify any additional information that might be required to complete the task. Include this information in the plan in the human_clarification_request field of the plan. If it is not required, leave it as null.

            When identifying required information, consider what input a GenericAgent or fallback LLM model would need to perform the task correctly. This may include:
            - Input data, text, or content to process
            - A question to answer or topic to describe
            - Any referenced material that is mentioned but not actually included (e.g., "the given text")
            - A clear subject or target when the task instruction is too vague (e.g., "describe," "summarize," or "analyze" without specifying what to describe)

            If such required input is missing—even if not explicitly referenced—generate a concise clarification request in the human_clarification_request field.

            Do not include information that you are waiting for clarification on in the string of the action field, as this otherwise won't get updated.

            You must prioritise using the provided functions to accomplish each step. First evaluate each and every function the agents have access too. Only if you cannot find a function needed to complete the task, and you have reviewed each and every function, and determined why each are not suitable, there are two options you can take when generating the plan.
            First evaluate whether the step could be handled by a typical large language model, without any specialised functions. For example, tasks such as "add 32 to 54", or "convert this SQL code to a python script", or "write a 200 word story about a fictional product strategy".
            If a general Large Language Model CAN handle the step/required action, add a step to the plan with the action you believe would be needed. Assign these steps to the GenericAgent. For example, if the task is to convert the following SQL into python code (SELECT * FROM employees;), and there is no function to convert SQL to python, write a step with the action "convert the following SQL into python code (SELECT * FROM employees;)" and assign it to the GenericAgent.
            Alternatively, if a general Large Language Model CAN NOT handle the step/required action, add a step to the plan with the action you believe would be needed and assign it to the HumanAgent. For example, if the task is to find the best way to get from A to B, and there is no function to calculate the best route, write a step with the action "Calculate the best route from A to B." and assign it to the HumanAgent.

            Limit the plan to 6 steps or less.

            Choose from {{$agents_str}} ONLY for planning your steps.

GroupChatManagerエージェントの手順

You are a GroupChatManager agent responsible for creating and managing plans. You analyze tasks, break them down into steps, and assign them to the appropriate specialized agents.

いくつかアプリでタスクの実行手順を考えてもらって、チェックしてみたのですが、ログとかはAI Foundry側には残ってなさそうでした。

Semantic KernelとAzure AI Foundryの役割

Planner Agentがいるけど、Semantic Kernelの役割はなんなのか、聞いてみました。

実装

# BaseAgentクラス(agent_base.py)
class BaseAgent(AzureAIAgent):  # Semantic KernelのAzureAIAgentを継承
    def __init__(self, ...):
        super().__init__(  # Semantic Kernelのエージェント初期化
            client=client,  # AI Foundryクライアント
            definition=definition  # AI Foundryエージェント定義
        )

🎯 ハイブリッドアプローチ

このアプリケーションは以下のような ハイブリッドアプローチを採用しています:

Semantic Kernel: エージェントの実装、ツール管理、会話フロー
AI Foundry: 認証、プロジェクト管理、リソース管理

💡 主要コンポーネント
Agent Factory (agent_factory.py): Semantic Kernelエージェントの作成
Agent Base (agent_base.py): AzureAIAgentを継承したベースクラス
Specialized Agents: HR、Marketing、Product等の専門エージェント
AI Project Client: AI Foundryプロジェクトとの接続

このアプリケーションは Semantic Kernelエージェント をメインとして使用し、AI Foundryをインフラストラクチャとプロジェクト管理の目的で統合したハイブリッドアーキテクチャを採用しています。

エージェントの処理フロー

結論

一例だと思いますが、こちらのハイブリッドアプローチでAI Foundryでエージェントを管理しつつ、Semantic Kernelでエージェント利用するという流れが実現されているようです。

おまけ

以下は実行した結果から生成してもらったものですが、こちらを理解するというより、
ただチャットにデプロイしたいって言ってコマンドを選択していくだけなので、理解不要かと。


Multi-Agent Custom Automation Engine Solution Acceleratorのデプロイ手順

はじめに

Microsoft の Multi-Agent Custom Automation Engine Solution Accelerator を Azure にデプロイする手順を詳しく解説します。このソリューションは、複数の AI エージェントが連携して組織のタスクを自動化するためのプラットフォームです。

前提条件

必要なツール

  • Azure Developer CLI (azd) v1.15.0 以上
  • Azure サブスクリプションへのアクセス権限
  • リソースグループとリソースを作成する権限

必要なAzureサービス

以下のサービスが利用可能なリージョンを選択してください:

  • Azure AI Foundry
  • Azure Container Apps
  • Azure Container Registry
  • Azure Cosmos DB
  • Azure Key Vault
  • Azure AI Search

推奨リージョン: East US, East US2, Japan East, UK South, Sweden Central

デプロイ手順

ステップ1: 開発環境の準備

GitHub Codespaces または VS Code Dev Containers を使用することを推奨します。

GitHub Codespaces の場合:

  1. Open in GitHub Codespaces をクリック
  2. デフォルト値でCodespacesページを作成
  3. ターミナルウィンドウを開く

VS Code Dev Containers の場合:

  1. Docker Desktop を起動
  2. Open in Dev Containers をクリック
  3. プロジェクトファイルが表示されたらターミナルを開く

ステップ2: Azure への認証

特定のテナントIDを指定してAzureにログインします:

# azd のバージョン確認
azd version

# 現在のログイン状態を確認
azd auth login --check-status

特定のテナントIDでログインする場合:

# デバイスコードを使用してログイン(推奨)
azd auth login --tenant-id [YOUR_TENANT_ID] --use-device-code

ステップ3: アプリケーションのデプロイ

以下のコマンドでプロビジョニングとデプロイを実行します:

azd up

デプロイ中に以下の選択肢が表示されます:

WAF対応構成の選択

  • true: 本番環境向けのWell-Architected Framework対応構成
  • false: 開発・PoC向けの軽量なサンドボックス構成

設定可能なパラメータ

設定項目 説明 デフォルト値
Environment Name リソース名のプレフィックス macae
Azure Region Azureリソースの場所 swedencentral
GPT Model Name 使用するGPTモデル gpt-4o
GPT Model Capacity GPTモデルの容量 150
Enable Telemetry テレメトリの有効化 true

ステップ4: デプロイ結果の確認

デプロイが完了すると以下のような出力が表示されます:

SUCCESS: Your up workflow to provision and deploy to Azure completed in 12 seconds.

デプロイされたリソースの確認

# デプロイ情報の表示
azd show

# Container Apps のエンドポイント確認
az containerapp list --resource-group [RESOURCE_GROUP_NAME] --query "[].{Name:name, URL:properties.configuration.ingress.fqdn}" --output table

# App Service のエンドポイント確認  
az webapp list --resource-group [RESOURCE_GROUP_NAME] --query "[].{Name:name, URL:defaultHostName}" --output table

アプリケーションへのアクセス

重要:正しいエンドポイント

デプロイにより以下の2つのサービスが作成されます:

  1. フロントエンドアプリケーション (App Service)

    • URL: https://app-[環境名].azurewebsites.net
    • 用途: ユーザーインターフェース
  2. バックエンドAPI (Container App)

    • URL: https://ca-[環境名].[リージョン].azurecontainerapps.io
    • 用途: API エンドポイント

重要: メインアプリケーションには App Service のURL からアクセスしてください。Container AppのURLに直接アクセスすると {"detail":"Not Found"} エラーが表示されます。

アクセス例

フロントエンド: https://app-macae-xxx.azurewebsites.net
バックエンド: https://ca-macae-xxx.zzz.eastus2.azurecontainerapps.io

トラブルシューティング

認証エラーの場合

# ログイン状態の確認
azd auth login --check-status

# デバイスコードでの再ログイン
azd auth login --tenant-id [YOUR_TENANT_ID] --use-device-code

404 Not Found エラーの場合

  • Container App の URL ではなく、App Service の URL にアクセスしているか確認
  • ログの確認: az containerapp logs show --name [CONTAINER_APP_NAME] --resource-group [RESOURCE_GROUP_NAME] --tail 50

リソースの確認

# リソースグループの詳細
az group show --name [RESOURCE_GROUP_NAME]

# App Service の状態確認
az webapp show --name [APP_SERVICE_NAME] --resource-group [RESOURCE_GROUP_NAME] --query "{State:state, HostName:defaultHostName, HttpsOnly:httpsOnly}" --output table

後片付け

アプリケーションを削除する場合:

azd down

まとめ

この手順により、Multi-Agent Custom Automation Engine Solution Accelerator を Azure に正常にデプロイできます。主なポイントは:

  1. 適切な開発環境(Codespaces/Dev Containers)の使用
  2. 正しいテナントIDでの認証
  3. WAF構成の選択
  4. 正しいエンドポイント(App Service)へのアクセス

デプロイ後は、認証設定ガイドカスタマイズガイドを参考に、さらなる設定やカスタマイズを行うことができます。

参考リンク

ヘッドウォータース

Discussion