通过


工具概述

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

工具类型

工具类型 Description
函数工具 代理可以在对话期间调用的自定义代码
工具审批 工具调用的人工循环审批
代码解释器 在沙盒环境中执行代码
文件搜索 搜索上传的文件
Web 搜索 在 Web 上搜索信息
托管 MCP 工具 由 Azure AI Foundry 托管的 MCP 工具
本地 MCP 工具 在本地或自定义服务器上运行的 MCP 工具

提供程序支持矩阵

OpenAI 和 Azure OpenAI 提供程序各自提供具有不同工具功能的多个客户端类型。 Azure OpenAI 客户端镜像其 OpenAI 等效项。

工具类型 聊天完成 反应 助手 Azure AI Foundry Anthropic Ollama GitHub Copilot Copilot Studio
函数工具
工具审批
代码解释器
文件搜索
Web 搜索
托管 MCP 工具
本地 MCP 工具

注释

聊天完成响应助手列同时适用于 OpenAI 和 Azure OpenAI — Azure 变体镜像其 OpenAI 对应项的相同工具支持。

提供程序支持矩阵

OpenAI 和 Azure OpenAI 提供程序各自提供具有不同工具功能的多个客户端类型。 Azure OpenAI 客户端镜像其 OpenAI 等效项。

工具类型 聊天完成 反应 助手 Azure AI Foundry Anthropic Claude 代理 Ollama GitHub Copilot
函数工具
工具审批
代码解释器
文件搜索
Web 搜索
图像生成
托管 MCP 工具
本地 MCP 工具

注释

聊天完成响应助手列同时适用于 OpenAI 和 Azure OpenAI — Azure 变体镜像其 OpenAI 对应项的相同工具支持。 本地 MCP 工具适用于支持函数工具的任何提供程序。

使用代理作为函数工具

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

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

// Create the inner agent with its own tools
AIAgent weatherAgent = new AzureOpenAIClient(
    new Uri("https://<myresource>.openai.azure.com"),
    new AzureCliCredential())
     .GetChatClient("gpt-4o-mini")
     .AsAIAgent(
        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 AzureOpenAIClient(
    new Uri("https://<myresource>.openai.azure.com"),
    new AzureCliCredential())
     .GetChatClient("gpt-4o-mini")
     .AsAIAgent(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?"));

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

from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential

# Create the inner agent with its own tools
weather_agent = AzureOpenAIChatClient(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 = AzureOpenAIChatClient(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"
)

后续步骤