Share via

Guidance Required: Accessing Copilot Studio Agent via Python Code

Nathan V 45 Reputation points
2026-04-09T12:55:20.5333333+00:00

Hi Team,

I am currently working with a Copilot Studio agent (built using Microsoft Copilot Studio) and would like to integrate it with a Python-based application.

I have enabled the Direct Line channel and received a connection string in the following format: Endpoint=...;Secret=...

However, I need clarification on the correct approach to access and interact with the Copilot agent programmatically using Python.

Specifically, I would like to understand:

  1. What is the recommended method to invoke a Copilot Studio agent from Python?
  2. Should the Direct Line API be used in this scenario, and if so, how should the connection string be properly utilized?
  3. Are there any official SDKs, APIs, or best practices available for integrating Copilot Studio agents with external backend services (e.g., Python/FastAPI)?
  4. Is there support for real-time/streaming responses when accessing the agent programmatically?
  5. Are there any authentication or permission considerations specific to Copilot Studio agents when accessed outside Microsoft Teams?

It would be helpful if you could provide:

  • Official documentation references
  • Sample implementation (if available)
  • Any limitations or recommended architecture for this integration

Looking forward to your guidance.

Thanks & Regards, Nathan VHi Team,

I am currently working with a Copilot Studio agent (built using Microsoft Copilot Studio) and would like to integrate it with a Python-based application.

I have enabled the Direct Line channel and received a connection string in the following format:
Endpoint=...;Secret=...

However, I need clarification on the correct approach to access and interact with the Copilot agent programmatically using Python.

Specifically, I would like to understand:

  1. What is the recommended method to invoke a Copilot Studio agent from Python?
  2. Should the Direct Line API be used in this scenario, and if so, how should the connection string be properly utilized?
  3. Are there any official SDKs, APIs, or best practices available for integrating Copilot Studio agents with external backend services (e.g., Python/FastAPI)?
  4. Is there support for real-time/streaming responses when accessing the agent programmatically?
  5. Are there any authentication or permission considerations specific to Copilot Studio agents when accessed outside Microsoft Teams?

It would be helpful if you could provide:

  • Official documentation references
  • Sample implementation (if available)
  • Any limitations or recommended architecture for this integration

Looking forward to your guidance.

Thanks & Regards,
Nathan V

Microsoft Copilot | Microsoft 365 Copilot | Development
0 comments No comments

1 answer

Sort by: Most helpful
  1. Sayali-MSFT 5,521 Reputation points Microsoft External Staff Moderator
    2026-04-10T11:56:13.4666667+00:00

    Hello Nathan V ,
    To integrate a Copilot Studio agent with a Python‑based application, the officially supported approach is to use the Microsoft Bot Framework Direct Line API, since Copilot agents run on Azure Bot Service infrastructure. The connection string you receive from enabling the Direct Line channel must first be split to extract the secret, which is then exchanged for a short‑lived Direct Line token—this token is used to initiate a conversation and send or receive messages programmatically, rather than calling the agent endpoint directly. In a typical Python workflow (e.g., using FastAPI), your backend generates the token securely, starts a Direct Line conversation, and sends user input as activities to the agent while polling or subscribing to responses via REST or WebSocket streaming for real‑time interaction. Although generative answers, topics, Power Automate actions, and Adaptive Cards are supported through Direct Line, Teams‑based SSO or user identity context is not inherited automatically in external environments, so any user‑specific permissions must be passed manually within the channel data. For production use, it’s recommended to implement a server‑side token proxy to prevent exposing the Direct Line secret and to handle conversation lifecycle and authentication securely while interacting with the Copilot agent from external services like Python applications.
    Reference-https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-api-reference?view=azure-bot-service-4.0

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.