Generate OpenAPI Spec for M365 Copilot Declarative Agent
Introduction
After encountering issues with creating a To-Do task action in my previous attempt Building a Copilot Agent with Microsoft 365 Agents Toolkit and Microsoft Graph Plugin to list my ToDo Tasks, I explored various methods to generate an OpenAPI specification for M365 Copilot Declarative Agents using the Ms Graph OpenAPI spec. This post outlines the different approaches I tried, the challenges I faced, and the lessons learned.
Methods for Generating OpenAPI Specs
1. Kiota
In my earlier blog post, Building a Copilot Agent with Microsoft 365 Agents Toolkit and Microsoft Graph Plugin to list my ToDo Taskss, I detailed how to create an OpenAPI action to get ToDo Tasks using Kiota.
Challenges
The
Create To-Do Task
action did not work despite following the steps multiple times.When attempting to generate OpenAPI specs for SharePoint list items for actions
Get List Item
orCreate List Item
, the resulting file was excessively large (184 MB), far exceeding the allowed size limit.
I was unsuccessful attempting to have a trimmed down version.
2. Microsoft 365 Agents Toolkit
I also tried using the Microsoft 365 Agents Toolkit (previously known as Teams Toolkit), which generated a different format for the OpenAPI spec. Below are the steps I followed:
Steps:
- Download the Microsoft Graph OpenAPI Specification
Use the following command to download the OpenAPI spec:
Invoke-WebRequest -Uri "https://aka.ms/graph/v1.0/openapi.yaml" -OutFile "openapi.yaml"
- Used hidi to get the functions CreateItems and ListItems
Install hidi
dotnet tool install --global Microsoft.OpenApi.Hidi --version 1.6.24
Retrieve the function listitems and createitems
hidi transform -d "C:\Users\reshm\TeamsApps\VolunteeringApp\apis\openapi.yaml" -f json -o apis\graph_Createitem.yaml -v OpenApi3_0_4 --op sites.lists.CreateItems,sites.lists.ListItems --co
Use Microsoft 365 Agents Toolkit to generate the action browsing to the graph_Createitem.yaml
generated above, however the number of lines on the API spec file end up being 25,149 causing the same issue with filesize exceeded.
Dev Proxy
I was unable to determine how to use Dev Proxy to extract specific actions from the Microsoft Graph OpenAPI spec. This remains an area for further exploration.
Copilot
Thanks to Lee Ford, who suggested using Copilot to generate an OpenAPI spec for another API call, I decided to try prompting Copilot with the endpoint and request body. This approach allowed me to generate a targeted OpenAPI spec containing only the required functionality, and it worked perfectly.
For more details on how I successfully created an OpenAPI spec for SharePoint lists, refer to my post: Creating an OpenAPI Specification for Microsoft 365 Copilot Declarative Agents to Interact with SharePoint Lists.
References
- Copilot
- Declarative Agent
- Microsoft Graph
- Azure OpenAI
- Teams Toolkit
- M365 Copilot Extensibility
- OpenAPI
- Authentication
- ttk
- atk
- Microsoft 365 Agents Toolkit