工具概述

代理框架支持许多不同类型的工具,用于扩展代理功能。 工具允许代理与外部系统交互、执行代码、搜索数据等。

工具类型

工具类型 Description
函数工具 代理可以在对话期间调用的自定义代码
代码解释器 在沙盒环境中执行代码
文件搜索 搜索上传的文件
Web 搜索 在 Web 上搜索信息
托管 MCP 工具 提供程序运行时调用的 MCP 服务器
本地 MCP 工具 在本地或自定义主机上运行的 MCP 服务器
Foundry 工具箱 在 Foundry 项目中管理的托管工具配置的命名版本控制捆绑包
工具类型 Description
函数工具 代理可以在对话期间调用的自定义代码
代码解释器 在沙盒环境中执行代码
文件搜索 搜索上传的文件
Web 搜索 在 Web 上搜索信息
托管 MCP 工具 提供程序运行时调用的 MCP 服务器
本地 MCP 工具 在本地或自定义主机上运行的 MCP 服务器
Foundry 工具箱 在 Foundry 项目中管理的托管工具配置的命名版本控制捆绑包
图像生成 Foundry/OpenAI 响应运行时上的托管映像生成
Shell OpenAI 响应运行时上的托管 shell 执行 - 不同于 GitHub Copilot CLI 的内置 shell/文件/URL 运行时工具
必应Grounding 使用必应搜索资源通过自己的地面进行 Web 地面 - 实验性
必应自定义搜索 必应限制为特选域列表 - 预览
Azure AI 搜索 通过 Foundry 连接查询Azure AI 搜索索引 - 实验性
SharePoint SharePoint内容中的基本答案 — 预览
Microsoft Fabric 查询Fabric数据代理 — 预览版
内存搜索 搜索 Foundry 托管的内存存储 - 预览版
计算机应用 驱动桌面或浏览器环境 — 预览版
浏览器自动化 通过 playwright Azure 驱动浏览器 — 预览版
代理对代理(A2A)工具 从 Foundry 代理调用远程 A2A 代理作为工具 — 预览版

注释

标记为 实验 性或 预览的工具 记录在相关提供程序页面上,并在过程中首次发出 ExperimentalWarning 它们。

工具审批

工具审批 是一项框架功能,可用于在模型收到结果之前通过人工循环决策来限制每个工具调用(函数工具、托管工具、MCP 工具调用)。 它由框架的函数调用聊天客户端在.NET和Python进行处理,因此它适用于客户端在本地调用工具的任何提供程序;它不是按提供程序的功能。 有关完整模式,请参阅 工具审批 页,包括审批如何与会话、流式处理和中间件交互。

提供程序支持矩阵

OpenAI 和 Azure OpenAI 提供程序分别提供两种客户端类型(响应和聊天完成),具有不同的工具功能。 Azure OpenAI 客户端镜像其 OpenAI 等效项。 Copilot StudioA2A 代理在远程服务上运行,以便其功能在远程代理上配置,而不是通过 Agent Framework 客户端进行配置, 它们不会列在矩阵中。

工具类型 反应 聊天完成 代工厂 Anthropic Ollama GitHub Copilot
函数工具
代码解释器
文件搜索
Web 搜索
托管 MCP 工具
本地 MCP 工具

注释

ResponsesChat Completion 列同时适用于 OpenAI 和 Azure OpenAI ,Azure变体与 OpenAI 对应项镜像相同的工具支持。 不再记录弃用的 OpenAI Assistants API;有关迁移指南,请参阅 语义内核 迁移指南

提供程序支持矩阵

OpenAI 和 Azure OpenAI 提供程序各自提供具有不同工具功能的多个客户端类型。 Azure OpenAI 客户端镜像其 OpenAI 等效项。 Foundry 列适用于 FoundryChatClient - 对于FoundryAgent,工具是在 Foundry 代理定义上配置的(请参阅“工作内容”和“不支持FoundryAgent的内容”)。 Copilot StudioA2A 代理在远程服务上运行,以便其功能在远程代理上配置,而不是通过 Agent Framework 客户端进行配置, 它们不会列在矩阵中。

