1
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?

A2A AgentをAzure API Managementでインポート

Posted at

A2A AgentをAzure API Managementでインポートして、Copilot Studioから呼び出してみました。
A2A AgentはOAuthの認証を設定していて、作る部分は以下の記事参照。

Steps

1. A2A Agentインポート

API Managementでメニュー APIs -> API からA2A Agentをインポート
image.png

Agent CardのURLを指定(Agent Cardは認証なしに設定済)。
image.png
適当に項目埋めていき、作成。
image.png

その後、Productsとのひもづけもしておきます。

2. ポリシー設定

名前付き値を使わず、直接URLなどを書きました。
AIの提案をそのまま受け入れたので、根本的におかしい点もあるかもしれません。

Policies
<policies>
	<!-- Throttle, authorize, validate, cache, or transform the requests -->
	<inbound>
		<base />
		<!-- 1) キャッシュからトークンを探す -->
		<cache-lookup-value key="a2a_access_token" variable-name="accessToken" />
		<!-- 2) 無ければトークンを取りに行く -->
		<choose>
			<when condition="@(!context.Variables.ContainsKey("accessToken") || string.IsNullOrEmpty((string)context.Variables["accessToken"]))">
				<send-request mode="new" response-variable-name="tokenResponse" timeout="20" ignore-error="false">
					<set-url>https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token</set-url>
					<set-method>POST</set-method>
					<set-header name="Content-Type" exists-action="override">
						<value>application/x-www-form-urlencoded</value>
					</set-header>
					<set-body>@{
            // v2.0 endpoint
            var body =
              "grant_type=client_credentials" +
              "&client_id=" +
              "&client_secret=" +
              "&scope=api://c116acab-c584-4dce-ba6d-931989dddeed/.default";
            return body;
          }</set-body>
				</send-request>
				<!-- 3) JSON から access_token を取り出す -->
				<set-variable name="accessToken" value="@{
          var json = ((IResponse)context.Variables["tokenResponse"]).Body.As<JObject>();
          return (string)json["access_token"];
        }" />
				<!-- 4) キャッシュ(期限は少し短め推奨) -->
				<cache-store-value key="a2a_access_token" value="@((string)context.Variables["accessToken"])" duration="3300" />
			</when>
		</choose>
		<!-- 5) バックエンド向けに Authorization を付与 -->
		<set-header name="Authorization" exists-action="override">
			<value>@($"Bearer {(string)context.Variables["accessToken"]}")</value>
		</set-header>
	</inbound>
	<!-- Control if and how the requests are forwarded to services  -->
	<backend>
		<base />
	</backend>
	<!-- Customize the responses -->
	<outbound>
		<base />
	</outbound>
	<!-- Handle exceptions and customize error responses  -->
	<on-error>
		<base />
	</on-error>
</policies>

3. Copilot Studioから呼出

詳細手順は参照記事とほぼ同じなので省略しますが、Key認証でA2Aを呼び出します。
Ocp-Apim-Subscription-Keyをキーにして、値はAPIのProductに紐づいたサブスクリプションキーを使用。

呼出画面。
image.png

1
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
1
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?