AI Projects 用戶端函式庫是 Microsoft Foundry SDK 的一部分,提供對 Microsoft Foundry Project 中資源的輕鬆存取。 可用於:
-
在用戶端使用該
.agents屬性建立並執行代理程式。
-
使用專用工具強化代理人:
- 代理記憶體搜尋(預覽)
- 代理對代理 (A2A)(預覽)
- Azure AI 搜尋服務
- 必應自訂搜尋(預覽)
- Bing 綜合基礎
- 瀏覽器自動化
- 程式碼解譯器
- 計算機使用
- 檔案搜尋
- 功能工具
- 影像生成
- Microsoft Fabric(預覽版)
- 模型內容通訊協定 (MCP)
- OpenAPI
- Microsoft SharePoint(預覽)
- 網頁搜尋(預覽)
- 工具搜尋
-
使用該
.getOpenAIClient.方法取得一個 OpenAI 客戶端,與您的代理執行回應、對話、評估及微調操作。
-
使用
.agents支援工作階段的部署操作管理託管代理程式工作階段與檔案。 -
透過操作管理可重複使用的代理程式功能的
.beta.skills技能(預覽)。 -
透過 操作
.toolboxes管理工具箱,將工具分組成可重複使用的集合。 -
使用以下
.beta.memoryStores操作管理代理程式對話的記憶體儲存(預覽)。 -
使用操作
.beta.routines管理排程與派遣自動化工作流程的例程(預覽)。 -
管理模型版本(預覽), 用於建立、更新及管理自訂模型版本,使用操作
.beta.models。 -
探索更多評估工具(部分為預覽版),利用 、
.beta.evaluationTaxonomies、.beta.evaluators、.beta.insights及.beta.schedules操作,評估您的生成式 AI 應用程式.evaluationRules的效能。 -
執行 Red Team 掃描(預覽), 利用操作
.beta.redTeams識別與生成式 AI 應用程式相關的風險。 - 微調 AI 模型在你的資料上。
-
透過這些
.deployments操作列舉部署到您的 Foundry Project 的 AI 模型。 -
使用操作
.connections列舉 Foundry 專案中已連接的 Azure 資源。 -
上傳文件並建立資料集 以使用
.datasets操作來參考它們。 -
使用以下
.indexes操作建立並列舉搜尋索引。
用戶端函式庫使用 Microsoft Foundry v1 的版本 。
產品文件 | 範例 | 套件(npm) | API 參考文件 | SDK 原始碼
目錄
入門指南
先決條件
- Node.js的 LTS 版本
- Azure訂閱。
- Microsoft Foundry 的
專案。 - 一個與你的 Foundry 專案相關的 Application Insights 資源,用於代理追蹤。
- 專案端點的網址為表單
https://your-ai-services-account-name.services.ai.azure.com/api/projects/your-project-name。 它可以在你的 Microsoft Foundry Project 總覽頁面找到。 以下我們假設環境變數FOUNDRY_PROJECT_ENDPOINT被定義為承載此值。
授權
- 驗證客戶端需要 Entra ID。 您的應用程式需要實作 TokenCredential 介面的物件。 這裡的程式碼範例使用 DefaultAzureCredential。 若要讓該作業正常運作,您將需要:
- 合適的角色分配。 請參見 Microsoft Foundry 入口網站 中的
基於角色的存取控制。 角色指派可以透過 Azure 入口網站中 Azure AI Project 資源的「存取控制 (IAM)」標籤來完成。 - 已安裝 Azure CLI。
- 你登入的是 Azure 帳號,執行
az login。 - 請注意,如果你有多個 Azure 訂閱,包含 Azure AI Project 資源的訂閱必須是你的預設訂閱。 執行
az account list --output table列出您的所有訂用帳戶,並查看哪一個是預設值。 執行az account set --subscription "Your Subscription ID or Name"以變更您的預設訂用帳戶。
- 合適的角色分配。 請參見 Microsoft Foundry 入口網站 中的
安裝套件
npm install @azure/ai-projects dotenv
重要概念
用 Entra ID 建立並驗證客戶端
Entra ID 是目前客戶端唯一支援的認證方式。
若要建構 AIProjectsClient,可以從 projectEndpoint 取得 。 下面我們假設定義了環境變數 FOUNDRY_PROJECT_ENDPOINT 來保存此值:
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const projectEndpoint = process.env["FOUNDRY_PROJECT_ENDPOINT"] || "<project endpoint string>";
project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential());
預覽操作群組與選擇加入的功能旗標
部分預覽操作需要明確 foundryFeatures 的選擇加入標記。 例如:
await project.agents.createVersion(
"preview-agent",
{
kind: "workflow",
},
{ foundryFeatures: "WorkflowAgents=V1Preview" },
);
for await (const rule of project.evaluationRules.list()) {
console.log(rule.id);
}
預覽操作群組包括 .beta.voiceAgents、 .beta.skills、 .beta.memoryStores、 .beta.routines.beta.models.beta.evaluationTaxonomies.beta.evaluators.beta.insights.beta.schedules.beta.redTeams和 。 語音代理具備 GA 與預覽功能;請參閱 語音代理運作 以了解其選擇加入的要求。
用 .agentInsightMonitors 來列出分析你代理人的監視器:
for await (const monitor of project.agentInsightMonitors.list()) {
console.log(`${monitor.id}: ${monitor.agent_name}`);
}
範例
使用 OpenAI 用戶端執行回應作業
您的 Microsoft Foundry 專案可能已部署一個或多個 AI 模型。 這些模型可能是 OpenAI 模型、Microsoft 模型,或是其他供應商的模型。 使用下列程式碼從 openai 套件取得已驗證的 OpenAI,並執行聊天完成呼叫。
運行下面的代碼。 這裡我們假設 deploymentName (str) 已定義。 它是你 Foundry Project 中 AI 模型的部署名稱。 如「模型 + 端點」選項卡的「名稱」列下所示。
更多樣本,包括串流回應,請參見 package samples 中的「responses」資料夾。
const openAIClient = project.getOpenAIClient();
const response = await openAIClient.responses.create({
model: deploymentName,
input: "What is the size of France in square miles?",
});
console.log("response = ", JSON.stringify(response, null, 2));
const detailResponse = await openAIClient.responses.create({
model: deploymentName,
input: "And what is the capital city?",
previous_response_id: response.id,
});
console.log("detailed response = ", JSON.stringify(detailResponse, null, 2));
執行 Agent作
.agents上的AIProjectsClient屬性可讓您存取所有代理程式作業。 代理程式使用 OpenAI 回應通訊協定的延伸模組,因此您可能需要讓用戶端執行 OpenAI 代理程式作業,如下列範例所示。
關於設定,請參見快速入門:設定 Microsoft Foundry 資源。
const openAIClient = project.getOpenAIClient();
const agent = await project.agents.createVersion("my-agent-basic", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant that answers general questions",
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
const conversation = await openAIClient.conversations.create({
items: [
{ type: "message", role: "user", content: "What is the size of France in square miles?" },
],
});
console.log(`Created conversation with initial user message (id: ${conversation.id})`);
// Generate response using the agent
console.log("\nGenerating response...");
const response = await openAIClient.responses.create(
{
conversation: conversation.id,
},
{
body: { agent: { name: agent.name, type: "agent_reference" } },
},
);
console.log(`Response output: ${response.output_text}`);
// Add a second user message to the conversation
console.log("\nAdding a second user message to the conversation...");
await openAIClient.conversations.items.create(conversation.id, {
items: [{ type: "message", role: "user", content: "And what is the capital city?" }],
});
console.log("Added a second user message to the conversation");
// Generate second response
console.log("\nGenerating second response...");
const response2 = await openAIClient.responses.create(
{
conversation: conversation.id,
},
{
body: { agent: { name: agent.name, type: "agent_reference" } },
},
);
console.log(`Response output: ${response2.output_text}`);
// Clean up
console.log("\nCleaning up resources...");
await openAIClient.conversations.delete(conversation.id);
console.log("Conversation deleted");
await project.agents.deleteVersion(agent.name, agent.version);
console.log("Agent deleted");
語音代理操作
用於 project.agents 建立與管理語音代理程式。 選擇與您的代理程式相符的連線用戶端:
-
project.voiceAgents.realtime適用於即時與串接語音代理。 -
project.beta.voiceAgents.live適用於 GPT Live(預覽版)。
舊 project.beta.voiceAgents.realtime 路徑是同一用戶端的已棄用相容性別名。 在新程式碼中使用根路徑。 一般即時連線為 GA, 預設不會發送 VoiceAgents 預覽的加入通知。
| Scope | API 或功能 | VoiceAgents=V1Preview |
|---|---|---|
| GA | 即時/級聯定義、委派子代理與電話系統工具 project.agents |
非必要 |
| GA |
project.agents.createFromPrompt (agents:generate) |
不要寄出 |
| GA | 所有 14 個儲存的即時對話操作皆用於 project.voiceAgents.conversations;即時協定與 OpenAI 即時模型 |
非必要 |
| GA | TPE/Twilio 電話與呼叫作業清單/取得作業操作 project.voiceAgents.telephony |
非必要 |
| Conditional | 使用線上切換、SIP 傳輸目的地或 post_call |
傳球 foundryFeatures 至 connect() |
| Conditional | 電話綁定/傳輸/呼叫寫入及呼叫工作建立/取消/刪除 project.voiceAgents.telephony |
僅在使用 SIP 時通過foundryFeatures |
| 預覽版 | GPT Live 定義、委派、工作階段、儲存對話與模型 | 必須;原生 Live 並 project.beta.voiceAgents.liveConversations 內部供應 |
| 預覽版 | 線上切換設定/狀態/事件、SIP 模型及 post_call 配置/類型 |
這些預覽成員必須具備;請使用相關作業的主動加入 |
| 預覽版 | 全部七次戰役行動均為 project.beta.voiceAgents.telephony |
必須;內部供應 |
GA 作業可以接受僅有預覽成員的聯合。 選擇 Live、inline-handoff 或 SIP 成員時,或在設定 post_call時請選擇;這些成員的存在不會讓整個聯合或操作預覽完整。
對於電話寫入,請使用連線、綁定、通話或呼叫工作提供者來判斷 SIP 使用情況,而非僅僅是地址類型:SIP 連線可以使用 phone_number 來源與目的地址。 REST 追蹤範例僅接受現有的 TPE/Twilio 連線作為其可選的外撥呼叫;它並未示範 SIP 呼叫。 另外, transfer.require_handoff 是 GA 傳輸摘要設定;它本身並不啟用預覽內嵌切換。
在遷移較舊的樣本時,請將 替換為 project.agents.createFromPrompt, project.beta.voiceAgents.conversationsproject.voiceAgents.conversations並將非活動用途project.beta.voiceAgents.telephony替換project.beta.agents.createFromPrompt為 project.voiceAgents.telephony。 將他們已退休 Beta*OptionalParams 的回應類型與對話下載的回應類型替換為相應的非測試型。 將活動與 GPT Live 的運作控制在以下 project.beta.voiceAgents;請使用上述列出的根即時客戶端。
此 Node.js 範例將文字傳送給現有的即時代理程式並列印回覆。 使用不用自動問候語的客服,這樣第一個回應就是你訊息的回應。
// Ordinary Realtime sessions are GA and do not require a preview opt-in.
const connection = await project.voiceAgents.realtime.connect("<voice agent name>");
try {
await connection.sendText("Hello. Please introduce yourself briefly.");
for await (const event of connection) {
if (
event.type === "response.output_text.delta" ||
event.type === "response.output_audio_transcript.delta"
) {
process.stdout.write(event.delta);
} else if (event.type === "error") {
throw new Error(event.error.message);
} else if (event.type === "response.done") {
if (event.response.status !== "completed") {
throw new Error(`Voice response ${event.response.status}.`);
}
break;
}
}
} finally {
await connection.close();
}
用一個 for await 迴圈讀取事件。 離開迴路會關閉連線。
未知事件類型會在未中斷連線時抵達 type: "unknown" ;其原始類型位於 eventType。 在使用欄位前先驗證 rawEvent 。
畸形事件拋出 VoiceAgentProtocolError。 依照上述所示方式處理服務 error 事件。
若要保留對話,請將 agent 或 開啟 store: trueconnect(),然後使用 project.voiceAgents.conversations 來閱讀即時對話。 連接已停用代理程式失敗,出現 409 Conflict 錯誤代碼 agent_disabled。
內 嵌切換範例 顯示使用預覽設定的即時代理程式的明確選擇加入:
const connection = await project.voiceAgents.realtime.connect("<inline-handoff agent name>", {
foundryFeatures: "VoiceAgents=V1Preview",
});
await connection.close();
在 Node.js中,此選項會傳送標頭。foundry-features 瀏覽器與 React Native 會傳送等效 foundry_features 的 WebSocket 查詢參數。 請使用有型別的選項,而非保留的通用 query 參數。 預設的即時範例使用 GA 代理程式設定;對於現有具備內嵌切換、SIP 傳輸目的地或 post_call的代理程式,請如上所述選擇加入。
為你想要的任務選擇完整範例:
| 任務 | Node.js 範例 |
|---|---|
| 建立並讀取代理程式定義 | 設定語音代理 |
| 從目標產生代理 | 產生語音代理 |
| 傳送語音並儲存音訊回覆 | 即時音訊 |
| 傳送文字並處理函式呼叫 | 即時文字與工具 |
| 在不撥打電話的情況下檢查綁定與通話記錄 | 電話 |
| 將回合導向內嵌專家(預覽) | 內嵌切換 |
| 檢查即時(GA)或即時(預覽)錄影 | 對話錄音 |
| 檢查預覽活動與 GA 外撥呼叫作業 | 唯讀活動 |
預覽交接範例在建立定義並連線時會自動選擇加入。 它會建立兩個內嵌即時專家,觀察相關切換事件及目標完成的回應,然後刪除其樣本代理。 如果建立中斷,中止的 HTTP 請求不會取消伺服器端的建立:請使用記錄中的唯一代理名稱檢查是否有稍後完成的資源。 追蹤樣本是獨立的儀器導覽;基本生成、即時與 GPT Live 範例不需要設定追蹤。 設定範例預設為 GA;設定可選的通話後目的地可啟用預覽轉錄傳送,並新增定義選擇加入。 通話後傳送也支援可選的合併錄音 URL;範例不會要求來電者音訊。
儲存的對話與錄音
對話錄音範例為唯讀,並支援兩種持久化的 API 家族。 設定 FOUNDRY_AGENT_NAME 並選擇 FOUNDRY_VOICE_CONVERSATION_PROTOCOL=realtime 或 live。 即時時使用無預覽標頭的 GA project.voiceAgents.conversations 用戶端;Live 則使用 project.beta.voiceAgents.liveConversations 所需的預覽標頭。 它讀取一頁,並可利用 sample.env 中描述的變數選取精確的對話或項目。 請使用 REST 集合回傳的 ID,而非原生的 RealTime WebSocket 項目或回應 ID。 先 store: true 連線並完成錄音,再下載音訊。 樣本從不刪除儲存的對話,也不會列印來電者文字記錄。
設定 FOUNDRY_VOICE_RECORDING_OUTPUT_FILE 為選擇下載WAV檔案。 使用 FOUNDRY_VOICE_AUDIO_ITEM_ID,這會下載該項目所聽到的音訊;否則則下載合併後的立體聲錄音。 這些 WAV 檔案與串流取樣所寫的原始 PCM 檔案不同。 請將下載的來電媒體保持私密。
自帶儲存錄音必須 blob_uri 使用您自己的儲存憑證讀取;此範例不會擷取任意儲存 URL。
即時功能同時還包含回應檢查與產生但未聽見的項目音訊。 產生音訊變數需要一個中斷或截斷的項目,該項目服務產生的音訊超出所聽段落;僅僅取消並不能保證該雜訊存在。 遺失音訊會返回 404。 未完成的合併錄音可以返回 409 recording_not_ready;請依照其 Retry-After 指引行事,而非將該回應視為空白錄音。
對於儲存的 GPT Live 會話,請使用 project.beta.voiceAgents.liveConversations.
連接 project.beta.voiceAgents.live.connect() 並 store: true 持續執行 Live 連線; project.voiceAgents.realtime.connect() 採用即時通訊協定,並非 Live 連線。 以下 Node.js 範例閱讀已完成的 Live 對話,列出其儲存項目而不列印逐字稿,並儲存由 Foundry 管理的合併 WAV 錄音:
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
import { pipeline } from "node:stream/promises";
import { createWriteStream } from "node:fs";
const project = new AIProjectClient("<project endpoint>", new DefaultAzureCredential());
const agentName = "<GPT Live agent name>";
const conversationId = "<stored Live conversation ID>";
const conversations = project.beta.voiceAgents.liveConversations;
const conversation = await conversations.get(agentName, conversationId);
console.log("Conversation:", conversation.id, conversation.status);
for await (const item of conversations.listItems(agentName, conversationId)) {
console.log("Stored item:", item.id, item.type);
}
const recording = await conversations.getAudio(agentName, conversationId);
if (recording.blob_uri) {
throw new Error("Retrieve BYOS audio from blob_uri using your own storage credentials.");
}
const audio = await conversations.downloadAudio(agentName, conversationId);
if (!audio.readableStreamBody) {
throw new Error("Expected a Node.js audio stream.");
}
await pipeline(audio.readableStreamBody, createWriteStream("live-conversation.wav"));
活動操作使用預覽 project.beta.voiceAgents.telephony 用戶端。
用於 deleteCampaign() 刪除活動; deleteTelephony() 是該操作已棄用的相容性別名。
呼叫工作清單/取得操作使用 GA project.voiceAgents.telephony 用戶端,包括由預覽活動建立的工作。 活動範例僅讀取活動準備、驗證錯誤、作業監控及呼叫工作。 活動讀取需要部署時啟用這些預覽路由。
它從不建立或取消通話:活動建立時可以在準備輪詢器返回前授權撥號。 在準備過程中出現空白的驗證錯誤頁面,並不能證明活動已有效或已就緒。
自訂查詢參數
通過 query 以新增一個連線的 URL 參數。 請使用您的服務或閘道支援的名稱;以下名稱為範例:
const connection = await project.voiceAgents.realtime.connect("my-voice-agent", {
query: {
custom_key: "custom value",
custom_flag: true,
// Explicit URL transport: only use non-sensitive prompt variables.
structured_inputs: JSON.stringify({ persona: "guide" }),
},
});
await connection.close();
值可以是字串、有限數或布林值。 SDK 會對 URL 進行編碼,並在被呼叫時 connect() 擷取。 值會取代匹配的端點參數; undefined 將其移除。 這些值不會在後續連線中重複使用。
使用foundryFeatures像 、 agentVersionOverride、 和 Realtime 這樣的類型選項store,而不是在 SDK 設定中query輸入。 SDK/認證名稱、非典型結構化輸入名稱,以及以 SDK h- /Original 開頭的名稱仍保留。 即時明確允許以 JSON 物件字串使用精確 structured_inputs 金鑰,如上所示;請勿將其與 structuredInputs結合。
其他自訂查詢值不會成為提示變數。
即時 structuredInputs 保存 Node.js中基於標頭的傳輸。 瀏覽器使用 URL 查詢,因為它們無法傳送任意的 WebSocket 升級標頭。
如果您的服務需要查詢表單,請透過明確 query.structured_inputs 選擇加入,而非 structuredInputs。
切勿在查詢參數中加入秘密或敏感提示變數: 伺服器與代理存取記錄可能會保留 URL。
GPT Live 語音代理
用於 project.beta.voiceAgents.live GPT Live 代理程式。 建立代理程式時,請將 、 sub_protocol: "live"model_type: "self_deployed"、 及 model 設定為你的 GPT Live 部署名稱。 創造需要 VoiceAgents=V1Preview。
傳遞 { foundryFeatures: "VoiceAgents=V1Preview" } 至 project.agents.create() 或 createVersion()。 原生 Live 連線總是在內部傳送所需的預覽旗標;呼叫者不需要在 上 live.connect()設置旗標。
此簡短範例需要一個已設定為單聲道PCM16LE音訊且頻率為 24 kHz 的代理程式。 Live 即使在新增文字指令時也會在音訊時鐘上提前,因此範例會先靜默,直到相關確認訊息送達,然後結束工作階段。 請使用以下完整範例發送文字或語音,並閱讀回覆。
import {
AIProjectClient,
LiveServerEventLiveInstructionsAppended,
LiveServerEventLiveErrorEvent,
} from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const project = new AIProjectClient("<project endpoint>", new DefaultAzureCredential());
const connection = await project.beta.voiceAgents.live.connect("<GPT Live agent name>", {
store: false,
});
const eventId = "brief-instructions";
// Requires an agent configured for mono PCM16LE at 24 kHz.
const silence = new Uint8Array(4800); // 100 ms of audio.
let correlatedAck = false;
let serviceError: Error | undefined;
const onAppended = (event: LiveServerEventLiveInstructionsAppended): void => {
if (event.client_event_id === eventId) correlatedAck = true;
};
const onError = (event: LiveServerEventLiveErrorEvent): void => {
serviceError = new Error(event.error.message);
};
connection.on("session.instructions.appended", onAppended);
connection.on("error", onError);
try {
await connection.appendInstructions("Keep your answers brief.", { eventId });
const deadline = Date.now() + 10000;
while (!correlatedAck) {
if (serviceError) throw serviceError;
if (connection.state !== "connected") {
throw new Error(`Live connection became ${connection.state} before the instructions ACK.`);
}
if (Date.now() >= deadline) {
throw new Error("Timed out waiting for the correlated instructions ACK.");
}
await connection.sendAudio(silence);
await new Promise((resolve) => setTimeout(resolve, 100));
}
if (serviceError) throw serviceError;
} finally {
connection.off("session.instructions.appended", onAppended);
connection.off("error", onError);
await connection.close();
}
執行 GPT Live 範例
設定並 FOUNDRY_PROJECT_ENDPOINTFOUNDRY_LIVE_MODEL 。.env
請使用 部署名稱,而非模型型錄 ID。 函數範例也需要 FOUNDRY_LIVE_BACKEND_MODEL。 請參閱 sample.env 以了解這些設定及可選音訊檔案路徑。
| 任務 | Node.js 範例 |
|---|---|
| 發送問候語,並將口頭回覆列印成文字 | GPT Live text |
| 傳送語音檔案並儲存音訊回覆 | GPT Live 音訊 |
| 執行本地函式,讓代理程式說出結果 | GPT Live 函式呼叫 |
從已建置的 SDK 簽出中,執行包含 22.18 或更新版本 Node.js 範例:
node samples-dev/agents/agentVoiceLiveText.ts
每個樣本會自行建立並刪除自己的代理人。 它會列印字幕,但不會透過喇叭播放聲音。 音訊取樣使用錄製檔案而非麥克風,讀取並儲存 24 kHz 的原始單聲道PCM16LE,無需 WAV 或其他檔案標頭。
回覆後按 Enter 鍵,或按 Ctrl+C 停止。 使用量可計費,直到會話結束為止。 Live 需要持續的音訊輸入,即使是文字和工具,因此取樣在閒置時會傳送靜音。 Live 沒有語音完成的事件;完成後端回應並不代表代理已經講完。
文字範例會附加課程指示,並等待相關說明後再加入評論。 這個確認表示接受,而非完成演講;保持會議開放,直到預期回覆到來。
會話控制與事件
connect() 等待 session.started。 讀取目前的設定 connection.session,包括所選的受管理代理程式及版本(如適用)。 讀取一個迴 for await 圈的事件,或使用 on、 、 off以及 once 後續事件的監聽器。
僅供聽眾使用時,連線時可接收 onEvent 啟動事件及初始音訊,無需等待 connect() 返回。 原始啟動事件,包括服務提供的持久化對話 ID,仍可透過 connection.sessionStarted提供。 在設定回調後 onEvent 啟動的迭代器會接收後續事件,而非過去事件。
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const project = new AIProjectClient("<project endpoint>", new DefaultAzureCredential());
const connection = await project.beta.voiceAgents.live.connect("<GPT Live agent name>", {
store: true,
onEvent: (event) => {
if (event.type === "session.started") {
console.log("Conversation:", event.conversation_id);
} else if (event.type === "session.output_audio.delta") {
console.log("Received an audio chunk.");
}
},
});
try {
console.log("Session:", connection.sessionStarted.session.id);
} finally {
await connection.close();
}
| 任務 | API 或事件 |
|---|---|
| 傳送原始音訊 |
sendAudio();Live 會偵測語音邊界,因此不需要音訊緩衝提交 |
| 閱讀逐字稿 |
session.input_transcript.delta,session.output_transcript.delta |
| 接收音訊 |
session.output_audio.delta;在儲存或播放前先解碼 base64 資料 |
| 新增文字上下文,而非使用者訊息 |
appendInstructions()、appendThinking()、appendCommentary() |
| 暫停或繼續音訊處理 |
muteInputAudio(),unmuteInputAudio() |
| 更新後端設定與逐字稿觸發器 |
configureSession();初始模型、音訊格式及委派擁有者無法變更 |
| 關閉會話 |
close();等待 session.closed 並拒絕,若未確認最終決定 |
close() 並且 dispose() 在插座已經斷開時拒絕未經確認的關機。 檢查 connection.closed 服務的最終事件及任何連線錯誤。
透過回應委派,後端事件會傳送到 response.event。 用來 sendResponseItem() 新增使用者訊息並 requestResponse() 請求回覆。
對於函式呼叫,請等待呼叫後端回應完成,然後用 回 sendToolOutput() 傳結果並請求繼續。 這些方法需要 Responses 授權。 對於用戶端處理的委派,請使用 appendThinking() 或 appendCommentary() ,並將委派 ID 傳入為 delegationId。
決策上下文項目支援使用者訊息、函式呼叫與結果,以及自訂工具呼叫與結果。 以 decision.item.create;收到 decision.item.created 的事件會保留對應的項目欄位與儲存的 ID。
決策指令需要服務部署的支援。
Live 不支援即時時間。response.cancel 中止訊號是取消 SDK 連線或傳送操作,而非已產生的語音。 若要儲存即時對話,請啟用 store 並使用 project.beta.voiceAgents.liveConversations;服務部署必須支援持久性。 設定 liveOptions 為 on AIProjectClient ,以變更連線、工作階段啟動及關閉逾時。
使用儲存對話範例FOUNDRY_VOICE_CONVERSATION_PROTOCOL=live來檢查持續存在的項目或下載其 WAV 音訊。
瀏覽器驗證
使用瀏覽器憑證,例如 InteractiveBrowserCredential.。 SDK 採用原生 WebSocket 的承 live 載憑證子協定,並使用短壽命的 bearer-token 子協定,包括 Web Workers。
Node.js 改用承載標頭。 不要以 Live 子協定形式提供 realtime ,也不要在 URL 中輸入 token ,或在瀏覽器程式碼中嵌入 API 金鑰、用戶端密鑰或長效 token。
若無法使用直接瀏覽器驗證,請透過 提供已驗證的後端中繼 webSocketFactory。
即時連線會保留structuredInputsx-ms-voice-structured-inputs在 Node.js 標頭中,並在瀏覽器和工作程式中使用 structured_inputs URL 查詢。 Explicit Realtime query.structured_inputs 會在任何主機上選擇 URL 傳輸。 GPT Live 在所有主機上持續使用 URL 查詢,且沒有基於標頭的替代方案。
代理伺服器與伺服器存取記錄可以保留 URL:請勿在 URL 所載輸入中輸入憑證、個人資料或其他敏感資訊。
使用 代理工具
代理商可透過各種功能專用工具來強化。 工具依其連接需求進行組織:
內建工具
這些工具可立即運作,無需外部連接。
程式碼解譯器
在沙盒環境中撰寫並執行 Javascript 程式碼,處理檔案並處理各種資料格式。 OpenAI 文件
const openAIClient = project.getOpenAIClient();
const response = await openAIClient.responses.create({
model: deploymentName,
input: "I need to solve the equation 3x + 11 = 14. Can you help me?",
tools: [{ type: "code_interpreter", container: { type: "auto" } }],
});
console.log(`Response output: ${response.output_text}`);
完整範例代碼請見agentCodeInterpreter.ts。
檔案搜尋
內建 RAG(Retrieval-Augmented 生成)工具,利用向量儲存工具處理與搜尋文件以進行知識檢索。 OpenAI 文件
const openAIClient = project.getOpenAIClient();
const assetFilePath = path.join(
__dirname,
"..",
"samples-dev",
"agents",
"assets",
"product_info.txt",
);
const vectorStore = await openAIClient.vectorStores.create({
name: "ProductInfoStreamStore",
});
console.log(`Vector store created (id: ${vectorStore.id})`);
// Upload file to vector store
const fileStream = fs.createReadStream(assetFilePath);
const uploadedFile = await openAIClient.vectorStores.files.uploadAndPoll(
vectorStore.id,
fileStream,
);
console.log(`File uploaded to vector store (id: ${uploadedFile.id})`);
// Create agent with file search tool
const agent = await project.agents.createVersion("StreamingFileSearchAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful assistant that can search through product information and provide detailed responses. Use the file search tool to find relevant information before answering.",
tools: [
{
type: "file_search",
vector_store_ids: [vectorStore.id],
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentFileSearchStream.ts。
影像生成
根據文字提示生成圖片,並可自訂解析度、品質與風格設定:
const agent = await project.agents.createVersion("agent-image-generation", {
kind: "prompt",
model: deploymentName,
instructions: "Generate images based on user prompts",
tools: [
{
type: "image_generation",
quality: "low",
size: "1024x1024",
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
撥打 responses.create()電話後,你可以根據回覆下載檔案:
import { fileURLToPath } from "url";
const openAIClient = project.getOpenAIClient();
const agent = await project.agents.createVersion("agent-image-generation", {
kind: "prompt",
model: deploymentName,
instructions: "Generate images based on user prompts",
tools: [
{
type: "image_generation",
quality: "low",
size: "1024x1024",
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
const response = await openAIClient.responses.create(
{
input: "Generate an image of Microsoft logo.",
},
{
body: { agent: { name: agent.name, type: "agent_reference" } },
},
);
console.log(`Response created: ${response.id}`);
const imageData = response.output?.filter((output) => output.type === "image_generation_call");
if (imageData && imageData.length > 0 && imageData[0].result) {
console.log("Downloading generated image...");
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const filename = "microsoft.png";
const filePath = path.join(__dirname, filename);
// Decode base64 and save to file
const imageBuffer = Buffer.from(imageData[0].result, "base64");
fs.writeFileSync(filePath, imageBuffer);
console.log(`Image downloaded and saved to: ${path.resolve(filePath)}`);
} else {
console.log("No image data found in the response.");
}
網頁搜尋(預覽)
進行一般網路搜尋以取得網路上的最新資訊。 OpenAI 文件
const openAIClient = project.getOpenAIClient();
// Create Agent with web search tool
const agent = await project.agents.createVersion("agent-web-search", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant that can search the web",
tools: [
{
type: "web_search_preview",
user_location: {
type: "approximate",
country: "GB",
city: "London",
region: "London",
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
// Create a conversation for the agent interaction
const conversation = await openAIClient.conversations.create();
console.log(`Created conversation (id: ${conversation.id})`);
// Send a query to search the web
console.log("\nSending web search query...");
const response = await openAIClient.responses.create(
{
conversation: conversation.id,
input: "Show me the latest London Underground service updates",
},
{
body: { agent: { name: agent.name, type: "agent_reference" } },
},
);
console.log(`Response: ${response.output_text}`);
完整範例代碼請見agentWebSearch.ts。
電腦使用
使代理程式能直接與電腦系統互動,以進行任務自動化與系統操作(需要支援此 computer 工具的模型部署,例如 gpt-5.4;部署時 computer-use-preview 請使用 computer_use_preview):
const agent = await project.agents.createVersion("ComputerUseAgent", {
kind: "prompt" as const,
model: deploymentName,
instructions: `
You are a computer automation assistant.
Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see.
`.trim(),
tools: [
{
type: "computer",
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
呼叫 responses.create()後,將回應進行互動迴圈處理。 處理computer_call輸出項目並依照computer_call_output類型提供截圖computer_screenshot以持續互動。
完整範例代碼請見agentComputerUse.ts。
模型上下文協定(MCP)
整合 MCP 伺服器,以標準化工具與資源擴展代理能力。 OpenAI 文件
const openAIClient = project.getOpenAIClient();
const agent = await project.agents.createVersion("agent-mcp", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.",
tools: [
{
type: "mcp",
server_label: "api-specs",
server_url: "https://gitmcp.io/Azure/azure-rest-api-specs",
require_approval: "always",
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
// Create a conversation thread to maintain context across multiple interactions
console.log("\nCreating conversation...");
const conversation = await openAIClient.conversations.create();
console.log(`Created conversation (id: ${conversation.id})`);
// Send initial request that will trigger the MCP tool to access Azure REST API specs
// This will generate an approval request since requireApproval="always"
console.log("\nSending request that will trigger MCP approval...");
const response = await openAIClient.responses.create(
{
conversation: conversation.id,
input: "Please summarize the Azure REST API specifications Readme",
},
{
body: { agent: { name: agent.name, type: "agent_reference" } },
},
);
呼叫 responses.create()後,檢查 mcp_approval_request 回應輸出中的項目。 請 McpApprovalResponse 回覆你的核准決定,允許代理人繼續其工作。
完整範例代碼請見agentMcp.ts。
OpenAPI
呼叫由 OpenAPI 規範定義的外部 API,無需額外用戶端程式碼。 OpenAI 文件
const weatherSpecPath = path.resolve(__dirname, "../assets", "weather_openapi.json");
const agent = await project.agents.createVersion("MyOpenApiAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful assistant that can call external APIs defined by OpenAPI specs to answer user questions. When calling the weather tool, always include the query parameter format=j1.",
tools: [
{
type: "openapi",
openapi: {
name: "get_weather",
description: "Retrieve weather information for a location using wttr.in",
spec: weatherSpecPath,
auth: { type: "anonymous" },
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentOpenApi.ts。
功能工具
定義自訂函式,讓代理能與外部 API、資料庫或應用邏輯互動。 OpenAI 文件
/**
* Define a function tool for the model to use
*/
const funcTool = {
type: "function" as const,
function: {
name: "get_horoscope",
description: "Get today's horoscope for an astrological sign.",
strict: true,
parameters: {
type: "object",
properties: {
sign: {
type: "string",
description: "An astrological sign like Taurus or Aquarius",
},
},
required: ["sign"],
additional_properties: false,
},
},
};
const agent = await project.agents.createVersion("function-tool-agent", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant that can use function tools.",
tools: [funcTool],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
呼叫 responses.create()後,從回應輸出處理 function_call 項目,使用提供的參數執行函式邏輯,並將結果回 FunctionCallOutput 傳。
完整範例代碼請見agentFunctionTool.ts。
- 記憶體搜尋工具(預覽)
記憶體儲存工具會為代理加入記憶體,讓代理的 AI 模型搜尋與當前使用者提示相關的過去資訊。
這是 embeddingModelDeployment 用於建立記憶儲存與搜尋向量嵌入的模型名稱。
const memoryStoreName = "AgentMemoryStore";
const embeddingModelDeployment =
process.env["MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME"] || "<embedding model>";
const scope = "user_123";
const memoryStore = await project.beta.memoryStores.create(
memoryStoreName,
{
kind: "default",
chat_model: deploymentName,
embedding_model: embeddingModelDeployment,
options: {
user_profile_enabled: true,
chat_summary_enabled: true,
},
},
{
description: "Memory store for agent conversations",
},
);
console.log(
`Created memory store: ${memoryStore.name} (${memoryStore.id}) using chat model '${deploymentName}'`,
);
// Create an agent that will use the Memory Search tool
const agent = await project.agents.createVersion("MemorySearchAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful assistant that remembers user preferences using the memory search tool.",
tools: [
{
type: "memory_search_preview",
memory_store_name: memoryStore.name,
scope,
update_delay: 1, // wait briefly after conversation inactivity before updating memories
},
],
});
完整範例代碼請見agentMemorySearch.ts。
Connection-Based 工具
這些工具需要在你的 AI Foundry 專案中設定連線並使用 projectConnectionId。
Azure AI 搜尋服務
整合 Azure AI 搜尋服務 索引,實現強大的知識檢索與語意搜尋功能:
const aiSearchConnectionId = process.env["AI_SEARCH_CONNECTION_ID"] || "";
const aiSearchIndexName = process.env["AI_SEARCH_INDEX_NAME"] || "";
const agent = await project.agents.createVersion("MyAISearchAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful assistant. You must always provide citations for answers using the tool and render them as: `[message_idx:search_idx†source]`.",
tools: [
{
type: "azure_ai_search",
azure_ai_search: {
indexes: [
{
project_connection_id: aiSearchConnectionId,
index_name: aiSearchIndexName,
query_type: "simple",
},
],
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentAiSearch.ts。
Bing 基礎設置
地面人員回應,附有 Bing 的即時網路搜尋結果,提供 up-to日期資訊:
const bingProjectConnectionId = process.env["BING_GROUNDING_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("MyBingGroundingAgent", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant.",
tools: [
{
type: "bing_grounding",
bing_grounding: {
search_configurations: [
{
project_connection_id: bingProjectConnectionId,
},
],
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentBingGrounding.ts。
Bing 自訂搜尋(預覽)
使用自訂設定的 Bing 搜尋實例來搜尋特定網域或篩選的網頁搜尋結果:
const bingCustomSearchProjectConnectionId = process.env["BING_CUSTOM_SEARCH_CONNECTION_ID"] || "";
const bingCustomSearchInstanceName = process.env["BING_CUSTOM_SEARCH_INSTANCE_NAME"] || "";
const agent = await project.agents.createVersion("MyAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful agent that can use Bing Custom Search tools to assist users. Use the available Bing Custom Search tools to answer questions and perform tasks.",
tools: [
{
type: "bing_custom_search_preview",
bing_custom_search_preview: {
search_configurations: [
{
project_connection_id: bingCustomSearchProjectConnectionId,
instance_name: bingCustomSearchInstanceName,
},
],
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentBingCustomSearch.ts。
Microsoft Fabric(預覽版)
連接並查詢 Microsoft Fabric:
const fabricProjectConnectionId = process.env["FABRIC_PROJECT_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("MyFabricAgent", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant.",
tools: [
{
type: "fabric_dataagent_preview",
fabric_dataagent_preview: {
project_connections: [
{
project_connection_id: fabricProjectConnectionId,
},
],
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentFabric.ts。
Microsoft SharePoint(預覽)
存取並搜尋 SharePoint 文件、清單及網站以進行企業知識整合:
const sharepointProjectConnectionId = process.env["SHAREPOINT_PROJECT_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("MyAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a helpful agent that can use SharePoint tools to assist users. Use the available SharePoint tools to answer questions and perform tasks.",
// Define SharePoint tool that searches SharePoint content
tools: [
{
type: "sharepoint_grounding_preview",
sharepoint_grounding_preview: {
project_connections: [
{
project_connection_id: sharepointProjectConnectionId,
},
],
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentSharepoint.ts。
瀏覽器自動化
自動化瀏覽器互動,用於網頁爬蟲、測試及與網頁應用程式的互動:
const browserAutomationProjectConnectionId =
process.env["BROWSER_AUTOMATION_PROJECT_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("MyAgent", {
kind: "prompt",
model: deploymentName,
instructions: `You are an Agent helping with browser automation tasks.
You can answer questions, provide information, and assist with various tasks
related to web browsing using the Browser Automation tool available to you.`,
// Define Browser Automation tool
tools: [
{
type: "browser_automation",
browser_automation: {
connection: {
project_connection_id: browserAutomationProjectConnectionId,
},
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見 agentBrowserAutomation.ts。
在執行範例前,先設定 FOUNDRY_PROJECT_ENDPOINT、 FOUNDRY_MODEL_NAME、 BROWSER_AUTOMATION_PROJECT_CONNECTION_ID 和 (你的 Azure Playwright 資源的專案連線資源 ID)。 它使用 GA browser_automation 工具,根據瀏覽器結果瀏覽 https://example.com 並回報頁面標題及可見描述。 可選擇性地選擇 FOUNDRY_AGENT_NAME 代理人名稱;預設為 MyAgent。
串流範例會將每個完成的文字訊息列印一次,包括瀏覽器即時檢視的網址,並記錄遠端函式動作名稱、呼叫 ID 及參數,且不含 browserSessionId。 將即時檢視的網址視為敏感:不要分享或提交給原始碼控制。 失敗或不完整的回應會以非零狀態退出,而非回報成功。 無論回應處理成功或失敗,樣本都會刪除它在區 finally 塊中建立的代理版本。
MCP 搭配 Project Connection
利用專案特定連線來存取已連接的 MCP 伺服器的整合:
const mcpProjectConnectionId = process.env["MCP_PROJECT_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("agent-mcp-connection-auth", {
kind: "prompt",
model: deploymentName,
instructions: "Use MCP tools as needed",
tools: [
{
type: "mcp",
server_label: "api-specs",
server_url: "https://api.githubcopilot.com/mcp",
require_approval: "always",
project_connection_id: mcpProjectConnectionId,
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentMcpConnectionAuth.ts。
代理程式對代理程式(A2A)(預覽)
啟用多代理協作,讓代理能溝通並將任務委派給其他專業代理:
const a2aProjectConnectionId = process.env["A2A_PROJECT_CONNECTION_ID"] || "";
const agent = await project.agents.createVersion("MyA2AAgent", {
kind: "prompt",
model: deploymentName,
instructions: "You are a helpful assistant.",
// Define A2A tool for agent-to-agent communication
tools: [
{
type: "a2a_preview",
project_connection_id: a2aProjectConnectionId,
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentAgentToAgent.ts。
OpenAPI 與 Project 連線
透過專案連線驗證呼叫 OpenAPI 規範定義的外部 API:
const tripAdvisorProjectConnectionId = process.env["TRIPADVISOR_PROJECT_CONNECTION_ID"] || "";
function loadOpenApiSpec(specPath: string): unknown {
if (!fs.existsSync(specPath)) {
throw new Error(`OpenAPI specification not found at: ${specPath}`);
}
try {
const data = fs.readFileSync(specPath, "utf-8");
return JSON.parse(data);
} catch (error) {
throw new Error(`Failed to read or parse OpenAPI specification at ${specPath}: ${error}`);
}
}
const tripAdvisorSpecPath = path.resolve(__dirname, "../assets", "tripadvisor_openapi.json");
const tripAdvisorSpec = loadOpenApiSpec(tripAdvisorSpecPath);
const agent = await project.agents.createVersion("MyOpenApiConnectionAgent", {
kind: "prompt",
model: deploymentName,
instructions:
"You are a travel assistant that consults the TripAdvisor Content API via project connection to answer user questions about locations.",
tools: [
{
type: "openapi",
openapi: {
name: "get_tripadvisor_location_details",
description:
"Fetch TripAdvisor location details, reviews, or photos using the Content API via project connection auth.",
spec: tripAdvisorSpec,
auth: {
type: "project_connection",
security_scheme: {
project_connection_id: tripAdvisorProjectConnectionId,
},
},
},
},
],
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
完整範例代碼請見agentOpenApiConnectionAuth.ts。
欲了解所有工具的完整工作範例,請參見 samples-dev 目錄。
Evaluation
Azure AI Project 客戶端庫中的評估,提供量化、AI 輔助的品質與安全指標,用以評估效能並評估大型語言模型模型、生成式人工智慧應用與代理。 指標被定義為評估者。 內建或客製化評估器能提供全面的評估洞察。
以下程式碼展示了一些評估操作。 完整範例清單可在
const openAIClient = project.getOpenAIClient();
const dataSourceConfig = {
type: "custom" as const,
item_schema: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"],
},
include_sample_schema: true,
};
const evalObject = await openAIClient.evals.create({
name: "Agent Evaluation",
data_source_config: dataSourceConfig,
testing_criteria: [
{
type: "azure_ai_evaluator",
name: "violence_detection",
evaluator_name: "builtin.violence",
data_mapping: { query: "{{item.query}}", response: "{{item.response}}" },
} as any,
],
});
console.log(`Evaluation created (id: ${evalObject.id}, name: ${evalObject.name})`);
完整範例代碼請見agentEvaluation.ts。
部署作
以下程式碼展示了一些部署操作,允許你列舉部署到Microsoft Foundry專案中的AI模型。 這些模型可以在你的 Microsoft Foundry Project 中的「Models + endpoints」標籤中看到。 完整範例可在 package samples 的「deployment」資料夾中找到。
import { ModelDeployment } from "@azure/ai-projects";
const modelPublisher = process.env["MODEL_PUBLISHER"] || "<model publisher>";
console.log("List all deployments:");
const deployments: ModelDeployment[] = [];
const properties: Array<Record<string, string>> = [];
for await (const deployment of project.deployments.list()) {
// Check if this is a ModelDeployment (has the required properties)
if (
deployment.type === "ModelDeployment" &&
"modelName" in deployment &&
"modelPublisher" in deployment &&
"modelVersion" in deployment
) {
deployments.push(deployment);
properties.push({
name: deployment.name,
modelPublisher: deployment.modelPublisher,
modelName: deployment.modelName,
});
}
}
console.log(`Retrieved deployments: ${JSON.stringify(properties, null, 2)}`);
// List all deployments by a specific model publisher (assuming we have one from the list)
console.log(`List all deployments by the model publisher '${modelPublisher}':`);
const filteredDeployments: ModelDeployment[] = [];
for await (const deployment of project.deployments.list({
modelPublisher,
})) {
// Check if this is a ModelDeployment
if (
deployment.type === "ModelDeployment" &&
"modelName" in deployment &&
"modelPublisher" in deployment &&
"modelVersion" in deployment
) {
filteredDeployments.push(deployment);
}
}
console.log(
`Retrieved ${filteredDeployments.length} deployments from model publisher '${modelPublisher}'`,
);
// Get a single deployment by name
if (deployments.length > 0) {
const deploymentName = deployments[0].name;
console.log(`Get a single deployment named '${deploymentName}':`);
const singleDeployment = await project.deployments.get(deploymentName);
console.log(`Retrieved deployment: ${JSON.stringify(singleDeployment, null, 2)}`);
}
連接作
以下程式碼展示了一些連線操作,允許你列舉連接到 Microsoft Foundry 專案的 Azure 資源。 這些連線可在 Microsoft Foundry Project 的「Connected resources」標籤中的「管理中心」中看到。 完整取樣可在
import { Connection } from "@azure/ai-projects";
// List the details of all the connections
const connections: Connection[] = [];
const connectionNames: string[] = [];
for await (const connection of project.connections.list()) {
connections.push(connection);
connectionNames.push(connection.name);
}
console.log(`Retrieved connections: ${connectionNames}`);
// Get the details of a connection, without credentials
const connectionName = connections[0].name;
const connection = await project.connections.get(connectionName);
console.log(`Retrieved connection ${JSON.stringify(connection, null, 2)}`);
const connectionWithCredentials = await project.connections.getWithCredentials(connectionName);
console.log(
`Retrieved connection with credentials ${JSON.stringify(connectionWithCredentials, null, 2)}`,
);
// List all connections of a specific type
const azureAIConnections: Connection[] = [];
for await (const azureOpenAIConnection of project.connections.list({
connectionType: "AzureOpenAI",
defaultConnection: true,
})) {
azureAIConnections.push(azureOpenAIConnection);
}
console.log(`Retrieved ${azureAIConnections.length} Azure OpenAI connections`);
// Get the details of a default connection
const defaultConnection = await project.connections.getDefault("AzureOpenAI", {
includeCredentials: true,
});
console.log(`Retrieved default connection ${JSON.stringify(defaultConnection, null, 2)}`);
數據集作
下面的代碼展示了一些 Dataset作。 完整樣本可在 package samples 的「datasets」資料夾中找到。
本地檔案系統上傳(project.datasets.uploadFile、 project.datasets.uploadFolder、 project.beta.models.create和 )僅支援於 Node.js。 瀏覽器應用程式可以匯入 AIProjectClient 、 VoiceAgentRealtimeClient 從資料集及模型 @azure/ai-projects REST 操作,無需 Node.js 檔案系統多重填充。
import { DatasetVersionUnion } from "@azure/ai-projects";
const VERSION1 = "1.0";
const VERSION2 = "2.0";
const VERSION3 = "3.0";
// sample files to use in the demonstration
const sampleFolder = "sample_folder";
// Create a unique dataset name for this sample run
const datasetName = `sample-dataset-basic`;
console.log("Upload a single file and create a new Dataset to reference the file.");
console.log("Here we explicitly specify the dataset version.");
const dataset1 = await project.datasets.uploadFile(
datasetName,
VERSION1,
path.join(__dirname, sampleFolder, "sample_file1.txt"),
);
console.log("Dataset1 created:", JSON.stringify(dataset1, null, 2));
const credential = project.datasets.getCredentials(dataset1.name, dataset1.version, {});
console.log("Credential for the dataset:", credential);
console.log(
"Upload all files in a folder (including subfolders) to the existing Dataset to reference the folder.",
);
console.log("Here again we explicitly specify a new dataset version");
const dataset2 = await project.datasets.uploadFolder(
datasetName,
VERSION2,
path.join(__dirname, sampleFolder),
);
console.log("Dataset2 created:", JSON.stringify(dataset2, null, 2));
console.log(
"Upload a single file to the existing dataset, while letting the service increment the version",
);
const dataset3 = await project.datasets.uploadFile(
datasetName,
VERSION3,
path.join(__dirname, sampleFolder, "sample_file2.txt"),
);
console.log("Dataset3 created:", JSON.stringify(dataset3, null, 2));
console.log("Get an existing Dataset version `1`:");
const datasetVersion1 = await project.datasets.get(datasetName, VERSION1);
console.log("Dataset version 1:", JSON.stringify(datasetVersion1, null, 2));
console.log(`Listing all versions of the Dataset named '${datasetName}':`);
const datasetVersions = project.datasets.listVersions(datasetName);
for await (const version of datasetVersions) {
console.log("List versions:", version);
}
console.log("List latest versions of all Datasets:");
const latestDatasets = project.datasets.list();
for await (const dataset of latestDatasets) {
console.log("List datasets:", dataset);
}
// List the details of all the datasets
const datasets = project.datasets.listVersions(datasetName);
const allDatasets: DatasetVersionUnion[] = [];
for await (const dataset of datasets) {
allDatasets.push(dataset);
}
console.log(`Retrieved ${allDatasets.length} datasets`);
console.log("Delete all Datasets created above:");
await project.datasets.delete(datasetName, VERSION1);
await project.datasets.delete(datasetName, VERSION2);
await project.datasets.delete(datasetName, dataset3.version);
console.log("All specified Datasets have been deleted.");
檔案作業
下面的程式碼展示了一些使用 OpenAI 用戶端的檔案操作,這些操作允許您上傳、檢索、列出和刪除檔案。 這些操作對於處理可用於微調和其他 AI 模型操作的檔案非常有用。 完整取樣可在 package samples 的「files」資料夾中找到。
const openAIClient = project.getOpenAIClient();
console.log("Uploading file");
const created = await openAIClient.files.create({
file: fs.createReadStream(filePath),
purpose: "fine-tune",
});
console.log(`Uploaded file with ID: ${created.id}`);
const uploadedFile = await openAIClient.files.retrieve(created.id);
console.log("Processed file metadata:\n", JSON.stringify(uploadedFile, null, 2));
console.log(`Retrieving file content with ID: ${uploadedFile.id}`);
const contentResponse = await openAIClient.files.content(uploadedFile.id);
const buf = Buffer.from(await contentResponse.arrayBuffer());
console.log(buf.toString("utf-8"));
// 4) List all files
console.log("Listing all files:");
const filesList = await openAIClient.files.list();
for (const f of filesList.data ?? []) {
console.log(JSON.stringify(f));
}
// 5) Delete the file
console.log(`Deleting file with ID: ${uploadedFile.id}`);
const deleted = await openAIClient.files.delete(uploadedFile.id);
console.log(
`Successfully deleted file: ${deleted?.id || uploadedFile.id}, deleted=${String(deleted?.deleted ?? true)}`,
);
索引作
下面的代碼顯示了一些 Indexes作。 完整取樣可在 package samples 的「indexes」資料夾中找到。
import { AzureAISearchIndex } from "@azure/ai-projects";
const indexName = "sample-index";
const version = "1";
const azureAIConnectionConfig: AzureAISearchIndex = {
name: indexName,
type: "AzureSearch",
version,
indexName,
connectionName: "sample-connection",
};
// Create a new Index
const newIndex = await project.indexes.createOrUpdate(indexName, version, azureAIConnectionConfig);
console.log("Created a new Index:", newIndex);
console.log(`Get an existing Index version '${version}':`);
const index = await project.indexes.get(indexName, version);
console.log(index);
console.log(`Listing all versions of the Index named '${indexName}':`);
const indexVersions = project.indexes.listVersions(indexName);
for await (const indexVersion of indexVersions) {
console.log(indexVersion);
}
console.log("List all Indexes:");
const allIndexes = project.indexes.list();
for await (const i of allIndexes) {
console.log("Index:", i);
}
console.log("Delete the Index versions created above:");
await project.indexes.delete(indexName, version);
微調操作
以下程式碼展示了如何使用 OpenAI 客戶端建立微調工作。 這些操作支援各種微調技術,如監督 Fine-Tuning(SFT)、強化 Fine-Tuning(RFT)及直接效能優化(DPO)。 完整取樣可在 package samples 的「finetuning」資料夾中找到。
import { JobCreateParams } from "openai/resources/fine-tuning/jobs";
const trainingFilePath = "training_data_path.jsonl";
const validationFilePath = "validation_data_path.jsonl";
const openAIClient = project.getOpenAIClient();
// 1) Create the training and validation files
const trainingFile = await openAIClient.files.create({
file: fs.createReadStream(trainingFilePath),
purpose: "fine-tune",
});
console.log(`Uploaded file with ID: ${trainingFile.id}`);
const validationFile = await openAIClient.files.create({
file: fs.createReadStream(validationFilePath),
purpose: "fine-tune",
});
console.log(`Uploaded file with ID: ${validationFile.id}`);
// 2) Wait for the files to be processed
await openAIClient.files.waitForProcessing(trainingFile.id);
await openAIClient.files.waitForProcessing(validationFile.id);
console.log("Files processed.");
// 3) Create a supervised fine-tuning job
const fineTuningJob = await openAIClient.fineTuning.jobs.create({} as JobCreateParams, {
body: {
trainingType: "Standard",
training_file: trainingFile.id,
validation_file: validationFile.id,
model: deploymentName,
method: {
type: "supervised",
supervised: {
hyperparameters: {
n_epochs: 3,
batch_size: 1,
learning_rate_multiplier: 1.0,
},
},
},
},
});
console.log("Created fine-tuning job:\n", JSON.stringify(fineTuningJob));
代理程式會話操作
用於 project.agents 管理託管代理程式的工作階段及工作階段檔案。
會話提供隔離的沙盒環境,供代理互動使用。 此範例需要支援工作階段操作的託管代理程式部署。
import { VersionRefIndicator } from "@azure/ai-projects";
const agentName = "MySessionAgent";
// Create a session for the agent
const versionIndicator: VersionRefIndicator = {
type: "version_ref",
agent_version: "1.0",
};
const session = await project.agents.createSession(agentName, versionIndicator);
console.log(`Session created: ${session.agent_session_id}`);
// Upload a file to the session sandbox
const filePath = "/sandbox/hello.txt";
const fileContent = new TextEncoder().encode("Hello from the agent sessions sample!");
const uploadResult = await project.agents.uploadSessionFile(
agentName,
session.agent_session_id,
filePath,
fileContent,
);
console.log(`Uploaded file: ${uploadResult.path} (${uploadResult.bytes_written} bytes)`);
請參閱完整範例程式碼 agentSessions.ts 及相應 筆記本。
技能操作(預覽)
這些 .beta.skills 操作讓你能創建並管理定義代理能力的可重複使用技能。
const skillName = "sample-skill";
// Create a new skill
const created = await project.beta.skills.create(skillName, {
inlineContent: {
description: "Example skill created by the @azure/ai-projects sample.",
instructions: "You are a helpful assistant that answers questions concisely.",
metadata: { owner: "sample" },
},
});
console.log(`Skill created: ${created.name} (id: ${created.skill_id})`);
// Retrieve the skill
const fetched = await project.beta.skills.get(skillName);
console.log(`Retrieved skill: ${fetched.name} (id: ${fetched.id})`);
完整範例代碼請見skillBasic.ts。
工具箱操作(預覽)
這些 .toolboxes 操作讓你能建立和管理工具箱——可重複使用的工具集合,能在代理人間共享。
import { ToolUnion, MCPTool } from "@azure/ai-projects";
const toolboxName = "mcp";
// Define tools for the toolbox
const tools: ToolUnion[] = [
{
type: "mcp",
server_label: "api_specs",
server_url: "https://github.com/Azure/azure-rest-api-specs",
require_approval: "never",
} satisfies MCPTool,
];
// Create a new toolbox version
const created = await project.toolboxes.createVersion(toolboxName, tools, {
description: "Example toolbox created by the @azure/ai-projects sample.",
metadata: { status: "created" },
});
console.log(`Toolbox: ${created.name} (tools: ${created.tools.length})`);
// Retrieve the toolbox
const fetched = await project.toolboxes.get(toolboxName);
console.log(`Retrieved toolbox: ${fetched.name} (${fetched.id})`);
完整範例代碼請見toolboxesCrud.ts。
追蹤
實驗性特徵閘
重要說明: 生成式AI追蹤儀器是一項實驗性預覽功能。 跨度、屬性和事件可能會在未來的版本中進行修改。 要使用它,你必須明確選擇加入,方法是在建tracingOptions構 時傳遞 experimental: true ,AIProjectClient或設定環境變數:
AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING=true
只有在檢視需求並了解追蹤行為未來版本可能會改變後,才啟用此功能。
開始描摹
你可以將 Microsoft Foundry 專案新增 Application Insights Azure 資源。 如果啟用了,你可以取得 Application Insights 的 連接字串,設定你的 AI 專案客戶端,並在 Azure 監視器 中觀察追蹤。 通常,您可能想要在建立用戶端或代理程式之前開始追蹤。
Installation
要向 Azure 監視器 發送 traces:
npm install @azure/monitor-opentelemetry @opentelemetry/api
列印到主控台的追蹤(對本地開發很有用):
npm install @opentelemetry/sdk-trace-node @opentelemetry/api
如何啟用追蹤
追蹤是透過傳遞 tracingOptions 給 AIProjectClient 建構子來實現的。 若 tracingOptions 未提供,生成式 AI 追蹤將完全停用,且不會輸出生成式 AI 的跨度或指標。 此設定僅控制 GenAI 專屬的追蹤(模型呼叫、代理操作、令牌使用等語意慣例範圍)。 追蹤設定適用於透過該特定用戶端實例執行的所有操作,包括代理操作及透過 project.getOpenAIClient()取得的任何 OpenAI 用戶端。 不同的客戶端實例可以有獨立的追蹤設定。
import { DefaultAzureCredential } from "@azure/identity";
import { AIProjectClient } from "@azure/ai-projects";
const endpoint = process.env["FOUNDRY_PROJECT_ENDPOINT"] || "<project endpoint>";
const credential = new DefaultAzureCredential();
// Tracing enabled
const project = new AIProjectClient(endpoint, credential, {
tracingOptions: { experimental: true },
});
// Tracing disabled (default — no tracingOptions passed)
const projectNoTrace = new AIProjectClient(endpoint, credential);
console.log(project, projectNoTrace);
傳遞 tracingOptions: {} (空物件)也可啟動追蹤——此時所有個別設定皆由對應環境變數解析。
該 tracingOptions 物件接受以下性質:
| Option | 環境變數 | Default | Description |
|---|---|---|---|
experimental |
AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING |
false |
承認此特性的實驗性質(發射跨度所必需) |
contentRecording |
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT |
false |
在 traces 中擷取提示與完成內容 |
traceContextPropagation |
AZURE_TRACING_GEN_AI_ENABLE_TRACE_CONTEXT_PROPAGATION |
true |
將 W3C 追蹤上下文標頭注入請求中 |
每個選項依以下優先順序解決:
-
明確值 (
tracingOptions最高優先權) - 環境變數 (當選項省略或未定義時勾選)
- 預設值 (當兩者皆未設定或環境變數無法讀取時使用)
注意: 由於目前所有追蹤特徵仍處於實驗階段,
experimental: true因此也必須設定(無論是明示或透過環境變數)才能產生任何範圍。
語音代理追蹤
註冊 OpenTelemetry 提供者與匯出器,然後設定 tracingOptions: { experimental: true } 為 AIProjectClient。 這會追蹤語音代理程式的生成、電話變更、對話刪除,以及即時會話與回應。
不需要另外的語音代理追蹤標記。
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const project = new AIProjectClient("<project endpoint>", new DefaultAzureCredential(), {
tracingOptions: {
experimental: true,
contentRecording: false,
},
});
const connection = await project.voiceAgents.realtime.connect("<voice agent name>");
try {
await connection.sendText("Hello.");
for await (const event of connection) {
if (event.type === "error") {
throw new Error(event.error.message);
}
if (event.type === "response.done") {
if (event.response.status !== "completed") {
throw new Error(`Voice response ${event.response.status}.`);
}
break;
}
}
} finally {
await connection.close();
}
即時記錄的是每個回應的會話長度、連線長度,以及每個回應的長度, invoke_agent 而不是每個音訊區塊。 這些包括狀態、令牌使用量以及音訊位元組數。
首次音訊延遲是從回應建立到接收的過程來衡量,而非使用者語音或喇叭播放。 服務 ID 會顯示在追蹤圖中,而非指標維度。
REST 並 project.voiceAgents.realtime 分享專案的追蹤設定。
獨立構造 VoiceAgentRealtimeClient 的不會繼承這些元素。
輸入摘要描述的是最新的輸入,而非完整的對話歷史。
內容錄製預設為關閉狀態。 僅在您打算記錄文字、逐字稿及工具參數/結果(可能包含敏感資料)時啟用 contentRecording: true 。
原始媒體、憑證、查詢值、電話號碼、SDP 以及原始錯誤/結束訊息不會被記錄。 讀取/列表操作使用現有的 HTTP 管線追蹤。
Azure 監視器 tracing
這裡有一個範例程式碼,展示如何啟用 Azure 監視器 追蹤功能:
import { useAzureMonitor } from "@azure/monitor-opentelemetry";
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const projectEndpoint = process.env["FOUNDRY_PROJECT_ENDPOINT"] || "<project endpoint>";
// Configure Azure Monitor tracing (must be done before creating the client)
const connectionString =
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<connection string>";
useAzureMonitor({
azureMonitorExporterOptions: { connectionString },
samplingRatio: 1,
tracesPerSecond: 0,
});
// Create client with tracing enabled (experimental)
const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential(), {
tracingOptions: {
experimental: true,
contentRecording: false,
traceContextPropagation: true,
},
});
你也可以為你的情境建立一個跨度:
import { trace, context } from "@opentelemetry/api";
const tracer = trace.getTracer("MyScenario");
const span = tracer.startSpan("myOperation");
const ctx = trace.setSpan(context.active(), span);
await context.with(ctx, async () => {
// Your agent operations here
});
span.end();
完整範例程式碼請見 agentBasicWithAzureMonitorTracing.ts。
主機追蹤
在本地開發時,你可以列印到控制台的痕跡:
import {
NodeTracerProvider,
SimpleSpanProcessor,
ConsoleSpanExporter,
} from "@opentelemetry/sdk-trace-node";
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
// Set up OpenTelemetry with a console exporter (must be done before creating the client)
const provider = new NodeTracerProvider({
spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())],
});
provider.register();
// Create client with tracing enabled (experimental)
const projectEndpoint = process.env["FOUNDRY_PROJECT_ENDPOINT"] || "<project endpoint>";
const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential(), {
tracingOptions: {
experimental: true,
contentRecording: false,
traceContextPropagation: true,
},
});
完整範例程式碼請見 agentBasicWithConsoleTracing.ts。
啟用內容錄製
內容記錄控制訊息內容及工具呼叫細節(如參數與回傳值)是否被記錄在追蹤中。 這些資料可能包含敏感的使用者資訊。
要啟用內容錄製,請 contentRecording: true 在建構客戶端時傳遞進 tracingOptions 去,或將環境變數 OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT 設為 true。 內容錄製預設為 false。
啟用追蹤上下文傳播
追蹤上下文傳播允許客戶端的跨度與 Azure、OpenAI 及其他 Azure 服務的伺服器端跨度相關聯。 啟用後,SDK 會自動將 W3C 追蹤上下文標頭(traceparent 和 tracestate)注入到 OpenAI 用戶端 project.getOpenAIClient()透過 取得的 HTTP 請求中。
這確保分散式追蹤中的所有操作共用相同的追蹤 ID,提供對應用及 Azure 服務的端對端可視性,並能在可觀察性後端實現。
預設啟用了追蹤上下文傳播。 要停用它,請 traceContextPropagation: false 在建構客戶端時傳遞進 tracingOptions 去,或將環境變數 AZURE_TRACING_GEN_AI_ENABLE_TRACE_CONTEXT_PROPAGATION 設為 false。
重要的安全與隱私考量:
- 追蹤 ID:啟用追蹤上下文傳播時,追蹤 ID 會傳送至 Azure OpenAI 及其他外部服務。
- 請求關聯:追蹤 ID 允許 Azure 服務在多個 API 呼叫中關聯來自同一工作階段或使用者的請求,這可能會根據您的使用情境帶來隱私影響。
只有在仔細檢視你的可觀察性、隱私和安全需求後,才啟用追蹤上下文傳播。
故障排除
例外狀況
進行服務呼叫的用戶端方法會針對來自服務的非成功 HTTP 狀態代碼回應,引發 RestError。 例外狀況的 code 會保存 HTTP 回應狀態代碼。 例外狀況的 error.message 包含詳細的訊息,可能有助於診斷問題:
import { isRestError } from "@azure/core-rest-pipeline";
try {
const result = await project.connections.list();
} catch (e) {
if (isRestError(e)) {
console.log(`Status code: ${e.code}`);
console.log(e.message);
} else {
console.error(e);
}
}
例如,當您提供錯誤的認證時:
Status code: 401 (Unauthorized)
Operation returned an invalid status 'Unauthorized'
報告問題
若要回報客戶端函式庫的問題或申請額外功能,請開啟GitHub期 here
下一步
可以看看 package samples 資料夾,裡面有完全可執行的程式碼。
從 TypeSpec(維護者)重新生成
此封裝是根據 Azure/azure-rest-api-specs 的 TypeSpec 規範重新生成的。 這六個重生階段及其分配的議題編排器會以技能編碼在 .github/skills/ 下,並可由 GitHub Copilot 的編碼代理任務端對端驅動。
倉庫層級ai-projects-regen的自訂代理程式只是 GitHub 發現的入口。 問題指派的工作流程由 package-local run-issue-regeneration 技能擁有。
要從某一議題開始工作流程,請在議題描述中為每個必需標籤精確包含一個值:
TypeSpec commit: <40-character-lowercase-SHA>
Base branch: <branch>
將問題指派給 Copilot,選擇ai-projects-regen自訂代理,並選擇描述中相同的起始分支。 當任一值缺失或無效時,代理會在進行變更前停止。
要派遣 regen 作為雲端代理任務,請從以下目錄執行:
pwsh -NoProfile -File ./scripts/start-cloud-regen.ps1 # latest commit on feature/foundry-release
pwsh -NoProfile -File ./scripts/start-cloud-regen.ps1 -TspCommit <sha> # pin a specific commit
pwsh -NoProfile -File ./scripts/start-cloud-regen.ps1 -DryRun # render the prompt locally, do not dispatch
pwsh -NoProfile -File ./scripts/start-cloud-regen.ps1 -Repo myuser/azure-sdk-for-js -Follow # smoke-test on a fork
在 Windows 上,直接呼叫腳本(例如
./scripts/start-cloud-regen.ps1)可能會被預設的Restricted執行策略阻擋。 上面的pwsh -NoProfile -File ...表格避開了這點。 或者,執行Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned一次以允許本地腳本。
Prerequisites:
-
ghCLI 已gh auth login安裝並驗證目標儲存庫()。 這個agent-task子指令目前還在預覽階段,需要最近的gh。 - 在目標倉庫啟用 GitHub Copilot 編碼代理程式的組織中。
- 推送存取目標倉庫(雲端代理使用自己的 GitHub App 身份推送並開啟草擬 PR)。
注意:派遣的提示符會在任務開始時執行 pnpm install --filter "@azure/ai-projects..." 並 pnpm turbo build --filter="@azure/ai-projects..." --token 1 內聯執行。 如果雲端代理的沙箱阻擋了這些網路通話,該任務在設定時就會失敗;在這種情況下,可以在本地執行技能,或與 SDK 建置團隊協調,在 repo 根節點新增集中管理 copilot-setup-steps.yml 的工作流程。
參與
此項目歡迎參與和建議。 大部分的捐款都要求您同意「參與者許可協定」(CLA),宣告您有權,而且實際上確實會授與我們使用您貢獻的許可權。 如需詳細資訊,請瀏覽 https://cla.microsoft.com。
當您提交提取要求時,CLA-Bot 會自動判斷您是否需要提供 CLA 並適當裝飾 PR(例如標籤、批註)。 只要遵循 Bot 所提供的指示即可。 您只需要使用我們的 CLA 在所有存放庫上執行此動作一次。
本專案已採用Microsoft開源行為準則。 如需詳細資訊,請參閱《管理辦法》常見問題或連絡 opencode@microsoft.com,以取得任何其他問題或意見。