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

Microsoft Foundry Agentでナレッジの承認不要に設定

Posted at

Python SDKでナレッジの承認不要なMicrosoft Foundry Agentを定義しました。
2025年12月時点ではFoundry Portalで設定できなかったので、SDKを使っています。

Steps

0. 前提

Windows11のPython3.13.7で実行
以下のパッケージを使っています。

azure-identity==1.25.1
azure-ai-projects==2.0.0b2

あと、ロール割当追加として、Foundry プロジェクトのリソースに「検索イデックス共同作成者」を割当追加。
Foundryリソースに割り当ててもダメなので要注意。

1. Script

以下のスクリプトを実行。

import os
import requests

from azure.ai.projects.models import MCPTool, PromptAgentDefinition
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

# ここは固定値定義を入れる
subscription = 
resource_group = 
account_name = 
project_name = 
project_connection_name = 
knowledgebase_name = 
ai_search_endpoint = 
agent_name = 

credential = DefaultAzureCredential()

project_resource_id = f"/subscriptions/{subscription}/resourceGroups/{resource_group}/providers/Microsoft.CognitiveServices/accounts/{account_name}/projects/{project_name}"
# MS Foundry 画面のOperate -> Admin画面で確認可能

# Get bearer token for authentication
bearer_token_provider = get_bearer_token_provider(credential, "https://management.azure.com/.default")
headers = {
  "Authorization": f"Bearer {bearer_token_provider()}",
}

mcp_endpoint = f"{ai_search_endpoint}/knowledgebases/{knowledgebase_name}/mcp?api-version=2025-11-01-preview"
response = requests.put(
  f"https://management.azure.com{project_resource_id}/connections/{project_connection_name}?api-version=2025-10-01-preview",
  headers = headers,
  json = {
    "name": project_connection_name,
    "type": "Microsoft.MachineLearningServices/workspaces/connections",
    "properties": {
      "authType": "ProjectManagedIdentity",
      "category": "RemoteTool",
      "target": mcp_endpoint,
      "isSharedToAll": True,
      "audience": "https://search.azure.com/",
      "metadata": { "ApiType": "Azure" }
    }
  }
)

response.raise_for_status()
print(f"Connection '{project_connection_name}' created or updated successfully.")

作成されたAgentをYAMLで見ます。require_approvalの値がneverになっているのがわかります。

Agent定義抜粋
metadata:
  description: ""
  modified_at: "1764738303"
object: agent.version
id: test03:14
name: test03
version: "14"
description: ""
created_at: 1764738305
definition:
  tools:
    - type: mcp
      server_label: knowledge-base
      allowed_tools:
        - knowledge_base_retrieve
      require_approval: never
      project_connection_id: aisearchagentncustest05
0
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
0
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?