Following my earlier post about creating an agent flow. I’m now writing about error handling in Agent Flows. How do we handle basic failures within agent flows?

An example error

First of all I created a flow that will generate an error. The following flow will of course fail.

A failing Agent flow example
A failing Agent flow example

Now we have multiple types of error that an agent flow may generate.

  • Coding mistakes
  • Unexpected failures

For Coding mistakes like shown above we don’t want any real error handling be put in place as we need to fix this. These kinds of errors should not ever get to a production system.

When however we get to issue where for example an action fails because of a timeout or unavailable API then a retry or an email reporting the error may be useful. Like with cloud flows we could implement a try-catch pattern.

Before we look at how to handle the errors, I want to have a look at how the agent behaves. When the failure occurs we’re twice asked to Allow a connection to Microsoft To-Do.

Our agent flow is called twice as there is no error handling in place
Our agent flow is called twice as there is no error handling in place

When we look at the action calling the Agent flow then there is no setting for retries. However the flow is definitely called twice, when things go wrong.

We can't set the retry policy
We can’t set the retry policy

How can we sort this behaviour out? If we compare this to calling a child flow in Power Automate cloud flows then we can adjust the retry policy.

Implement Error Handling in Agent Flows

Similar to the cloud flow we could implement the try catch pattern.

Error handling implemented with a classic try-catch with scopes
Error handling implemented with a classic try-catch with scopes

If we now test our Agent flow again we will find that the retry doesn’t happen. Why not? Well that is simple.

Our Agent flow only runs once
Our Agent flow only runs once

The calling of the Agent flow retries only when we have an agent flow not returning a response. In our case we are telling the agent to respond with a failure message. This way the user gets informed about the issue. Therefore technically the flow doesn’t fail anymore.

The message that is returned to the user needs to be handled in a slightly better way of course. But that is just a small detail now.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.