|
| 1 | +--- |
| 2 | +title: Order Management with Enhanced Task Completion |
| 3 | +parent: MCP |
| 4 | +grand_parent: Extensibility |
| 5 | +nav_order: 3 |
| 6 | +--- |
| 7 | + |
| 8 | +# Order Management with Enhanced Task Completion |
| 9 | + |
| 10 | +{: .warning } |
| 11 | +> **Experimental feature.** Enhanced Task Completion is an experimental capability in Copilot Studio. See the [official documentation](https://github.com/microsoft/Agents/blob/main/docs/enhanced-task-completion.md) for current status and limitations. |
| 12 | +
|
| 13 | +An end-to-end sample demonstrating Copilot Studio agents with [**Enhanced Task Completion**](https://github.com/microsoft/Agents/blob/main/docs/enhanced-task-completion.md) calling MCP servers for e-commerce order management and warehouse fulfillment, with a **Gradio chat UI** that renders tool calls, reasoning, and file attachments inline. |
| 14 | + |
| 15 | +## What is Enhanced Task Completion? |
| 16 | + |
| 17 | +Enhanced Task Completion shifts Copilot Studio from a "plan-then-execute" model to an adaptive, conversational approach. Instead of selecting all tools upfront, the agent: |
| 18 | + |
| 19 | +- **Reasons before acting** — asks clarifying questions and gathers context before calling tools |
| 20 | +- **Orchestrates tools dynamically** — recognizes dependencies between tool outputs, parallelizes independent calls, and adjusts strategy based on intermediate results |
| 21 | +- **Interleaves conversation and actions** — fluidly mixes questions, tool calls, and responses across multiple turns |
| 22 | +- **Recovers from failures** — retries or finds alternative approaches when tool calls fail |
| 23 | + |
| 24 | +This sample demonstrates all of these capabilities through a realistic e-commerce customer service scenario where the agent chains 9 tools across two MCP servers and a connected agent to answer complex multi-part questions. |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +## What's Included |
| 29 | + |
| 30 | +### Orders Agent (Copilot Studio) |
| 31 | + |
| 32 | +The primary agent with Enhanced Task Completion enabled. Handles customer inquiries by dynamically chaining tools from the Order Management MCP server. When a question involves inventory or fulfillment, it delegates to the Warehouse Agent as a connected agent. |
| 33 | + |
| 34 | +### Warehouse Agent (Copilot Studio) |
| 35 | + |
| 36 | +A connected agent invoked by the Orders Agent for warehouse and fulfillment queries. Calls tools from the Warehouse MCP server to check stock levels, track fulfillment pipeline stages, find alternative products, and look up restock dates. |
| 37 | + |
| 38 | +### Order Management MCP Server (5 tools) |
| 39 | + |
| 40 | +Node.js [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) server with interdependent tools for e-commerce order operations: |
| 41 | + |
| 42 | +| Tool | Input | Purpose | |
| 43 | +|---|---|---| |
| 44 | +| `search_orders` | Customer name/email/order# | Entry point — find orders | |
| 45 | +| `get_order` | order_id | Full order details + line items | |
| 46 | +| `get_shipment` | order_id | Tracking info (shipped/delivered only) | |
| 47 | +| `request_return` | order_id, item_skus[], reason | Initiate a return | |
| 48 | +| `get_return_status` | return_id | Check return progress | |
| 49 | + |
| 50 | +### Warehouse MCP Server (4 tools) |
| 51 | + |
| 52 | +Node.js Streamable HTTP server with interdependent tools for warehouse and fulfillment: |
| 53 | + |
| 54 | +| Tool | Input | Purpose | |
| 55 | +|---|---|---| |
| 56 | +| `check_stock` | SKU | Inventory levels + warehouse location | |
| 57 | +| `get_fulfillment_status` | order_id | Pipeline stage (received → shipped) | |
| 58 | +| `find_alternatives` | SKU | Similar products in stock | |
| 59 | +| `get_restock_date` | SKU | Next inbound shipment date | |
| 60 | + |
| 61 | +### Gradio Chat UI |
| 62 | + |
| 63 | +Python frontend that connects to the Orders Agent via the [Microsoft Agents SDK](https://github.com/microsoft/Agents-for-python) and renders the full Enhanced Task Completion activity protocol inline: |
| 64 | + |
| 65 | +- **Reasoning steps** — agent thinking displayed as collapsible accordions |
| 66 | +- **Tool calls** — grouped with parameters, duration, and results |
| 67 | +- **Intermediate messages** — agent narration between tool call batches |
| 68 | +- **File upload/download** — CSV/text files sent as base64 attachments, agent-generated files offered for download |
| 69 | +- **MSAL auth** — interactive login with persisted token cache (sign in once) |
| 70 | + |
| 71 | +### Custom Connectors |
| 72 | + |
| 73 | +Power Platform connector definitions (Swagger + apiProperties) that expose each MCP server as an action in Copilot Studio. The connectors use the `x-ms-agentic-protocol: mcp-streamable-1.0` extension to enable native MCP tool discovery. |
| 74 | + |
| 75 | +## Prerequisites |
| 76 | + |
| 77 | +- Node.js 18+ |
| 78 | +- Python 3.12+ |
| 79 | +- [Dev Tunnels CLI](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started) (`devtunnel`) |
| 80 | +- A Power Platform environment with Copilot Studio |
| 81 | +- An Entra ID app registration with `CopilotStudio.Copilots.Invoke` permission |
| 82 | + |
| 83 | +## Quick Start |
| 84 | + |
| 85 | +### 1. Install dependencies |
| 86 | + |
| 87 | +```bash |
| 88 | +node scripts/setup.mjs |
| 89 | +``` |
| 90 | + |
| 91 | +### 2. Import agents (first time only) |
| 92 | + |
| 93 | +Import `agents/solution/OrderManagementMCPDemo.zip` into your environment via **make.powerapps.com > Solutions > Import**. After import, create connections for each MCP connector from the **Custom connectors** page (no auth — just click **Create**). See [Importing the Agent Solutions](./agents/IMPORT) for details. |
| 94 | + |
| 95 | +### 3. Start MCP servers + tunnels |
| 96 | + |
| 97 | +```bash |
| 98 | +node scripts/start.mjs |
| 99 | +``` |
| 100 | + |
| 101 | +This starts both MCP servers and creates anonymous dev tunnels. Note the tunnel URLs printed: |
| 102 | + |
| 103 | +``` |
| 104 | +Order Management MCP endpoint: https://xxxxx-3000.uks1.devtunnels.ms/mcp |
| 105 | +Warehouse MCP endpoint: https://xxxxx-3001.uks1.devtunnels.ms/mcp |
| 106 | +``` |
| 107 | + |
| 108 | +### 4. Update connector URLs |
| 109 | + |
| 110 | +Each time you restart (tunnels get new URLs), update the custom connector hosts: |
| 111 | + |
| 112 | +1. Go to **make.powerapps.com** > **Custom connectors** |
| 113 | +2. Find **"orders mcp"** > click **Edit** > update the **Host** field with the order tunnel host (e.g., `xxxxx-3000.uks1.devtunnels.ms`) > click **Update connector** |
| 114 | +3. Find **"warehouse server 3"** > click **Edit** > update the **Host** field with the warehouse tunnel host (e.g., `xxxxx-3001.uks1.devtunnels.ms`) > click **Update connector** |
| 115 | + |
| 116 | +No need to republish the agents — the connectors are referenced dynamically. |
| 117 | + |
| 118 | +### 5. Start the chat UI |
| 119 | + |
| 120 | +Configure the `.env` file with your agent details (requires an Entra ID App Registration). See [Chat UI Setup](./SETUP) for step-by-step instructions. |
| 121 | + |
| 122 | +```bash |
| 123 | +cp chat-ui/.env.sample chat-ui/.env |
| 124 | +# Edit chat-ui/.env — see SETUP.md for details |
| 125 | +node scripts/start-ui.mjs |
| 126 | +``` |
| 127 | + |
| 128 | +Open http://localhost:7860 and try one of these: |
| 129 | + |
| 130 | +**Basic order lookup:** |
| 131 | +> Hi, I'm Sarah Mitchell. I ordered some Sony headphones recently but they arrived with a crackling sound in the left ear. I'd like to return them. |
| 132 | +
|
| 133 | +**Cross-server (orders + warehouse):** |
| 134 | +> I'm James Rivera. My Nintendo Switch order hasn't shipped yet. When can I expect it? If it's not available, what are my options? |
| 135 | +
|
| 136 | +**File upload — populate a CSV:** |
| 137 | +> Upload `chat-ui/data/demo-orders.csv` and ask: "Fill in all the empty columns for each order and return the completed CSV." |
| 138 | +
|
| 139 | +## Architecture |
| 140 | + |
| 141 | +```mermaid |
| 142 | +graph TB |
| 143 | + User([fa:fa-user User]) -->|chat| GradioUI |
| 144 | +
|
| 145 | + subgraph Local Machine |
| 146 | + GradioUI["Gradio Chat UI<br/>Port 7860<br/><i>Reasoning, tool calls,<br/>file upload/download</i>"] |
| 147 | + OrderMCP["Order Management<br/>MCP Server<br/><b>5 tools</b> · Port 3000"] |
| 148 | + WarehouseMCP["Warehouse<br/>MCP Server<br/><b>4 tools</b> · Port 3001"] |
| 149 | + end |
| 150 | +
|
| 151 | + subgraph Copilot Studio |
| 152 | + OrdersAgent["Orders Agent<br/><i>Enhanced Task Completion</i>"] |
| 153 | + WarehouseAgent["Warehouse Agent<br/><i>connected agent</i>"] |
| 154 | + OrdersAgent -->|invokes| WarehouseAgent |
| 155 | + end |
| 156 | +
|
| 157 | + GradioUI -->|"Agents SDK<br/>(streaming)"| OrdersAgent |
| 158 | + OrdersAgent -->|"MCP Action<br/>(via connector)"| OrderMCP |
| 159 | + WarehouseAgent -->|"MCP Action<br/>(via connector)"| WarehouseMCP |
| 160 | +``` |
0 commit comments