工具类型 反应 聊天完成 代工厂 Anthropic Ollama Foundry Local GitHub Copilot
函数工具 ⚠️¹ ⚠️¹
代码解释器
文件搜索
Web 搜索
图像生成
托管 Shell (get_shell_tool
内置 shell/文件系统/URL 提取 ✅2
托管 MCP 工具
本地 MCP 工具
Foundry 工具箱
必应地面 (实验)
必应自定义搜索 (预览版)
Azure AI 搜索 (实验)
SharePoint (预览版)
Microsoft Fabric (预览版)
内存搜索 (预览版)
计算机使用 (预览版)
浏览器自动化 (预览版)
代理到代理 (A2A) 工具 (预览版)

¹ 取决于所选的本地模型支持函数调用。 ー 内置于 GitHub Copilot CLI 运行时中,由权限处理程序封闭。 与 OpenAI 不同的 get_shell_tool图面。

注释

ResponsesChat Completion 列同时适用于 OpenAI 和 Azure OpenAI ,Azure变体与 OpenAI 对应项镜像相同的工具支持。 本地 MCP 工具适用于支持函数工具的任何提供程序。

使用代理作为函数工具

可以将代理用作另一个代理的函数工具,从而启用代理组合和更高级的工作流。 内部代理将转换为函数工具,并提供给外部代理,然后可以根据需要调用它。

.AsAIFunction()调用AIAgent某个函数以将其转换为可提供给另一个代理的函数工具:

// Create the inner agent with its own tools
AIAgent weatherAgent = new AIProjectClient(
    new Uri("<your-foundry-project-endpoint>"),
    new DefaultAzureCredential())
     .AsAIAgent(
        model: "gpt-4o-mini",
        instructions: "You answer questions about the weather.",
        name: "WeatherAgent",
        description: "An agent that answers questions about the weather.",
        tools: [AIFunctionFactory.Create(GetWeather)]);

// Create the main agent and provide the inner agent as a function tool
AIAgent agent = new AIProjectClient(
    new Uri("<your-foundry-project-endpoint>"),
    new DefaultAzureCredential())
     .AsAIAgent(
        model: "gpt-4o-mini",
        instructions: "You are a helpful assistant.",
        tools: [weatherAgent.AsAIFunction()]);

// The main agent can now call the weather agent as a tool
Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?"));

警告

DefaultAzureCredential 对于开发来说很方便,但在生产中需要仔细考虑。 在生产环境中,请考虑使用特定凭据(例如), ManagedIdentityCredential以避免延迟问题、意外凭据探测以及回退机制的潜在安全风险。

调用 .as_tool() 代理将其转换为可提供给另一个代理的函数工具:

import os
from agent_framework.openai import OpenAIChatCompletionClient
from azure.identity import AzureCliCredential

# Create the inner agent with its own tools
weather_agent = OpenAIChatCompletionClient(
    model=os.environ["AZURE_OPENAI_CHAT_COMPLETION_MODEL"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
    credential=AzureCliCredential(),
).as_agent(
    name="WeatherAgent",
    description="An agent that answers questions about the weather.",
    instructions="You answer questions about the weather.",
    tools=get_weather
)

# Create the main agent and provide the inner agent as a function tool
main_agent = OpenAIChatCompletionClient(
    model=os.environ["AZURE_OPENAI_CHAT_COMPLETION_MODEL"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
    credential=AzureCliCredential(),
).as_agent(
    instructions="You are a helpful assistant.",
    tools=weather_agent.as_tool()
)

# The main agent can now call the weather agent as a tool
result = await main_agent.run("What is the weather like in Amsterdam?")
print(result.text)

还可以自定义工具名称、说明和参数名称:

weather_tool = weather_agent.as_tool(
    name="WeatherLookup",
    description="Look up weather information for any location",
    arg_name="query",
    arg_description="The weather query or location"
)

后续步骤