使用 AI Toolkit Copilot 工具進行 AI 代理開發

AI Toolkit Copilot 工具可協助您更快地建置 AI 代理應用程式。這些工具提供現成的功能、範本和最佳實踐,讓您能更迅速地建立運用 AI 的智慧型應用程式。

注意

AI Toolkit Copilot 工具使用 VS Code 的 語言模型工具 API (Language Model Tool API)。這些工具在聊天介面中透過特定領域功能擴充了大型語言模型 (LLM)。在代理模式 (Agent mode) 下,VS Code 可以自動使用這些工具來處理使用者提示並執行任務。

AI Toolkit Copilot 工具包含四個主要工具

  • 代理程式碼產生 (Agent Code Gen)
  • AI 模型指南 (AI Model Guide)
  • 評估程式碼產生 (Evaluation Code Gen)
  • 追蹤程式碼產生 (Tracing Code Gen)

先決條件

  1. Visual Studio Code - 支援 MCP 伺服器開發的最新版本。
  2. GitHub Copilot Visual Studio Code 擴充功能
  3. GitHub Copilot Chat Visual Studio Code 擴充功能
  4. AI Toolkit Visual Studio Code 擴充功能

在 AI Toolkit 中使用 Copilot 工具

安裝必要組件後,您可以在聊天中使用代理時,使用 AI Toolkit 提供的工具

  1. 開啟聊天視圖 ⌃⌘I (Windows, Linux Ctrl+Alt+I),並從下拉式選單中選擇 Agent (代理)

  2. 選取 Tools (工具) 按鈕以查看可用工具清單。

    您可以選擇性地勾選或取消勾選要使用的工具。您也可以透過搜尋方塊輸入關鍵字來搜尋工具。

    Screenshot showing the Chat view in Visual Studio Code with Agent mode selected. The Tools button is highlighted, displaying a list of available tools including Agent Code Gen, AI Model Guide, Evaluation Code Gen, and Tracing Code Gen.

代理程式碼產生工具 (Agent Code Gen)

「代理程式碼產生工具」協助開發人員更輕鬆地建立代理程式碼。使用此工具可快速產生適用於 AI 代理的程式碼片段與範本。這種方法能加快開發速度,並確保您的程式碼遵循 AI 代理開發的最佳實踐。

代理程式碼產生工具的主要功能

代理程式碼產生工具具備多項重要功能

  • 智慧代理程式碼產生: 此工具會根據您的需求產生代理程式碼。

  • 預設框架選擇: 若您未指定框架,該工具會自動為您選擇 Microsoft Agent Framework SDK。

    需求範例

    Create an AI app that helps me to manage travel queries.
    
  • 整合式模型指南: 該工具使用 AI 模型指南 在建置代理時提供模型詳細資訊。除非您另行選擇,否則預設會選取 GPT4.1 作為模型。

    需求範例

    Create an AI app to manage travel queries, use Microsoft Foundry models.
    
  • 支援多種代理框架功能: 該工具支援函數呼叫 (Function calling)、MCP 以及串流回應 (Streaming responses) 等多項功能。

    需求範例

    Create an AI app to check the CNN headline, use local MCP playwright to fetch CNN web page.
    
  • 工作流程支援: 該工具支援代理框架中的多種工作流程,例如順序 (Sequential)、Switch-case、迴圈 (Loop) 以及人機協作 (Human-In-The-Loop)。

    需求範例

    Build a conditional routing workflow based on email classification:
     - "Email Classifier": determines if email is spam or legitimate.
     - "Spam Handler": processes spam emails (if spam detected).
     - "Email Assistant": drafts responses for legitimate emails (if not spam).
    

AI 模型指南工具 (AI Model Guide)

「AI 模型指南工具」協助開發人員為其應用程式挑選最佳的 AI 模型。它推薦 Microsoft Foundry 與 GitHub 模型,包含最新與最熱門的模型。該工具提供輸入類型、上下文長度、成本與指標(品質、速度、安全性)等詳細資訊。它還會說明如何連接至模型,例如 GitHub 端點與權杖 (Tokens)。

此工具支援

  • 基礎模型推薦

    範例資訊提示

    Which models are specifically designed for reasoning or math tasks?
    

    在此範例中,Copilot 會從此工具收集模型資訊,並推薦 o-series 模型以處理推理或數學任務。

  • 與程式碼產生工具協作,在產生代理程式碼時提供模型選擇

    需求範例提示

    Create a quick demo AI Chat app
    

    在此範例中,Copilot 為聊天應用程式選擇了諸如免費的 GitHub GPT-4.1 模型。

  • 根據特定需求進行模型選擇

    需求範例提示

    Create an AI app to manage travel queries using a cheap and fast azure model.
    

    在此範例中,Copilot 選擇了如 MicrosoftFoundry GPT-4.1-mini 的模型。

評估程式碼產生工具 (Evaluation Code Gen)

「評估程式碼產生工具」可協助您將評估功能加入 AI 應用程式或代理中。它使用「規劃工具」(Plan tool) 來收集詳細資訊,並在產生程式碼前準備好相關資產。

評估程式碼產生工具的主要功能

評估程式碼產生工具具備四項主要功能

  • 分析與指標建議: 審查您的 AI 應用程式並建議最佳測試方式。
  • 合成查詢產生: 根據您的測試目標建立測試問題。
  • 批次應用程式執行: 使用測試問題多次執行您的應用程式並收集結果。
  • 評估程式碼產生: 使用 Azure AI Eval SDK 產生測試程式碼。

無論您的技術水平如何,這些工具都非常實用。新手開發人員可獲得關於測試與工具的指引,資深開發人員則能節省時間。「規劃工具」會協助尋找您的測試檔案或詢問其位置,使您能輕鬆地將測試加入應用程式中。

需求範例提示

  • 範例 1

    Create an evaluation for my AI travel assistant application that assesses response accuracy and user satisfaction.
    
  • 範例 2

    Measure the tool call accuracy of the agent.
    

追蹤程式碼產生工具 (Tracing Code Gen)

「追蹤程式碼產生工具」分享了將追蹤功能加入 AI 應用程式的最佳實踐。它協助開發人員輕鬆監控與偵錯 AI 代理及工作流程。此工具針對以下語言與 SDK 支援本地追蹤:

  • (Python) agent-framework, azure-ai-inference, azure-ai-agents, azure-ai-projects, openai, openai-agents, langchain, google-genai, anthropic
  • (JS/TS) azure-ai-inference, azure-ai-projects, openai, langchain, anthropic

需求範例提示

Enable tracing for my AI travel assistant application built with the agent-framework SDK in Python.

您所學到的內容

在本文章中,您學習了如何:

  • 使用 AI 工具加速應用程式開發。
  • 加入追蹤功能以監控與偵錯您的 AI 應用程式。
  • 為您的任務挑選最佳 AI 模型。
  • 將評估與測試納入您的 AI 工作流程。
© . This site is unofficial and not affiliated with Microsoft.