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 AgentCreate A New Copilot Studio AgentSetup A SharePoint Document Library With Large FilesBuild A Power Automate Flow With A Recurrence TriggerGet The Copilot Studio Agent Unique IdentifierDetermine Which SharePoint Files To UploadGet The File Content For Each SharePoint Document Library FileAdd File To Copilot Studio Agent Knowledge With Power AutomateUpload  Large SharePoint Files To Copilot Studio 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.




Upload Large SharePoint Files To Copilot Studio Agent

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.







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

1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
Vikash Singh
Vikash Singh
5 hours ago

This is a really clever workaround – great work!