Building and customizing solutions using Microsoft 365 Copilot APIs and tools
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