Blog

Adventures with Agents – Part III

Part III – Bringing custom power to a Copilot Studio agent

This is a series of posts covering recent DMS adventures with AI Agents. In this post we answer the question “can we supplement Copilot Studio’s agent designer to provide appropriate access to custom software systems?”. There are lots of posts, videos and tutorials on Agent creation in Copilot Studio so we won’t repeat the outline steps for Agent creation. There are also posts on creation of REST API so we won’t over detail on either of those aspects. What we will focus on is answering the core question: having created your basic agent, how can you further extend it?

Ok. Lets jump in. Upon creating an Agent in Copilot Studio you will see a header bar like this:

cp studio header

Seeking to extend our Agent Adventures:

We’re looking for a way to extend our agent. Within Copilot Studio’ agent designer you will see the above header menu. The option we’re interested in is currently called ‘Tools’ in the designer. A peek in that section of the Studio designer and selecting “+ Add a Tool” brings up some interesting options. Ideally we’d like to leverage a REST API. There is a  </> REST API header but that just filters existing connectors and will likely be blank for new to Copilot users. Further clicking on the “+ New Tool” brings up the dialogue we need. There it is in its own large box:

Agents adventure - Add a tool

Source an API for your Agent’s Adventure

OK so this looks promising as does the corresponding dialog pop up which asks us questions about our REST API. But wait… let’s back up… if we don’t have a REST API already we’ll need to roll one.

Again there are existing posts on REST API development and in this case it’s not something our client was going to do themselves but an implementation service they pay DMS for. Besides a myriad of options exist to enable REST API development and that is not core focus of this post. You may choose to use others but given we’re working on .NET systems and a C# shop we chose to use VS Code and .NET core v9 to develop one that extended our clients custom system. For brevity we won’t describe REST API creation here but we will share some related tips that will help you make your REST API work better with Agents:

Decorate – decorating your REST API service is helpful to the Agent consuming it. In .NET you can leverage the following method decorations to help users, including AI agents, of your service:

.WithName("PartSearch")
.WithSummary("summary of what it does e.g. get parts by ID").WithDescription("an informative description helps!");

Generate Specification – you’ll need to get your target REST API to output a consumable specification. We used OpenAPI and using .NET 9 you achieve that with following line included in the code implementation:

app.MapOpenApi();

We deployed our REST API to Azure using their API App service. It doesn’t matter where you host so long as your agent can communicate and authenticate with the host.

Wiring up the API to the Agent

Ok, so back to the Copilot Studio environment. Now that we have sourced our API we can share it with the Copilot agent by inserting relevant details into the dialog:

Agents adventure - Specification
  • The first screen asks you for an OpenAPI specification. There are a variety of ways to derive this but for our .NET 9 REST API was accessible from the browser [e.g. https://yourWebAddress/openapi/v1.json]. We just saved the browser output as a file that we could upload to copilot studio.
  • Provide description and select your solution – if you leave blank copilot will create a PowerApps solution to add it to and this is what stores your agent config.
  • Configure the authentication you want used to access your REST API:
Agents adventure - Authentication
  • In the ‘Configure Tool’ section insert tool name and description
  • Finally publish the tool (your REST API):
Agents adventure - publishing REST

After publishing, you will need to select the API you want to add to your Agent in the “+ Add a tool” dialog. You can filter if you want to find the REST API you just added to CP Studio. Clicking it will enable you to now add it to your Agent:

Add tool to Agent

Note, if you didn’t earlier you will be prompted when testing to add connection and you’ll do that by clicking ‘connect’ on the resulting dialog:

API Connection

We are getting close now… if you review the tool in the Agent you can edit the configuration that controls inputs/outputs to the REST service. For our first test we are just going to allow Agent to use generative AI to fill out the inputs and figure response. Our guidance is to try this first. While it jars against what procedural programmers have done for most of their careers, our experience is the Generative AI is getting better and most of the time we get better results allowing it to drive and decide what to do for inputs/outputs. It can also better handle the myriad of potential prompts your user may chose to utilize:

Control input ouput

Voila – Calling REST API from our Agent!

Ok – so now if we test our Agent we can observe it using our REST API:

Agent using REST

Summary

Bingo! We achieved what we were seeking: the granular access we wanted to our backend systems using a REST API but with the ease and control of Copilot Studio configuration. While this post just showed you the basic setup, you have now seen how a CP Studio created Agent can be empowered by calls to custom REST API of your choosing. From here we can adapt the agent further to do smarter tasks like order and dispatch the part and/or request resupply for our low inventory. By doing this we are able to power up our Copilot Studio Agents taking them to next level!

Adventures with Agent - Powered by REST
M365 Copilot’s rendition of a REST Powered Agent

This post has been a rapid tour of a small part of our adventures with agents. We hope it helps you recognize an approach that can help you expedite the value of ‘Agentification’ in your own business. Nascent as the idea of AI Agents is, its time has arrived. We think that the ease of Agent creation in Copilot Studio, aligned with the power of extensibility has huge potential. If you’re seeking assistance to help you bring your agent ideas to life, reach out. DMS would welcome chance to collaborate.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Post Publication update: since this article we have come across Microsoft Preview documentation on how to extend copilot agent with REST API. See link here. Hopefully this link aligned with details above will help others seeking to power up and extend Copilot Studio agents!

Be the first to comment

Leave a Reply

Your email address will not be published. Required fields are marked *