Agents, Agents, Agents

Agents, Agents, Agents

The Agents topic is everywhere and omnipresent. Everybody tells you; this is the next big thing. You need an army of agents that finish your work. But how do I build such agents? Should I go for pro-code or for low-code? Should I use AI Foundry or Copilot Studio. Furthermore, what is a good example of building an agent? This was also the billion dollar-question for me.

Today, I will showcase a small example to you where I will build a Low Code agent with Copilot Studio. No, it is not again the same Microsoft demo agent shown by everybody. I will develop an own agent for one of my real-world use cases. Exactly, I will develop an automation scenario, where an agent helps me to manage my currency exchange rates in Dataverse.

Automation vs. Agent

Before I delve too fast into my story, I will discuss an important question. It’s: When should I automate, and when should I use an agent?

First of all, I try to automate everything, that is a rule-based or predictable task. Here I use per example Power Automate Flows or Logic Apps. Moreover, it’s perfect, when I have structured documents such as invoices and forms. In addition, I can break down the whole scenario into smaller workflows.

On the other hand, this gets sometimes difficult, when I stumble into bigger decision trees. It’s also hard when I’m working with unstructured data. Another example is, when I have to build up communication scenarios with end users. Here an AI agent can leverage the whole process a lot.

Under the bottom line there are in my opinion these options:

  • If you can solve your problem with simple automation, then set up an automated workflow!
  • If you are facing communication, classification, or extraction problems, use AI and agent workflows.

Let’s do a hands on…

Example Use Case

In my favorite presentation example – my Expenses Management System – I recently stumbled into an issue. I uploaded a receipt with a foreign currency, but I didn’t handle it properly. In other words, I imported a restaurant bill as Euro currency and not in polish zloty:

Later I wondered why I had unexpectedly high cost for this restaurant bill. The reason was, I did not respect foreign currencies in my expenses tracking system. I imported the total as Euro:

My question was, how to solve this? Can an agent help me? Should I automate or…

Lots of questions that I had. However, first I must tackle the root cause of my problem: I did not respect the foreign currency.

Currencies in Dataverse

After a bit of investigation, I noticed again that Dataverse is cool! This is because Dataverse is a multicurrency system. That means, Dataverse itself can already manage transactions in multiple currencies (see: Microsoft Docs).

There is the table Currencies that contains all exchange rates:

In my case, only the base currency is present. Ok, so I’m adding polish zloty as another currency.

Problem solved, now I can manually change my expenses document Currency into zloty. After saving te Total (Base) is automatically calculated into Euro based on the current Exchange Rate:

Ok, is my problem really solved? What happens, when I upload the next expenses document in e.g. US Dollar? How can I keep my exchange rates in sync with the market?

Exchange Rate Agent

Why not automating this scenario within a Copilot Agent? My agent can keep my exchange rates in sync. Furthermore, it automatically can add new currencies when needed.

Yes, I know I wrote in Automation vs. Agent that automation would be preferred for this deterministic problem. However, this is a great scenario to learn how to build agents. For that reason, I’m creating an agent and see how far I can go…

Tools

Before I’m starting with my agent, I set up some Power Automate Flows. First, I’m creating a flow that gets my exchange rates for the base currency:

This flow sends an HTTP request to the Exchange Rate API. This is per example:

GET https://open.er-api.com/v6/latest/EUR

Secondly, I’m creating another flow to add or update the currency in my system. Here is an example of a successful run:

Finally, I’m adding this flows as Tools to my Copilot Agent:

So good so far.

Instructions

As Instruction I’m describing how my agent should use my given tools to accomplish the task. Here I’m starting with with very basic instructions such as:

You are an exchange rate agent that is responsible for adding or updating currency exchange rates in Dataverse.
Your tools are:
- Use "🤖 Get Currency Exchange Rates" to get the actual exchange rates for base currency EURO. Required parameters are:
  + "CurrencyCode" is the base currency in Three-Letter ISO format.  
- Use "🤖 Update Currency Exchange Rate" to add or update the exchange rate for a currency. Required parameters are:
  + "CurrencyCode" is the currency in Three-Letter ISO format.
  + "CurrencyName" is the name of the currency.
  + "CurrencySymbol" is the symbol of the currency.
  + "ExchangeRate" is the current exchange rate of the currency.

Note, it’s the first of my instructions. Let’s see if this works well.

Testing my Agent

As usual, I’m testing my new agent directly in Copilot Studio. Here I’m using the Test your agent pane and enter a prompt:

