Skip to content

Implement Event-Source Send in CopilotStudioClient to handle stream responses#614

Merged
MattB-msft merged 5 commits intomainfrom
southworks/update/event-source-client
Sep 29, 2025
Merged

Implement Event-Source Send in CopilotStudioClient to handle stream responses#614
MattB-msft merged 5 commits intomainfrom
southworks/update/event-source-client

Conversation

@ceciliaavila
Copy link
Copy Markdown
Collaborator

Fixes #595
Fixes #598

Description

This PR updates the Copilot Studio Client package to use an EventSource client and return the Agent's messages as they arrive rather than waiting for the entire response.
It also fixes a bug in copilotStudioWebChat to notify WebChat immediately that the message was sent and then process the agent's response without blocking the UI.

NOTE:
These changes break compatibility for customers using the startConversationAsync, askQuestionAsync, and sendActivity methods directly, not for those using the copilotStudioWebChat createConnection method.

Detailed Changes

  • In copilotStudioClient:
    • Replaced axios with EventSourceClient to handle streaming responses asynchronously.
    • Updated the postRequestAsync method to yield each Agent's response until the connection is closed.
    • Updated the startConversationAsync, askQuestionAsync, and sendActivity methods to handle the AsyncIterator containing the agent's responses.
  • In copilotStudioWebChat:
    • Updated the createConnection method to handle the agent's async responses with for await.
    • Moved the subscriber.next call to notify WebChat immediately that the message was sent and then process the agent's response without blocking the UI.
  • Updated copilotstudio-console test-agent and mcsAgent sample to handle the agent's async responses with for await.
  • Added the printActivity function in copilotstudio-console to format the activities depending on their type.
  • Replaced axios dependency with eventsource-client in agents-copilotstudioclient.
  • Updated method signatures in agents-copilotstudio-client.api.md

Testing

These images show the samples processing multiple activities in one turn.
image

Here we can see the User message marked as sent while the agent's response is being processed.
image

@monaessam1
Copy link
Copy Markdown

Hello , Thanks for this fix , Can you please share when this will be released ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants