How To Add Copilot Studio Knowledge Files Using Power Automate

How To Add Copilot Studio Knowledge Files Using Power Automate

Copilot Studio knowledge files can be added to an Agent with a Power Automate flow. This is helpful when SharePoint files are over the 7MB size limit. By uploading files from SharePoint and adding them directly to the Agent now files can be up to 512MB in size. The Agent will be able to read very large files.

Table of Contents
Introduction: Sync Large Files From SharePoint To Copilot Studio Agent
Create A New Copilot Studio Agent
Setup A SharePoint Document Library With Large Files
Build A Power Automate Flow With A Recurrence Trigger
Get The Copilot Studio Agent Unique Identifier
Determine Which SharePoint Files To Upload
Get The File Content For Each SharePoint Document Library File
Add File To Copilot Studio Agent Knowledge With Power Automate
Publish The Copilot Studio Agent Using A Bound Action
Test The Copilot Studio Agent To Upload Large SharePoint Files
Bonus: Remove Knowledge From The Copilot Agent




Introduction: Sync Large Files From SharePoint To Copilot Studio Agent

A developer would like to use Copilot Studio to read several large PDF files in a SharePoint document library. However, due to memory limits Copilot Studio can only use SharePoint files that are under 7MB.




To workaround this limitation, the developer creates a Power Automate flow to add the files directly to the Agent’s knowledge on a recurring schedule. The maximum file size limit for a file uploaded to the Agent’s knowledge is 512MB.




Create A New Copilot Studio Agent

We will begin by creating a new Copilot Studio Agent named Knowledge Upload API Agent. Use the description “this Agent will use its files from knowledge to answer questions.” And turn on generative orchestration mode.



Do not add any knowledge to the Agent manually. We will do this with a Power Automate flow instead.




Setup A SharePoint Document Library With Large Files

The Copilot Studio Agent will be synced with a SharePoint document library holding many large files. Create a new SharePoint document library named Copilot Knowledge Library Sync. Then upload a few large PDF files into the document library.




Build A Power Automate Flow With A Recurrence Trigger

We want the Copilot Studio Agent to sync with the SharePoint document library every hour to ingest any new files added. Create a Power Automate flow and use the recurrence trigger. Set a recurrence interval of 1 day.




Get The Copilot Studio Agent Unique Identifier

To create add a new file to the Copilot Agent’s knowledge we need to know its unique identifier. Insert a Dataverse – List Rows action into the flow and select the Copilots table.



Filter rows by the Copilot’s display name.

name eq 'Knowledge Upload API Agent'



Then initialize a variable named varCopilotId to store the unique identifer.



Use this code to get the Agent’s unique identifier from the list rows action.

first(body('List_rows:_Copilots')?['value'])?['botId']




Determine Which SharePoint Files To Upload

If a file already exists as Agent knowledge the automation should not upload it. To determine which SharePoint files to upload add a SharePoint Files – Get Files action and select the Copilot Knowledge Library Sync document library.



Then add a Dataverse – List Rows action for the table Copilot Components to get the Agent’s current knowledge.



Use the following filter expression to return only components related to the chosen Agent.

_parentbotid_value eq variables('varCopilotId')



Next, convert the names of the Copilot Studio Agent’s knowledge files to a simple array using a Select action. For example: [“Filename1.pdf”, “Filename2.pdf”, “Filename3.pdf”].



And finally, we insert a Filter Array action to filter the list of files in the SharePoint document library by removing any filenames found in the simple array from Dataverse.



Use this expression for the filename with extension in the Filter Array comparison.

item()?['{FilenameWithExtension}']




Get The File Content For Each SharePoint Document Library File

The filter array action outputs a list of files to be uploaded to the Copilot Studio Agent. We must get the file content for each file from SharePoint. Begin by inserting an Apply To Each action and looping over the body of the Filter Array action.



The first action in the loop is a SharePoint – Get File Content action. We can target the file we want to obtain by using the file identifier.



