$npx -y skills add microsoft/skills-for-copilot-studio --skill chat-sdkSend a message to a Copilot Studio agent via the Copilot Studio Client SDK (M365). Use for agents with integrated auth (Entra ID SSO). Requires an App Registration Client ID.
| 1 | # Chat via Copilot Studio SDK |
| 2 | |
| 3 | Send a single utterance to a published agent via the Copilot Studio Client SDK. Use this for agents with **integrated authentication / Entra ID SSO** (authenticationmode 2). |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
| 7 | Requires prior authentication via `/copilot-studio:test-auth`. Do NOT ask the user for a client ID yourself — the test-auth skill handles app registration setup and authentication. |
| 8 | |
| 9 | ## Instructions |
| 10 | |
| 11 | 1. Run the script with `--client-id` and the utterance from `$ARGUMENTS`: |
| 12 | |
| 13 | ```bash |
| 14 | node ${CLAUDE_SKILL_DIR}/../../scripts/chat-with-agent.bundle.js \ |
| 15 | --client-id "<clientId>" "<utterance>" [--agent-dir <path>] |
| 16 | ``` |
| 17 | |
| 18 | 2. **Authentication**: Requires prior authentication via `/copilot-studio:test-auth`. The token is cached in the `"test-agent"` slot and shared with the eval API. If auth fails or the SDK hangs, tell the caller to re-run `test-auth`. |
| 19 | |
| 20 | 3. Parse the JSON output from stdout: |
| 21 | |
| 22 | ```json |
| 23 | { |
| 24 | "status": "ok", |
| 25 | "protocol": "m365", |
| 26 | "utterance": "hello", |
| 27 | "conversation_id": "abc123-...", |
| 28 | "start_activities": [ ... ], |
| 29 | "activities": [ ... ] |
| 30 | } |
| 31 | ``` |
| 32 | |
| 33 | Display the agent's response from the `activities` array: |
| 34 | - **Text**: activities where `type === "message"` — show `text` |
| 35 | - **Suggested actions**: `suggestedActions.actions` array |
| 36 | - **Adaptive cards**: `attachments` with `contentType === "application/vnd.microsoft.card.adaptive"` |
| 37 | |
| 38 | **Save `conversation_id`** for follow-ups. |
| 39 | |
| 40 | ## Multi-turn |
| 41 | |
| 42 | Pass `--conversation-id` from the previous response: |
| 43 | |
| 44 | ```bash |
| 45 | node ${CLAUDE_SKILL_DIR}/../../scripts/chat-with-agent.bundle.js \ |
| 46 | --client-id "<id>" "<follow-up>" --conversation-id "<id>" |
| 47 | ``` |
| 48 | |
| 49 | SDK sessions do not expire as quickly as DirectLine. Reuse `conversation_id` automatically for follow-ups. |
| 50 | |
| 51 | ## Error Handling |
| 52 | |
| 53 | | Error | Cause | Resolution | |
| 54 | |-------|-------|------------| |
| 55 | | `Authentication failed` | Wrong client ID or tenant | Verify app registration and permissions | |
| 56 | | `Could not obtain conversation_id` | Agent not published or wrong config | Verify agent is published | |