Copilot Studio 整合讓你能在 Agent Framework 中使用 Copilot Studio 代理。
以下範例展示了如何使用 Copilot Studio 建立代理:
using System;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.CopilotStudio;
// Create a Copilot Studio agent using the IChatClient pattern
// Requires: dotnet add package Microsoft.Agents.AI.CopilotStudio --prerelease
var copilotClient = new CopilotStudioChatClient(
environmentId: "<your-environment-id>",
agentIdentifier: "<your-agent-id>",
credential: new AzureCliCredential());
AIAgent agent = copilotClient.AsAIAgent(
instructions: "You are a helpful enterprise assistant.");
Console.WriteLine(await agent.RunAsync("What are our company policies on remote work?"));
Tools
Copilot Studio 代理程式可遠端執行:代理定義(主題、知識來源、生成動作、外掛、MCP 伺服器)皆由 Copilot Studio 入口網站撰寫。 代理框架Copilot Studio用戶端會呼叫已發佈代理並呈現其回應——它會在用戶端not 暴露代理框架的工具類型(函式工具、程式碼直譯器、檔案搜尋、託管/本地 MCP 等)。 若要擴充代理的功能,請在 Copilot Studio 代理本身上設定這些功能。
備註
套件中提供 agent-framework-copilotstudio Copilot Studio 代理的 Python 支援。
Installation
pip install agent-framework-copilotstudio --pre
Configuration
設定以下環境變數以進行自動設定:
COPILOTSTUDIOAGENT__ENVIRONMENTID="<your-environment-id>"
COPILOTSTUDIOAGENT__SCHEMANAME="<your-agent-schema-name>"
COPILOTSTUDIOAGENT__AGENTAPPID="<your-client-id>"
COPILOTSTUDIOAGENT__TENANTID="<your-tenant-id>"
建立 Copilot Studio 代理
CopilotStudioAgent 自動讀取環境變數中的連線設定:
import asyncio
from agent_framework.microsoft import CopilotStudioAgent
async def main():
agent = CopilotStudioAgent()
result = await agent.run("What are our company policies on remote work?")
print(result)
asyncio.run(main())
Tools
CopilotStudioAgent 會呼叫一個遠端執行的 Copilot Studio 代理。 代理的行為——主題、知識來源、生成動作、外掛、MCP 伺服器——都是在 Copilot Studio 入口網站中設定的,而不是在你的 Python 程式碼中。 代理框架用戶端 不會 在用戶端暴露代理框架的工具類型(函式工具、程式碼直譯器、檔案搜尋、託管/本地 MCP 等)。 若要擴充代理的功能,請在 Copilot Studio 代理本身上設定這些功能。
串流
async def streaming_example():
agent = CopilotStudioAgent()
print("Agent: ", end="", flush=True)
async for chunk in agent.run("What is the largest city in France?", stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
print()