共用方式為


工具概述

代理框架支援多種不同類型的工具,以擴充代理能力。 工具讓代理能與外部系統互動、執行程式碼、搜尋資料等。

工具類型

工具類型 Description
函式工具 客服人員在通話中可呼叫的自訂程式碼
工具核准 工具呼叫的人工審核審核
程式碼解譯器 在沙盒環境中執行程式碼
檔案搜尋 搜尋上傳的檔案
網路搜尋 請上網搜尋相關資訊
託管 MCP 工具 由 Azure AI Foundry 託管的 MCP 工具
本地 MCP 工具 MCP 工具可運行於本地或自訂伺服器上

提供者支援矩陣

OpenAI 與 Azure OpenAI 供應商各自提供多種客戶端類型及不同工具功能。 Azure OpenAI 用戶端會鏡像其 OpenAI 對應版本。

工具類型 聊天完成 回應 助理 Azure AI Foundry 人為 Ollama GitHub Copilot 副駕駛工作室
函式工具
工具核准
程式碼解譯器
檔案搜尋
網路搜尋
託管 MCP 工具
本地 MCP 工具

備註

聊天完成回應助理欄位同時適用於 OpenAI 與 Azure OpenAI——Azure 版本在工具支援上與 OpenAI 版本相同。

提供者支援矩陣

OpenAI 與 Azure OpenAI 供應商各自提供多種客戶端類型及不同工具功能。 Azure OpenAI 用戶端會鏡像其 OpenAI 對應版本。

工具類型 聊天完成 回應 助理 Azure AI Foundry 人為 克勞德·特工 Ollama GitHub Copilot
函式工具
工具核准
程式碼解譯器
檔案搜尋
網路搜尋
影像生成
託管 MCP 工具
本地 MCP 工具

備註

聊天完成回應助理欄位同時適用於 OpenAI 與 Azure OpenAI——Azure 版本在工具支援上與 OpenAI 版本相同。 本地 MCP 工具可與任何支援函式工具的供應商合作。

使用代理作為函數工具

你可以將一個代理當作另一個代理的功能工具,實現代理組合和更進階的工作流程。 內部代理會被轉換成功能工具,並提供給外部代理,外部代理可視需要呼叫。

呼叫 .AsAIFunction()AIAgent 將其轉換為可供其他代理使用的函式工具:

// 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"
)

後續步驟