Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Une boîte à outils Microsoft Foundry est un ensemble nommé et versionné côté serveur de configurations d’outils hébergés, comme l’interpréteur de code, la recherche de fichiers, la génération d’images, MCP et la recherche web. Les boîtes à outils vous permettent de gérer la configuration des outils une fois dans Foundry et de les réutiliser entre les agents.
Agent Framework couvre la consommation de boîte à outils. Créez et mettez à jour des versions de boîte à outils via le portail Foundry ou le azure-ai-projects Kit de développement logiciel (SDK).
Important
FoundryToolbox est fourni par le package bêta agent-framework-foundry-hosting et peut changer avant la version stable.
Pour un service géré FoundryAgent, attachez la boîte à outils à la définition de l’agent dans Foundry. Les conseils de consommation de la boîte à outils côté client .NET ne sont pas actuellement documentés.
Installer les packages
pip install agent-framework-foundry-hosting agent-framework-foundry --pre
FoundryToolbox est importé à partir et agent_framework.foundry fourni par agent-framework-foundry-hosting.
Configurer la boîte à outils
Définissez un point de terminaison MCP de boîte à outils explicite :
TOOLBOX_ENDPOINT="https://<account>.services.ai.azure.com/api/projects/<project>/toolboxes/<name>/mcp?api-version=v1"
Ou laissez FoundryToolbox construire le point de terminaison :
FOUNDRY_PROJECT_ENDPOINT="https://<account>.services.ai.azure.com/api/projects/<project>"
TOOLBOX_NAME="<toolbox-name>"
Les exemples d’agents hébergés sont également utilisés AZURE_AI_MODEL_DEPLOYMENT_NAME pour FoundryChatClient.
Utiliser FoundryToolbox avec un agent hébergé
FoundryToolboxrésout son point de terminaison, authentifie chaque demande MCP avec les informations d'identification Azure fournies, transfère l'ID d'appel Foundry par demande et participe au cycle de vie de connexion de l'agent.
import asyncio
import os
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient, FoundryToolbox, ResponsesHostServer
from azure.identity import DefaultAzureCredential
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
async def main():
credential = DefaultAzureCredential()
# FoundryToolbox resolves the toolbox endpoint from the environment
# (TOOLBOX_ENDPOINT, or FOUNDRY_PROJECT_ENDPOINT + TOOLBOX_NAME), authenticates
# every request with the credential, and transparently forwards the platform
# per-request call-id to the toolbox. The hosting server enters the agent, which
# connects the toolbox on first use and closes it at shutdown.
toolbox = FoundryToolbox(credential)
# Create the chat client
client = FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
credential=credential,
)
agent = Agent(
client=client,
instructions="You are a friendly assistant. Keep your answers brief.",
tools=toolbox,
# History will be managed by the hosting infrastructure, thus there
# is no need to store history by the service. Learn more at:
# https://developers.openai.com/api/reference/resources/responses/methods/create
default_options={"store": False},
)
server = ResponsesHostServer(agent)
await server.run_async()
Exposer les compétences de boîte à outils
Une boîte à outils peut exposer les compétences de l’agent sur MCP. Définissez load_tools=False quand seules les compétences doivent être visibles par modèle, puis ajoutez la boîte à outils en tant qu’outil afin que sa session MCP se connecte et utilise as_skills_provider() en tant que fournisseur de contexte.
import asyncio
import os
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient, FoundryToolbox, ResponsesHostServer
from azure.identity import DefaultAzureCredential
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
async def main() -> None:
credential = DefaultAzureCredential()
# FoundryToolbox resolves the toolbox endpoint from the environment
# (TOOLBOX_ENDPOINT, or FOUNDRY_PROJECT_ENDPOINT + TOOLBOX_NAME), authenticates
# every request with the credential, and forwards the platform per-request
# call-id. ``load_tools=False`` keeps the toolbox's tools hidden so only its
# Agent Skills (SEP-2640) are surfaced; passing it via ``tools=`` connects the
# MCP session that ``as_skills_provider()`` reads from.
toolbox = FoundryToolbox(credential, load_tools=False)
# as_skills_provider() discovers skills from skill://index.json on the toolbox
# MCP session and exposes them as an agent context provider; SKILL.md bodies are
# fetched on demand via resources/read. disable_load_skill_approval=True registers
# the load_skill tool with approval_mode="never_require" so this unattended agent
# can load skills without an approval round-trip -- the Responses host runs the
# agent without an AgentSession, which the default approval flow requires.
skills_provider = toolbox.as_skills_provider(disable_load_skill_approval=True)
client = FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
credential=credential,
)
agent = Agent(
client=client,
name=os.environ.get("AGENT_NAME", "hosted-toolbox-mcp-skills"),
instructions="You are a helpful assistant.",
tools=toolbox,
context_providers=[skills_provider],
# History will be managed by the hosting infrastructure, thus there
# is no need to store history by the service. Learn more at:
# https://developers.openai.com/api/reference/resources/responses/methods/create
default_options={"store": False},
)
server = ResponsesHostServer(agent)
await server.run_async()
L’approbation reste activée par défaut pour les opérations de compétence. Désactivez les approbations individuelles uniquement pour les scénarios approuvés et sans assistance.
Utiliser une boîte à outils avec FoundryAgent
Attachez la boîte à outils à la définition d’invite ou d’agent hébergé dans Foundry.
FoundryAgent utilise cette configuration d’outil stockée ; le passage d’une boîte à outils côté client ne l’ajoute pas à l’agent managé.
Se connecter via mcP brut
Utilisez MCPStreamableHTTPTool directement lorsque l’application n’utilise pas le FoundryToolbox wrapper d’hébergement. Fournissez le point de terminaison de la boîte à outils et un jeton du porteur de Entra ID via header_provider.
import asyncio
import os
from collections.abc import Callable
from typing import Any, cast
from agent_framework import Agent, MCPStreamableHTTPTool
from agent_framework.foundry import FoundryChatClient
from azure.core.credentials import TokenCredential
from azure.identity import AzureCliCredential, DefaultAzureCredential, get_bearer_token_provider
from dotenv import load_dotenv
def make_toolbox_header_provider(credential: TokenCredential) -> Callable[[dict[str, Any]], dict[str, str]]:
"""Build a header_provider that injects a fresh Azure AI bearer token on every MCP request."""
get_token = get_bearer_token_provider(credential, "https://ai.azure.com/.default")
def provide(_kwargs: dict[str, Any]) -> dict[str, str]:
return {
"Authorization": f"Bearer {get_token()}",
}
return provide
async def main() -> None:
credential = DefaultAzureCredential()
toolbox_tool = MCPStreamableHTTPTool(
name="foundry_toolbox",
description="Tools exposed by the configured Foundry toolbox",
url=os.environ["FOUNDRY_TOOLBOX_ENDPOINT"],
header_provider=make_toolbox_header_provider(credential),
load_prompts=False,
)
async with Agent(
client=FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["FOUNDRY_MODEL"],
credential=credential,
),
instructions="You are a helpful assistant. Use the available toolbox tools to answer the user.",
tools=toolbox_tool,
) as agent:
query = "What tools do you have access to?"
print(f"User: {query}")
result = await agent.run(query)
print(f"Assistant: {result}")
L’exemple de niveau inférieur utilise FOUNDRY_TOOLBOX_ENDPOINT. L’exemple de compétences de boîte à outils utilise FOUNDRY_TOOLBOX_MCP_SERVER_URL; ces noms appartiennent à ces exemples et sont séparés des paramètres et TOOLBOX_NAME des paramètres de TOOLBOX_ENDPOINT la FoundryToolbox classe.
Limitations
- Les outils MCP à l’intérieur d’une boîte à outils utilisent l’authentification côté serveur par le biais d’une instance Foundry
project_connection_id; le client Agent Framework ne contient pas le jeton du porteur MCP en amont. - L’utilisation d’une boîte à outils en tant que serveur MCP nécessite une authentification Entra ID côté client pour le point de terminaison de boîte à outils.
- Les réponses de flux de consentement telles que
CONSENT_REQUIREDsont gérées pendant l’exécution de l’agent, et non pendant la création de la connexion de boîte à outils.
Samples
| Sample | Description |
|---|---|
| foundry_toolbox/main.py |
FoundryToolbox avec un agent Réponses hébergées |
| foundry_toolbox_mcp_skills/main.py | Compétences de l’agent soutenu par la boîte à outils |
| foundry_chat_client_with_toolbox.py | Consommation MCP de boîte à outils avec MCPStreamableHTTPTool |
| foundry_chat_client_with_toolbox_skills.py | Configuration des compétences soutenues par la boîte à outils |
| invoke_foundry_toolbox_mcp | Consommation MCP côté flux de travail |
Go n’expose actuellement pas d’assistance à la boîte à outils Foundry. Configurez les boîtes à outils via Foundry et utilisez les déclarations d’outils locales ou hébergées prises en charge pour les agents Go.