Great, my agent starts and gets the exchange rates. Afterwards it is looking for knowledge. This might be to identify the currency symbol. But then it tries to update the currency twice?

let me check the step Search sources. Here I see that it is looking for some currency information such as currency codes:

But my agent did not finish the work. It stops because it can’t pass in the right parameters:

Unfortunately, I see this issue very often when I’m utilizing Power Automate flows as agent tools. The problem behind the scenes might be this. Power Automate flow parameters are always named like this: text, text_1, text_2, …

In conclusion, I must improve my instruction and my tools…

Exchange Rate Agent – Version 2

First, I must simplify my Power Automate flow tools. I’m starting with the flow 🤖 Update Currency Exchange Rate. I’m reducing the input parameters to CurrencyCode and ExchangeRate:

In addition, I’m using an AI Prompt to get the currency details such as currency name and symbol. This is because these fields are required when I’m adding a new currency to my system with Add Currency:

The AI Prompt itself is this:

Next, I’m adding another Power Automate flow to my solution and as Tools to my agent. This is my flow 🤖 Get Base Currency. Here I will provide information about my system’s base currency to my agent. This makes my solution more generic. The result of this flow is per example:

{
    "CurrencyCode": "EUR",
    "CurrencyName": "Euro",
    "CurrencySymbol": "€",
    "CurrencyId": "3410b343-96f5-ef11-be20-0022485c94c7"
}

Afterwards, I’m adding another tool to my agent. Here I’m utilizing the Dataverse action List row from selected environment:

I’m using these input parameters for my new tool List existing currencies:

As result, my agent has now three flows tools and one connector tool:

Finally, it’s time to improve my instruction. Here I’m specifying in more detail what my agent should do:

## Tools
- Use always "🤖 Get Base Currency" to get the base currency code!
- Use "List existing currencies" to get the current currencies.
- Retrieve the actual exchange rates for the base currency code with "🤖 Get Currency Exchange Rates"

In detail, I’m introducing first of all my added tools. Here I’m pointing out that my agent should always get information about my base currency. Additionally, tell the agent that he can use List existing currencies to get information about my currently configured currencies.

Next, I’ explaining my agent step-by-step how it should update currencies in my system:

## Update of Currencies
- Get first the base currency.
- Next, get all currencies of the system.
- Now get the current exchange rates for the base currency.
- Note down for each currency the code and exchange rate as XML with attributes "CurrencyCode" and "ExchangeRate" of all currencies except the base currency.
- From the noted XML run "🤖 Update Currency Exchange Rate" for each line. Skip, when the "CurrencyCode" is equal to the "CurrencyCode" of the base currency.
- Finally generate a well formatted summary of the updated currencies and their rates for the end user.

I’m also advising here my agent in the steps to write down collected information as XML. I got this trick from Robin Rosengrün. Robin told me that AI understands better parameters that are wrapped with XML tags. I must say, it works well.

The parameters are now correctly transferred to my flow:

Automated my Updates

As last improvement I’m adding a recurring trigger to my agent:

My triggers instruction is this:

Update the exchange rates of the active currencies (except base currency).

As result, my agent starts and get first the base currency. Afterwards it is querying the existing currencies and gets the current exchange rate for my configured base currency. Once this is done, my agent starts to update all my configured currencies, except my base currency.

Lastly my agent summarizes the whole process and lists all currencies:

Well done!

Summary

In this post, I showed you how a small real-world problem inspired me to build my first agent. First, a receipt with the wrong currency led me to dive into the topic of managing multiple currencies in Dataverse. From there, I discovered how an agent can help me keep everything in sync.

In detail, I built an agent in Copilot Studio from scratch. Here I added a few Power Automate flows that help my agent as tools. These tools get the exchange rates from an external API and update data in Dataverse. In my next step I drafted and tested the first instructions. Here I discovered that flows with lots of parameters didn’t work well. As a result, I refactored my agent, introduced additional tools, and refined my instructions. I did this to describe more precisely what the agent should do and how it should use my tools. Finally, tests showed me that my improvement worked as expected.

Along the way, I learned that Copilot Agents can simplify tasks that involve several steps and decisions. Even if automation works in this scenario, an agent can make the flow easier and more flexible. And building one is actually fun. I’m pretty sure my agent can already do more than a simple automated workflow.

This small example showed me that I don’t need a big or complex scenario to start. A simple problem is enough. It already proves how useful Copilot Studio agents can be in real situations.

Share

Leave a Reply