{"record":{"id":"fee45da442c25d41","repo":"microsoft/semantic-kernel","slug":"conversation-id-not-found-in-start-response","errorCode":null,"errorMessage":"Conversation ID not found in start response.","messagePattern":"Conversation ID not found in start response\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/samples/demos/copilot_studio_agent/src/direct_line_agent.py","lineNumber":192,"sourceCode":"        if not self.directline_token:\n            await self._fetch_token_and_conversation()\n\n        headers = {\n            \"Authorization\": f\"Bearer {self.directline_token}\",\n            \"Content-Type\": \"application/json\",\n        }\n\n        # Step 2: Start a conversation if one hasn't already been started.\n        if not self.conversation_id:\n            start_conv_url = f\"{self.bot_endpoint}/conversations\"\n            async with self.session.post(start_conv_url, headers=headers) as resp:\n                if resp.status not in (200, 201):\n                    logger.error(\"Failed to start conversation. Status: %s\", resp.status)\n                    raise AgentInvokeException(\"Failed to start conversation.\")\n                conv_data = await resp.json()\n                self.conversation_id = conv_data.get(\"conversationId\")\n                if not self.conversation_id:\n                    raise AgentInvokeException(\"Conversation ID not found in start response.\")\n\n        # Step 3: Post the message payload.\n        activities_url = f\"{self.bot_endpoint}/conversations/{self.conversation_id}/activities\"\n        async with self.session.post(activities_url, json=payload, headers=headers) as resp:\n            if resp.status != 200:\n                logger.error(\"Failed to post activity. Status: %s\", resp.status)\n                raise AgentInvokeException(\"Failed to post activity.\")\n            _ = await resp.json()  # Response from posting activity is ignored.\n\n        # Step 4: Poll for new activities using watermark until DynamicPlanFinished event is found.\n        finished = False\n        collected_data = None\n        watermark = None\n        while not finished:\n            url = activities_url if watermark is None else f\"{activities_url}?watermark={watermark}\"\n            async with self.session.get(url, headers=headers) as resp:\n                if resp.status == 200:\n                    data = await resp.json()","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/demos/copilot_studio_agent/src/direct_line_agent.py#L174-L210","documentation":"An AgentInvokeException raised when the conversation-start call succeeds (200/201) but the JSON response lacks a 'conversationId' field. Without a conversation id the activities URL cannot be constructed, so posting is impossible. This is a malformed-success-response condition.","triggerScenarios":"POST /conversations returns 200/201 with a body like {} or {'id': ...} where the key isn't 'conversationId'.","commonSituations":"DirectLine API version returns a differently-named id field; a gateway altered the response; the endpoint isn't actually DirectLine.","solutions":["Log the full conv_data to find the real conversation id field name.","Confirm the endpoint is DirectLine v3 (which returns conversationId).","If the key differs, adapt the parsing to read the correct field."],"exampleFix":"// before\nself.conversation_id = conv_data.get(\"conversationId\")\nif not self.conversation_id:\n    raise AgentInvokeException(\"Conversation ID not found in start response.\")\n\n// after\nself.conversation_id = conv_data.get(\"conversationId\") or conv_data.get(\"id\")\nif not self.conversation_id:\n    logger.error(\"Start-conversation body: %s\", conv_data)\n    raise AgentInvokeException(\"Conversation ID not found in start response.\")","handlingStrategy":"validation","validationCode":null,"typeGuard":"def has_conversation_id(conv_data) -> bool:\n    return isinstance(conv_data, dict) and bool(conv_data.get('conversationId') or conv_data.get('id'))","tryCatchPattern":"try:\n    await agent.invoke(history)\nexcept AgentInvokeException as e:\n    if \"Conversation ID not found\" in str(e):\n        logger.error(\"Start-conversation response schema unexpected.\")\n    raise","preventionTips":["Log conv_data on conversation start to learn the real id field name.","Pin the DirectLine API version to avoid field-name changes."],"tags":["network","directline","copilot-studio","validation","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}