SharePoint Agents when configured through the SharePoint interface store their configuration in a <agent name>.agent file. This config stores all the details about the Agent i.e. Name, Description, Welcome Message, Starter prompts, icon along with the sources of the agent i.e. Site, Document Library, Folder or File. The purpose of this blog is to show how these can be dynamically created using PowerShell so you could provision customised SharePoint Agents at scale.

I realised when I created an SharePoint Agent it created a .agent file with the configuration so I decided to see if I could open this up in a text editor. I then realised it is just a JSON file underneath (see image below).

So I then thought “lets see if I can automate the creation of these files using my favourite PowerShell”. A point to note this is most likely UNSUPPORTED and you do so at your OWN RISK – things are fast changing in the Copilot world so wouldn’t surprise if the configuration for SharePoint agents changed.
The Script
I have written a script to automate the creation of .agent files which you can then add to your sites & libraries. In the script you can then specify the details for the copilot i.e. name, welcome message, starter prompts & sources for the agent i.e. specific files, folders, libraries or sites that the agent is then grounded on. The script uses search to find the site ids, web ids and unique Ids of documents.
Minimum Steps To Success
- Enter a URL of a SharePoint site you have access to.
- Run the script (you will be asked for the following:)
- Name of the SharePoint Agent
- Description of the Agent
- Custom welcome message for the Agent
- Instructions for the Agent
- Enter at least one Starter Prompt i.e “How can you help me?”
- Enter at least one SharePoint source (File, Folder, Library or Site)
- Add created <Agent Name>.agent file to /SiteAssets/Copilots folder.
Summary
It will be great to be able to programmatically deploy customised SharePoint agents to each site and this script will give you the building blocks to show how the .copilot file can be built programmatically. I imagine this logic will be useful in provisioning solutions – imagine provisioning a Project site with a customised SharePoint Agent on the site. Pre-configured with custom instructions i.e. intent, behaviour, role with starter prompts so people can get max value from the Agent.
As mentioned – this scripted approach is likely UNSUPPORTED and SUBJECT TO CHANGE so USER BEWARE! I also havent added much error handling to the script so it may not be the most efficient.
Looking forward to people making more use of SharePoint Agents and even deploying them programmatically! Let me know how you get on or if you improve this concept in your organisation?