-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Package Version: microsoft-agents-copilotstudio-client 0.0.0a3
Released: May 20, 2025 (latest)
Hi Agents For Python team:
I'm part of a team using this package for about 12 Copilot Studio agents. The project we are building involves the use of the Microsoft Semantic Kernel SDK. We have agents hosted on AI Foundry, ML Studio and Copilot Studio. While it supports AI Foundry, we are including the use of the Copilot Studio Client SDK MS365 Agents SDK (Python), which uses the DirectToEngine technology. Recently, we had a large outage of all 12 Copilot agents (with no changes or issues in uat and production environment in the last 5 days it had been deployed), all throwing the same error of:
[2025-06-04T03:40:44.409Z] File "c:\Users\Zhi Lin Ooi\Documents\Azure DevOps\.venv\Lib\site-packages\microsoft\agents\copilotstudio\client\copilot_client.py", line 44, in post_request
[2025-06-04T03:40:44.411Z] activity = Activity.model_validate_json(activity_data)
[2025-06-04T03:40:44.413Z] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-06-04T03:40:44.415Z] File "c:\Users\Zhi Lin Ooi\Documents\Azure DevOps\.venv\Lib\site-packages\pydantic\main.py", line 656, in model_validate_json
[2025-06-04T03:40:44.417Z] return cls.__pydantic_validator__.validate_json(json_data, strict=strict, context=context)
[2025-06-04T03:40:44.419Z] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-06-04T03:40:44.421Z] pydantic_core._pydantic_core.ValidationError: 1 validation error for Activity
[2025-06-04T03:40:44.423Z] text
[2025-06-04T03:40:44.425Z] String should have at least 1 character [type=string_too_short, input_value='', input_type=str]
[2025-06-04T03:40:44.427Z] For further information visit https://errors.pydantic.dev/2.10/v/string_too_short
Upon reading into the CopilotStudioClient package (linked above), we found that it was line 44 throwing the error
activity = Activity.model_validate_json(activity_data)
when the client attempted to validate the response from the agent. Further investigation revealed that the response was returned correctly, but processed incorrectly by the Client. Here is the logged sample response body:
[2025-06-06T03:09:53.740Z] b'event: activity\r\n'
[2025-06-06T03:09:53.742Z] b'data: {"id":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b-227","type":"typing","text":" sustainability","channelData":{"streamType":"streaming","streamId":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b","chunkType":"delta","streamSequence":228}}\r\n'
[2025-06-06T03:09:53.745Z] b'\r\n'
[2025-06-06T03:09:53.747Z] b'event: activity\r\n'
[2025-06-06T03:09:53.749Z] b'data: {"id":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b-228","type":"typing","text":" knowledge","channelData":{"streamType":"streaming","streamId":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b","chunkType":"delta","streamSequence":229}}\r\n'
[2025-06-06T03:09:53.752Z] b'\r\n'
[2025-06-06T03:09:53.754Z] b'event: activity\r\n'
[2025-06-06T03:09:53.757Z] b'data: {"id":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b-229","type":"typing","text":" base","channelData":{"streamType":"streaming","streamId":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b","chunkType":"delta","streamSequence":230}}\r\n'
[2025-06-06T03:09:53.759Z] b'\r\n'
[2025-06-06T03:09:53.761Z] b'event: activity\r\n'
[2025-06-06T03:09:53.763Z] b'data: {"id":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b-230","type":"typing","text":".","channelData":{"streamType":"streaming","streamId":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b","chunkType":"delta","streamSequence":231}}\r\n'
[2025-06-06T03:09:53.765Z] b'\r\n'
[2025-06-06T03:09:53.982Z] b'event: activity\r\n'
[2025-06-06T03:09:53.984Z] b'data: {"type":"message","id":"ea9f0e59-77c5-43be-91c8-52fa41df4c9e","timestamp":"2025-06-06T03:09:54.1841433\\u002B00:00","channelId":"pva-published-engine-direct","from":{"id":"d828a6cb-5cf4-e21c-9bc9-8f48a73fe683/78aebf4e-2636-f011-8c4d-000d3a80e92e","name":"crbc_Sustainability","role":"bot"},"conversation":{"id":"e4e88623-b832-4a7d-9637-bceb4508b2c6"},"recipient":{"id":"e4f71a41-d2a0-47b8-9005-be502645ecf0","aadObjectId":"e4f71a41-d2a0-47b8-9005-be502645ecf0","role":"user"},"textFormat":"markdown","membersAdded":[],"membersRemoved":[],"reactionsAdded":[],"reactionsRemoved":[],"text":"\\u2611 Based on official sources\\n\\nOur\\u0027s sustainability strategy is built around six core ESG (Environmental, Social, and Governance) pillars. These pillars guide our efforts to create a positive impact on the environment, society, and our business operations. Our comprehensive sustainability framework includes:\\n\\n1. **Environmental Stewardship**: Initiatives to reduce our carbon footprint, manage resources efficiently, and promote biodiversity.\\n2. **Social Responsibility**: Programs to support community development, enhance employee well-being, and ensure diversity and inclusion.\\n3. **Governance**: Strong governance practices to ensure transparency, ethical behavior, and accountability.\\n4. **Sustainable Innovation**: Leveraging technology and innovation to drive sustainable solutions.\\n5. **Stakeholder Engagement**: Collaborating with stakeholders to align our sustainability goals and create shared value.\\n6. **Economic Impact**: Ensuring our business practices contribute to long-term economic sustainability.\\n\\nThese pillars are supported by specific metrics, best practices, and implementation strategies that are regularly updated and monitored to ensure continuous improvement and alignment with global sustainability standards. For more detailed information, you can refer to the SharePoint sustainability knowledge base.","inputHint":"acceptingInput","attachments":[],"entities":[],"channelData":{"streamType":"final","streamId":"bb0c32c7-b184-4c5e-a6c7-236c65bc003b"},"replyToId":"d7eda3e6-97b2-47df-93d0-6dd24e51669c","listenFor":[],"textHighlights":[]}\r\n'
CopilotStudioClient was unable to validate the structure of the streamed response because the structure was different from what it expected. We have our function as an Azure Functionapp endpoint, so we copied out the faulty package (luckily it was small), and employed a small fix which handled the JSON body differently:
# Original
if line.startswith(b"data:") and event_type == "message":
activity_data = line[5:].decode("utf-8").strip()
activity = Activity.model_validate_json(activity_data)
if activity.type == ActivityTypes.message:
self._current_conversation_id = activity.conversation.id
yield activity
# Patched
elif line.startswith(b"data:") :
activity_data = json.loads(line.replace(b"data: ",b""))
if activity_data["type"]=="message":
activity = Activity.model_validate(activity_data)
if activity.type == ActivityTypes.message:
self._current_conversation_id = activity.conversation.id
yield activity
break
else:
continue
We assume that it may have been how CopilotStudio is returning a different JSON body then before, but we would like to ask if there's any support for this issue. Thank you very much. 🙂