
You probably saw already the exciting Copilot Studio possibilities coming to Model-Driven Apps. If not, here is the preview announcement. Basically there are 3 ways to interact with Copilot Studio from Model-Driven Apps:
- Agent Xrm API (Xrm.Copilot) : a set of functions under the Xrm namespace, allowing us to call Copilot Studio topics using MDA scripting; right from the MDA scripting.
- Agent PCF API (context.Copilot): same functions as in the XRM.Copilot namespace, but this time inside a PCF
- Agent Response Component: a ready to use PCF, which is calling Agent PCF API.
This opens huge possibilities for Model-Driven Apps. But before going to extended use-cases, this blog is only about how to use the APIs. I’m a Copilot Studio newbie, and I’ve struggled for a while to make it work, so hopefully this blog would help somebody else too. This is my “Hello World” test für die Agent APIs.
The API
The Xrm.Copilot and the PCF context.Copilot offers two ways to interact with the Copilot Studio Agent:
- executeEvent : Executes a Microsoft Copilot Studio topic based on the registered Event Name
- executePrompt: Executes a Microsoft Copilot Studio topic based on the trigger queries registered in the topic.
The prerequires
The documentation is split on a few places, so here is what you need to do to start:
- prefer using “https://make.preview.powerapps.com/“, since I’m not sure if the feature is available otherwise. At least the docs suggest this for now (July 2025)
- the “note” in the docs is specifying that we need to use “early release cycle environment“
- it’s not enough to create your own Copilot Studio agent, and it’s not enough to add it to your Model-Driven App. Actually it’s documented that we need Interactive Agent to work with Agent API and Agent Response PCF.
The steps to start:
- Navigate to https://make.preview.powerapps.com/
- Open your app in edit mode.
- Spot the “Agents” tab, and locate the “Interactive agents”
- Use the “…” and pick “Configure in Copilot Studio”
Alle the steps are described here
Configure the Interactive Agent in Copilot Studio
Using the Agent API we can trigger an event or a prompt. So I won’t work with Knowledge for now, won’t add anything else. The API are targeting only “Event” and “Prompt”, so I’ll define only my Topics.
The Event Topic
We are inside Copilot Studio, editing the Interactive Agent. We navigate to “Topics” and choose “Add a topic” (From blank)
This opens an empty topic
We’ll choose a trigger: “A custom client event occurs”
Then we click in “Edit” to specify the name of the event
The name provided for “Event name” will be the one used later in PCFs. So save it for later: (in my case Diana2.MDACopilot.AdaptiveCard)
Choose “+” and then “Send a message” (we’re trying to respond to our PCF)
Provide some dummy text for now. I’ve also added a “Basic card” and provided there some test content and an image url.. just for fun.
The last step is “End all topics”. Honestly.. I don’t know if that’s the way to go.. but looks fine
Don’t forget to save and publish. You will be prompted to enter a name. This is the topic name, not the event name, so it’s not the one we’ll use in the PCF.
Come back to the App, and publish the app.
Agent Response Component
We’ll use this Topic with the Agent Response Component. We just need to add the “Agent Response (Preview)” to the form
And paste the name of the event inside customizing flyout for the “Agent Response”
Then you can save and publish.. and test your app, by opening the form.
It may take a while
And then you see the component rendering the answer right inside my page:
The downside of this PCF is that is called every time the form opens, even if we don’t need it. Also, we cannot provide further parameters. In the following steps we learn to make the calls by ourselves while having the control when the agent is asked.
Using the Agent API (Xrm.Copilot)
I’m trying now to use code, to invoke the same Agent Event as in the Agent Response PCF.
While staying on the form, press F12 and try the console:
Xrm.Copilot.executeEvent("Diana2.MDACopilot.AdaptiveCard")
.then(console.log).catch(console.error)
And I get the same answer, as the PCF before. I see the “text” with the provided message, I see the media content as attachment, including title and images.
Love it! 😍
The description of the response content can be found here.
Providing parameters
For the next step I was searching in the dark for a while. The docs specifies a second parameter for the executeEvent call, where we can provide the parameters. The docs are showing this example, by passing the id…
And I thought I should use the Topic “Details” to get the input parameters, BUT that was NOT it (or at least I couldn’t make it work). The false expectation of a newbie. 😁
In the end I could use the parameters provided as “Activity.Value”, so by choosing “Insert Variable”
And then pick from System: Activity.Value
We are getting also some Global variables with some contextual information like entityName and record id, which seems to be sent automatically to the topic.
I’m saving the Topic, and publishing again. And then I’m using the Xrm.Copilot API again, this time passing a second parameter:
Xrm.Copilot.executeEvent("Diana2.MDACopilot.AdaptiveCard", "Dianamics 😍")
.then(console.log).catch(console.error)
The second parameter can now be seen in the response I get from the Agent. We see also the table name and the record id, which are passed automatically to the Event.
[If you know better ways to pass params, I would love to hear about them. Please let me know.]
Executing a Prompt
We can try any prompt. The Interactive Agent is answering the best it can
Xrm.Copilot.executePrompt("Hello Copilot World")
.then(console.log).catch(console.error)
But we could add another topic which can answer more accurate. For instance, I’ve created a topic triggered by Agent, and in the description I’ve specified the triggers
In the next step I’m just redirecting to the Topic used above (the one containing the card), and end the topic.
Now if I trigger the Prompt again, I get the answer containing the card as I did above
Conculsion
Now we have the “Hello World” test. Of course, the Events and Prompts used are deterministic, and we don’t want to call the Copilot Studio for something like this. But now we have the basics of the interaction, and we are good to go to use the Copilot Studio to provide some answers where we combine the Knowledge, the Agents and the Tools to provide more intelligent answers for our users.
As I said, I’m a complete Copilot Studio newbie. If the blog can be improved, I would love to learn from you.
Photo by Igor Omilaev on Unsplash
Marketing
Project Operations
Supply Chain
HR