Use this code for the file identifier:

items('Apply_to_each:_SharePoint_File')?['{Identifier}']




Add File To Copilot Studio Agent Knowledge With Power Automate

Copilot Studio Agents store their knowledge in a table named Copilot components. We can add a new file to an Agent’s knowledge by adding a row to this table. Insert a Dataverse – Add A Row action and choose the Copilot components table. Select the component type Bot File Attachment.



The SchemaName must start with the same solution publisher prefix as the Copilot Studio Agent. Then follow the naming pattern before and use the filename with extension as the suffix.

cr6f9_knowledgeUploadApiAgent.file.@{items('Apply_to_each:_SharePoint_File')?['{FilenameWithExtension}']}



Write this code in the Parentbotid lookup field to indicate which Agent owns the component.

/bots(@{variables('varCopilotId')})



After the add a new row action insert an Upload a file or an image action as the final flow action. Target the Copilot components table and use the unique identifier for the newly created row in the Row ID field. Select the filedata column and supply the Body of the Get File From SharePoint action to the Content field.




Publish The Copilot Studio Agent Using A Bound Action

Changes made a Copilot Studio Agent must be published before they take effect on an Agent deployed to a channel. Add Dataverse – Perform A Bound Action the final flow action and select the Copilots table. Choose the PvaPublish action and use varCopilotId as the Row ID.





Test The Copilot Studio Agent To Upload Large SharePoint Files

We’re done building the Power Automate flow. Test run the flow to ensure it works.

Once the SharePoint document library files are added to the Agent they will show as In Progress while being converted to embeddings.



After a few minutes the knowledge files will show a status of Ready.



Now we can use the Copilot Studio Agent chat window to ask questions and get answers from the knowledge source.




Bonus: Remove Knowledge From The Copilot Agent

To keep the Copilot Studio Agent’s knowledge files in sync with the SharePoint document library we will also want to remove files as well. When a file is deleted from SharePoint we should delete it from the Agent as well.

To do this, delete the Publish Agent bound action at the end of the flow. Then add a Select action to the flow and get all of the filenames in SharePoint.



Then determine which files to delete by using the Filter Array action. Filter all of the current files in the Agent’s knowledge where the filename is not found in the array of filenames from the previous Select action.



Insert an Apply To Each action and loop over the Body of the Filter Array action.



Remove each file by adding a Dataverse – Delete A Row action and targeting the Copilot components table.



Use this code in the Row ID property to supply the Copilot Studio Agent’s unique identifier.

@items('Apply_to_each:_Copilot_Knowledge_File')?['botcomponentid']



Finally, add the Publish A Copilot Studio Agent action once again at the end of the flow.






Questions?

If you have any questions or feedback about How To Add Copilot Studio Knowledge Files Using Power Automate 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

8 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Vikash Singh
Vikash Singh
1 month ago

This is a really clever workaround – great work!

Craig White
Craig White
1 month ago

This is genius, nice work

Philip
Philip
1 month ago

Matthew, found your article doing a good search and just love this approach. Im building something very similar but with a few modifications (making it autonomous) that I can seem to get around due to the limitations of powerbuilder. What I would love to do is as files are uploaded to knowledge, it can then run “Sends a prompt to the specified copilot for processing” that would take that prompt and run for every new file in sharepoint and then “Recognize text in an Image or in a PDF document” and save the output in JSON or Excel based on the prompt instructions.

Emir
Emir
1 month ago

Excellent! I subscribed with the intention of praising your ☄️idea.👍😺🐱 ✨👋

Matt Maguire
Matt Maguire
5 days ago

Hi Matthew. This is genius! I have a document library with internal policies I would like to make an agent for. Can I ask, is there a way to determine the last updated date of an agent knowledge file source? I want to be able to replace a knowledge file of the same name with a new version if a new version is uploaded to SharePoint. Any ideas?