Customize The Model-Driven Apps Copilot Prompt Library

Customize The Model-Driven Apps Copilot Prompt Library

You can customize the model-driven apps Copilot’s prompt library with new groups & prompts. This is done by editing the agent in Copilot Studio and creating a new topic that triggers when the RequestSparks event fires. The RequestSparks event tells the model-driven apps agent to load the prompt library. Then you insert new prompts (i.e. Sparks) into it.

Table of Contents
Introduction: The Model-Driven Apps Copilot Custom Prompt Library
Create A New Topic In The Custom Model Driven Apps Copilot
Trigger The Topic On Request Sparks Event
Define The Prompt Library Custom Group And Custom Prompts
Set The SparksGroup And SparksArray Variables
Add Groups And Custom Prompts To The Model-Driven Apps Copilot Prompt Library
Test The Model-Driven Apps Copilot Custom Prompts




Introduction: The Model-Driven Apps Copilot Custom Prompt Library

Users of a model-driven app custom Copilot can browse a prompt library with a set of custom prompts.



When the custom prompt is selected it appears in the chat window. Users fill in the placeholder values and send the prompt to get a response from the Agent.




Create A New Topic In The Custom Model Driven Apps Copilot

Open the model-driven app and navigate to the Agents menu. Edit the App Assistant Agent.



In Copilot Studio, add a new topic to the Agent named Sparks Customize Prompt Library.




Trigger The Topic On Request Sparks Event

The prompt library appears in the model-driven apps Copilot chat window when the RequestSparks event is trigger. We will trigger our topic when that event occurs. Change the trigger type to a custom client event occurs.



Use this event name:

Microsoft.PowerApps.Copilot.RequestSparks



And set the following value for the priority field:

9999




Define The Prompt Library Custom Group And Custom Prompts

Our goal is to add a new group Copilot chat prompt library including multiple custom prompts inside of it. Store the name of the new group in a text variable named Topic.CustomPromptsGroup.



Then create a new text variable for each custom prompt that is found within the new group.



Write this value in Topic.CustomPrompt1.

List all contacts associated with the company [Company Name]



Use this prompt in Topic.CustomPrompt2.

Get me all contacts with the job title [Job Title]



Then provide this text in Topic.CustomPrompt3.

Find all contacts in the State of [State Name]




Set The SparksGroup And SparksArray Variables

Next, we will create two new variables: SparksArray and SparksGroups.



The SparksArray variable is a table of all the new groups we want to add to the prompt library and their sparks. Copy and paste the code below into the formula field for the set SparksGroup set variable value node. If we wanted to add more than one group, we could do so by adding another object to this table.

[
{
entityName: "",
displayName: ""&Topic.CustomPromptsGroup&"",
displaySubtitle: ""&Topic.CustomPromptsGroup&"",
iconName: "agents20Regular",
sparks: [
{
displayName: ""&Topic.CustomPrompt1&"",
type: "PromptText"
},
{
displayName: ""&Topic.CustomPrompt2&"",
type: "PromptText"
},
{
displayName: ""&Topic.CustomPrompt3&"",
type: "PromptText"
}
]
}
]



And the SparksGroups variable is a table of all the group names. Use this code to set the SparksGroup variable.

ForAll(Filter(Topic.SparksArray, IsBlank(ThisRecord.entityName) || (!IsBlank(Global.PA_Copilot_EntityContext) && ThisRecord.entityName in DropColumns(Global.PA_Copilot_EntityContext, DisplayName, Description))), ThisRecord)




Add Groups And Custom Prompts To The Model-Driven Apps Copilot Prompt Library

The SparksArray and SparksGroups were created to make it easier to insert groups and custom prompts in the model-driven apps Copilot prompt library. Now we will load their values into a set of two global Power Apps Copilot variables: Global.PA_Copilot_Sparks.sparkGroups and Global.PA_Copilot_Sparks.sparks.



Add the new groups to the model-driven apps prompt library by settings the Global.PA_Copilot_Sparks.sparkGroups variable to this code.

With({groups: CountRows(Global.PA_Copilot_Sparks.sparkGroups)}, ForAll(Sequence(groups + CountRows(Topic.SparkGroups)), If(Value <= groups, Index(Global.PA_Copilot_Sparks.sparkGroups, Value), Index(Topic.SparkGroups, Value - groups))))



And set Global.PA_Copilot_Sparks.sparks use this code to insert the custom prompts into the new group.

With({groups: CountRows(Global.PA_Copilot_Sparks.sparks)}, ForAll(Sequence(groups + CountRows(Topic.Sparks)), If(Value <= groups, Index(Global.PA_Copilot_Sparks.sparks, Value), Index(Topic.Sparks, Value - groups))))




Test The Model-Driven Apps Copilot Custom Prompts

We’re done. Save and publish the custom model-driven apps Copilot in Copilot Studio. Then open the model-driven app. The custom prompts will appear inside of the prompt library.



When the user selects a prompt it is inserted into the prompt window for the user to modify and send as a message to the Copilot.






Questions?

If you have any questions or feedback about Customize The Model-Driven Apps Copilot Prompt Library please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest

0 Comments
Oldest
Newest
Inline Feedbacks
View all comments