{"meta":{"title":"Microsoft代理框架集成","intro":"在 Microsoft Agent Framework（MAF）中将 Copilot SDK 用作代理提供程序，并结合 Azure OpenAI、Anthropic 和其他提供程序来构建多代理工作流。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/enterprise-cloud@latest/copilot","title":"GitHub Copilot"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos","title":"操作方法"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk","title":"Copilot SDK"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/integrations","title":"集成"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/integrations/microsoft-agent-framework","title":"Microsoft代理框架"}],"documentType":"article"},"body":"# Microsoft代理框架集成\n\n在 Microsoft Agent Framework（MAF）中将 Copilot SDK 用作代理提供程序，并结合 Azure OpenAI、Anthropic 和其他提供程序来构建多代理工作流。\n\n<!-- markdownlint-disable GHD046 GHD005 -->\n\n<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->\n\n## 概述\n\nMicrosoft Agent Framework 是语义内核和 AutoGen 的统一继任者。 它提供用于生成、协调和部署 AI 代理的标准接口。 借助专用集成包，可以将 Copilot SDK 客户端包装为一流的 MAF 代理，与框架中的其他任何代理提供程序互换。\n\n| 概念                | 说明                                              |\n| ----------------- | ----------------------------------------------- |\n| **Microsoft代理框架** | 用于 .NET 和 Python 的单代理和多代理编排的开源框架                |\n| **智能体提供程序**       | 为助手（如 Copilot、Azure OpenAI、Anthropic 等）提供支持的后端。 |\n| 业务流程协调程序\\*\\*\\*\\*  | 在顺序、并发或切换工作流中协调智能体的 MAF 组件                      |\n| **A2A 协议**        | 框架支持的代理到代理通信标准                                  |\n\n> \\[!NOTE]\n> MAF 集成包可用于 **.NET** 和 **Python**。 对于 TypeScript、Go、Java 和 Rust，直接使用 Copilot SDK—标准 SDK API 已经提供工具调用、流式处理和自定义代理。\n\n## 先决条件\n\n在开始之前，请确保具备：\n\n* 一个有效的所选语言的 [构建你的第一个由 Copilot 提供支持的应用](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/getting-started)\n* GitHub Copilot订阅（个人、企业或企业）\n* 已安装 Copilot CLI 或可通过 SDK 捆绑的 CLI 使用\n\n## 安装\n\n同时安装 Copilot SDK 和适用于您的编程语言的 MAF 集成包：\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```shell\ndotnet add package GitHub.Copilot.SDK\ndotnet add package Microsoft.Agents.AI.GitHub.Copilot --prerelease\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```shell\npip install copilot-sdk agent-framework-github-copilot\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n> \\[!NOTE]\n> Java SDK 没有专用 MAF 集成包。 直接使用标准 Copilot SDK——它开箱即用地提供工具调用、流式传输和自定义代理。\n\n```xml\n<!-- Maven -->\n<!-- Set copilot.sdk.version to the version published in java/README.md / Maven Central -->\n<dependency>\n    <groupId>com.github</groupId>\n    <artifactId>copilot-sdk-java</artifactId>\n    <version>${copilot.sdk.version}</version>\n</dependency>\n```\n\n</div>\n\n</div>\n\n## 基本用法\n\n使用单个方法调用将 Copilot SDK 客户端包装为 MAF 代理。 生成的代理符合框架的标准接口，可在预期 MAF 代理的任何位置使用。\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n<!-- docs-validate: skip -->\n\n```csharp\nusing GitHub.Copilot;\nusing Microsoft.Agents.AI;\n\nawait using var copilotClient = new CopilotClient();\nawait copilotClient.StartAsync();\n\n// Wrap as a MAF agent\nAIAgent agent = copilotClient.AsAIAgent();\n\n// Use the standard MAF interface\nstring response = await agent.RunAsync(\"Explain how dependency injection works in ASP.NET Core\");\nConsole.WriteLine(response);\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n<!-- docs-validate: skip -->\n\n```python\nfrom agent_framework.github import GitHubCopilotAgent\n\nasync def main():\n    agent = GitHubCopilotAgent(\n        default_options={\n            \"instructions\": \"You are a helpful coding assistant.\",\n        }\n    )\n\n    async with agent:\n        result = await agent.run(\"Explain how dependency injection works in FastAPI\")\n        print(result)\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n<!-- docs-validate: skip -->\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\nvar client = new CopilotClient();\nclient.start().get();\n\nvar session = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nvar response = session.sendAndWait(new MessageOptions()\n    .setPrompt(\"Explain how dependency injection works in Spring Boot\")).get();\nSystem.out.println(response.getData().content());\n\nclient.stop().get();\n```\n\n</div>\n\n</div>\n\n## 添加自定义工具\n\n使用自定义函数工具扩展Copilot 智能体。 当代理在 MAF 中运行时，通过标准Copilot SDK 定义的工具将自动可用。\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n<!-- docs-validate: skip -->\n\n```csharp\nusing GitHub.Copilot;\nusing Microsoft.Extensions.AI;\nusing Microsoft.Agents.AI;\n\n// Define a custom tool\nAIFunction weatherTool = CopilotTool.DefineTool(\n    (string location) => $\"The weather in {location} is sunny with a high of 25°C.\",\n    factoryOptions: new AIFunctionFactoryOptions\n    {\n        Name = \"GetWeather\",\n        Description = \"Get the current weather for a given location.\",\n    }\n);\n\nawait using var copilotClient = new CopilotClient();\nawait copilotClient.StartAsync();\n\n// Create agent with tools\nAIAgent agent = copilotClient.AsAIAgent(new AIAgentOptions\n{\n    Tools = new[] { weatherTool },\n});\n\nstring response = await agent.RunAsync(\"What's the weather like in Seattle?\");\nConsole.WriteLine(response);\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n<!-- docs-validate: skip -->\n\n```python\nfrom agent_framework.github import GitHubCopilotAgent\n\ndef get_weather(location: str) -> str:\n    \"\"\"Get the current weather for a given location.\"\"\"\n    return f\"The weather in {location} is sunny with a high of 25°C.\"\n\nasync def main():\n    agent = GitHubCopilotAgent(\n        default_options={\n            \"instructions\": \"You are a helpful assistant with access to weather data.\",\n        },\n        tools=[get_weather],\n    )\n\n    async with agent:\n        result = await agent.run(\"What's the weather like in Seattle?\")\n        print(result)\n```\n\n</div>\n\n</div>\n\n还可以将 Copilot SDK 的本机工具定义与 MAF 工具一起使用：\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient, defineTool } from \"@github/copilot-sdk\";\n\nconst getWeather = defineTool(\"GetWeather\", {\n    description: \"Get the current weather for a given location.\",\n    parameters: {\n        type: \"object\",\n        properties: {\n            location: { type: \"string\", description: \"City name\" },\n        },\n        required: [\"location\"],\n    },\n    handler: async ({ location }: { location: string }) =>\n        `The weather in ${location} is sunny, 25°C.`,\n});\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    model: \"gpt-5.4\",\n    tools: [getWeather],\n    onPermissionRequest: async () => ({ kind: \"approve-once\" }),\n});\n\nawait session.sendAndWait({ prompt: \"What's the weather like in Seattle?\" });\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.CompletableFuture;\n\nvar getWeather = ToolDefinition.create(\n    \"GetWeather\",\n    \"Get the current weather for a given location.\",\n    Map.of(\n        \"type\", \"object\",\n        \"properties\", Map.of(\n            \"location\", Map.of(\"type\", \"string\", \"description\", \"City name\")),\n        \"required\", List.of(\"location\")),\n    invocation -> {\n        var location = (String) invocation.getArguments().get(\"location\");\n        return CompletableFuture.completedFuture(\n            \"The weather in \" + location + \" is sunny, 25°C.\");\n    });\n\ntry (var client = new CopilotClient()) {\n    client.start().get();\n\n    var session = client.createSession(new SessionConfig()\n        .setModel(\"gpt-5.4\")\n        .setTools(List.of(getWeather))\n        .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n    ).get();\n\n    session.sendAndWait(new MessageOptions()\n        .setPrompt(\"What's the weather like in Seattle?\")).get();\n}\n```\n\n</div>\n\n</div>\n\n## 多代理工作流\n\nMAF 集成的主要优势在于，能够在编排式工作流中将 Copilot 与其他代理提供程序结合使用。 使用框架内置的编排器创建流水线，不同的代理负责不同的步骤。\n\n### 顺序工作流\n\n逐个运行代理，将输出从一个传递到下一个：\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n<!-- docs-validate: skip -->\n\n```csharp\nusing GitHub.Copilot;\nusing Microsoft.Agents.AI;\nusing Microsoft.Agents.AI.Orchestration;\n\nawait using var copilotClient = new CopilotClient();\nawait copilotClient.StartAsync();\n\n// Copilot agent for code review\nAIAgent reviewer = copilotClient.AsAIAgent(new AIAgentOptions\n{\n    Instructions = \"You review code for bugs, security issues, and best practices. Be thorough.\",\n});\n\n// Azure OpenAI agent for generating documentation\nAIAgent documentor = AIAgent.FromOpenAI(new OpenAIAgentOptions\n{\n    Model = \"gpt-5.4\",\n    Instructions = \"You write clear, concise documentation for code changes.\",\n});\n\n// Compose in a sequential pipeline\nvar pipeline = new SequentialOrchestrator(new[] { reviewer, documentor });\n\nstring result = await pipeline.RunAsync(\n    \"Review and document this pull request: added retry logic to the HTTP client\"\n);\nConsole.WriteLine(result);\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n<!-- docs-validate: skip -->\n\n```python\nfrom agent_framework.github import GitHubCopilotAgent\nfrom agent_framework.openai import OpenAIAgent\nfrom agent_framework.orchestration import SequentialOrchestrator\n\nasync def main():\n    # Copilot agent for code review\n    reviewer = GitHubCopilotAgent(\n        default_options={\n            \"instructions\": \"You review code for bugs, security issues, and best practices.\",\n        }\n    )\n\n    # OpenAI agent for documentation\n    documentor = OpenAIAgent(\n        model=\"gpt-5.4\",\n        instructions=\"You write clear, concise documentation for code changes.\",\n    )\n\n    # Compose in a sequential pipeline\n    pipeline = SequentialOrchestrator(agents=[reviewer, documentor])\n\n    async with pipeline:\n        result = await pipeline.run(\n            \"Review and document this PR: added retry logic to the HTTP client\"\n        )\n        print(result)\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n<!-- docs-validate: skip -->\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\n// Java uses the standard SDK directly — no MAF orchestrator needed\nvar client = new CopilotClient();\nclient.start().get();\n\n// Step 1: Code review session\nvar reviewer = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nvar review = reviewer.sendAndWait(new MessageOptions()\n    .setPrompt(\"Review this PR for bugs, security issues, and best practices: \"\n        + \"added retry logic to the HTTP client\")).get();\n\n// Step 2: Documentation session using review output\nvar documentor = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nvar docs = documentor.sendAndWait(new MessageOptions()\n    .setPrompt(\"Write documentation for these changes: \" + review.getData().content())).get();\nSystem.out.println(docs.getData().content());\n\nclient.stop().get();\n```\n\n</div>\n\n</div>\n\n### 并发工作流\n\n并行运行多个代理并聚合其结果：\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n<!-- docs-validate: skip -->\n\n```csharp\nusing GitHub.Copilot;\nusing Microsoft.Agents.AI;\nusing Microsoft.Agents.AI.Orchestration;\n\nawait using var copilotClient = new CopilotClient();\nawait copilotClient.StartAsync();\n\nAIAgent securityReviewer = copilotClient.AsAIAgent(new AIAgentOptions\n{\n    Instructions = \"Focus exclusively on security vulnerabilities and risks.\",\n});\n\nAIAgent performanceReviewer = copilotClient.AsAIAgent(new AIAgentOptions\n{\n    Instructions = \"Focus exclusively on performance bottlenecks and optimization opportunities.\",\n});\n\n// Run both reviews concurrently\nvar concurrent = new ConcurrentOrchestrator(new[] { securityReviewer, performanceReviewer });\n\nstring combinedResult = await concurrent.RunAsync(\n    \"Analyze this database query module for issues\"\n);\nConsole.WriteLine(combinedResult);\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n<!-- docs-validate: skip -->\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\nimport java.util.concurrent.CompletableFuture;\n\n// Java uses CompletableFuture for concurrent execution\nvar client = new CopilotClient();\nclient.start().get();\n\nvar securitySession = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nvar perfSession = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\n// Run both reviews concurrently\nvar securityFuture = securitySession.sendAndWait(new MessageOptions()\n    .setPrompt(\"Focus on security vulnerabilities in this database query module\"));\nvar perfFuture = perfSession.sendAndWait(new MessageOptions()\n    .setPrompt(\"Focus on performance bottlenecks in this database query module\"));\n\nCompletableFuture.allOf(securityFuture, perfFuture).get();\n\nSystem.out.println(\"Security: \" + securityFuture.get().getData().content());\nSystem.out.println(\"Performance: \" + perfFuture.get().getData().content());\n\nclient.stop().get();\n```\n\n</div>\n\n</div>\n\n## 流式响应\n\n在构建交互式应用程序时，通过流式传输代理的响应，以显示实时输出。 MAF 集成保留了 Copilot SDK 的流式传输能力。\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n<!-- docs-validate: skip -->\n\n```csharp\nusing GitHub.Copilot;\nusing Microsoft.Agents.AI;\n\nawait using var copilotClient = new CopilotClient();\nawait copilotClient.StartAsync();\n\nAIAgent agent = copilotClient.AsAIAgent(new AIAgentOptions\n{\n    Streaming = true,\n});\n\nawait foreach (var chunk in agent.RunStreamingAsync(\"Write a quicksort implementation in C#\"))\n{\n    Console.Write(chunk);\n}\nConsole.WriteLine();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n<!-- docs-validate: skip -->\n\n```python\nfrom agent_framework.github import GitHubCopilotAgent\n\nasync def main():\n    agent = GitHubCopilotAgent(\n        default_options={\"streaming\": True}\n    )\n\n    async with agent:\n        async for chunk in agent.run_streaming(\"Write a quicksort in Python\"):\n            print(chunk, end=\"\", flush=True)\n        print()\n```\n\n</div>\n\n</div>\n\n还可以直接通过没有 MAF 的 Copilot SDK 进行流式传输：\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    model: \"gpt-5.4\",\n    streaming: true,\n    onPermissionRequest: async () => ({ kind: \"approve-once\" }),\n});\n\nsession.on(\"assistant.message_delta\", (event) => {\n    process.stdout.write(event.data.deltaContent ?? \"\");\n});\n\nawait session.sendAndWait({ prompt: \"Write a quicksort implementation in TypeScript\" });\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n<!-- docs-validate: skip -->\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\nvar client = new CopilotClient();\nclient.start().get();\n\nvar session = client.createSession(new SessionConfig()\n    .setModel(\"gpt-5.4\")\n    .setStreaming(true)\n    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)\n).get();\n\nsession.on(AssistantMessageDeltaEvent.class, event -> {\n    System.out.print(event.getData().deltaContent());\n});\n\nsession.sendAndWait(new MessageOptions()\n    .setPrompt(\"Write a quicksort implementation in Java\")).get();\nSystem.out.println();\n\nclient.stop().get();\n```\n\n</div>\n\n</div>\n\n## 配置参考\n\n### MAF 代理选项\n\n| 财产                              | 类型                      | 说明           |\n| ------------------------------- | ----------------------- | ------------ |\n| `Instructions` / `instructions` | `string`                | 代理的系统提示      |\n| `Tools` / `tools`               | `AIFunction[]` / `list` | 代理可用的自定义函数工具 |\n| `Streaming` / `streaming`       | `bool`                  | 启用流式处理响应     |\n| `Model` / `model`               | `string`                | 覆盖默认模型       |\n\n### Copilot SDK 选项（直通传递）\n\n创建基础Copilot客户端时，所有标准 [构建你的第一个由 Copilot 提供支持的应用](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/getting-started) 选项仍然可用。 MAF 包装器在底层委托给 SDK：\n\n| SDK 功能                                     | MAF 支持 |\n| ------------------------------------------ | ------ |\n| 自定义工具 （`DefineTool` / `AIFunctionFactory`） |        |\n| ✅ 已与 MAF 工具合并                              |        |\n| MCP 服务器                                    |        |\n| ✅ 在 SDK 客户端上配置                             |        |\n| 自定义代理/子代理                                  |        |\n| ✅ 在 Copilot 代理中可用                          |        |\n| 无限会话                                       |        |\n| ✅ 在 SDK 客户端上配置                             |        |\n| 模型选择                                       |        |\n| ✅ 可按智能体或每次调用重写                             |        |\n| 流媒体                                        |        |\n| ✅ 完整增量事件支持                                 |        |\n\n## 最佳做法\n\n### 选择正确的集成级别\n\n当你需要在业务流程工作流中将 Copilot 与其他提供程序组合时，使用 MAF 包装器。 如果您的应用仅使用 Copilot，那么独立的 SDK 更简单，并且可让您完全掌控：\n\n```typescript\n// Standalone SDK — full control, simpler setup\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    model: \"gpt-5.4\",\n    onPermissionRequest: async () => ({ kind: \"approve-once\" }),\n});\nconst response = await session.sendAndWait({ prompt: \"Explain this code\" });\n```\n\n### 使代理保持专注\n\n生成多代理工作流时，请为每个代理提供一个具有明确说明的特定角色。 避免重叠责任：\n\n```typescript\n// ❌ Too vague — overlapping roles\nconst agents = [\n    { instructions: \"Help with code\" },\n    { instructions: \"Assist with programming\" },\n];\n\n// ✅ Focused — clear separation of concerns\nconst agents = [\n    { instructions: \"Review code for security vulnerabilities. Flag SQL injection, XSS, and auth issues.\" },\n    { instructions: \"Optimize code performance. Focus on algorithmic complexity and memory usage.\" },\n];\n```\n\n### 在业务流程级别处理错误\n\n将智能体调用包装在错误处理中，尤其是在多智能体工作流中，其中一个智能体的故障不应阻止整个管道：\n\n<!-- docs-validate: skip -->\n\n```csharp\ntry\n{\n    string result = await pipeline.RunAsync(\"Analyze this module\");\n    Console.WriteLine(result);\n}\ncatch (AgentException ex)\n{\n    Console.Error.WriteLine($\"Agent {ex.AgentName} failed: {ex.Message}\");\n    // Fall back to single-agent mode or retry\n}\n```\n\n## 另见\n\n* [构建你的第一个由 Copilot 提供支持的应用](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/getting-started)：初始Copilot SDK 设置\n* [自定义代理和子代理编排](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/features/custom-agents)：在 SDK 中定义专用子代理\n* [自定义技能](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-sdk/features/skills)：可重用的提示模块\n* [Microsoft Agent Framework 文档](https://learn.microsoft.com/en-us/agent-framework/agents/providers/github-copilot)：Copilot 提供程序的官方 MAF 文档\n* [博客：使用 GitHub Copilot SDK 和 Microsoft Agent Framework 生成 AI 代理](https://devblogs.microsoft.com/semantic-kernel/build-ai-agents-with-github-copilot-sdk-and-microsoft-agent-framework/)"}