Automating Power Platform Diagnostics with an Agent Harness
November 30, 2026 · 7 min read · Sadi Redwan

Every long-running Dynamics 365 or Power Platform environment develops a quiet backlog. A flow that stopped firing in August. A classic workflow sitting in Waiting with an error nobody read. Forty plug-in exceptions from one bad afternoon. None of it is urgent enough to page anyone, and all of it is invisible until someone says the thing they do every Tuesday has stopped working.
The usual answer is a periodic look around the admin centre. That works until you are doing it across several environments, and until you notice how much of it is the same clicking every time: open the flow, filter the run history, copy the error, check whether it is the same error as last time. The obvious move is to automate it, and the interesting question is which parts to automate with code and which parts need an agent.
This is a technical overview of a harness that does both: a read-only collector that pulls an environment's diagnostics out of the platform APIs into a single file, and an agent that reads that file, compares it with the previous one and explains what changed. The language model in the middle is deliberately replaceable.
The data is already there, it is just scattered
Almost nothing in a Power Platform health check needs a new monitoring agent installed anywhere. The platform already records what you want. The problem is that it records it across four different services, each with its own API, its own idea of a time window and its own token audience.

Four services, one collector, one snapshot per run.
Dataverse gives you system jobs, plug-in trace logs and audit volume through the Web API. The Power Automate API gives you flow run history with the failing action and its error message, which is the part you actually need and the part the Dataverse flow run table will not keep for long. The admin API gives you capacity and environment metadata. The Power Apps API gives you connection status and ownership.
The first real piece of engineering is not AI at all. It is one authentication that covers all four. A single interactive sign-in, cached on disk, with silent token refresh per audience. Get that wrong and every run becomes a browser pop-up, which is the one thing that stops a scheduled job being a scheduled job.
The second is a fixed window. Pick a period, state the time zone, and bucket everything by day inside it. Without that, two runs cannot be compared without an argument about boundaries.
The output is one JSON file. That file is the contract between the deterministic half of the system and the probabilistic half.
Keep the collector dumb
The strongest design decision in this shape is that the collector does not reason. It queries, counts and writes. It never decides whether something is a problem.

One sign-in check, one collector run. Everything after this reads the snapshot, not the platform.
That separation pays for itself three ways. The collector is testable, because the same window always produces the same numbers. It is cheap, because you pay for the slow API calls once and then re-read a local file as often as you like while iterating on the output. And it is honest: when a number looks wrong, you can point at the query that produced it instead of wondering what the model inferred.
It also means the agent never holds credentials to anything that can write. The collector's identity is read-only on production, and that is enforced by the security role, not by asking nicely in a prompt.
A few details that cost time, in case they save you some:
- The non-admin flow runs endpoint is more reliable than the admin one for listing runs, but it will not tell you which flows exist. Enumerate flows from Dataverse, then ask the flow API about each one.
- Zero runs does not mean unused. A started flow with no runs, in an environment full of rows that should have triggered it, is the most interesting line in the whole output and the easiest to miss.
- Aggregate queries have row caps. Past a few tens of thousands of rows you need to page and count yourself rather than trust a single aggregate.
- Some numbers the admin centre shows on screen have no API behind them. Collect what you can query and state plainly what you cannot.
- Run history windows differ by service. If you want history beyond a few weeks, you have to keep it yourself.
What the agent is actually for
Given a snapshot, producing something readable is not a formatting job. The hard part is judgement: this error and that error are the same underlying fault; this one was fixed last month and has come back; this burst of exceptions is the service having a bad hour, not your plug-in.

Fifty raw failures usually collapse into a handful of real issues.
That is a good fit for a model and a bad fit for a rules engine, because error text is written by humans and by Microsoft and varies in ways you cannot enumerate ahead of time. Two failures reading "Cannot find record to be updated" on the same flow a week apart are obviously one issue; a regular expression gets that right until the day the message changes.
It is also a job with a hard boundary. The agent reads a file and writes a document. It does not call the platform, and it cannot change anything in the environment.
The rules file matters more than the model
The most valuable artefact in a harness like this is not a script. It is a short markdown file holding the things that are invisible in the data.
Some of it is environment knowledge: which environments exist and which tier each one is, the publisher prefix, which integrations are in use, which faults are already known and being worked on. Without that last part, a recurring issue gets rediscovered with fresh enthusiasm on every run.
The rest is operating rules, and these are what make the thing safe to point at a production tenant. Stay inside the repository. Write generated output to one known folder. Never import an unmanaged solution. Treat any write to a non-development environment as something that needs explicit approval first, and default to read-only everywhere else.
Keep both next to the code, in version control, and update them the day something changes. A model reads them every session; a person reads them when they join the project.
How the repository is laid out
The structure is ordinary, which is the point. Anyone can open it and see where things go.

Rules at the top, one thin CLI, snapshots kept, everything generated in a gitignored folder.
Three conventions do most of the work. Reusable capability goes into the shared CLI rather than a one-off script, so the next environment benefits from the last one's debugging. Environment knowledge goes in a file, never in a prompt typed from memory. And the environment registry carries a tier on every entry, so the tooling knows which ones are production before anyone asks it to do something clever.
Snapshots are kept rather than overwritten, because comparison against the previous run is the feature that makes the output useful rather than merely long.
Where it genuinely helps, and where it does not
Collection is the honest win. Several APIs, a consistent window, day-wise counts, no clicking, and numbers that do not drift depending on who ran it.
Correlation is the subtler win. Grouping fifty raw failures into four real issues, spotting that one of them is last month's fix quietly reopening, noticing that a flow with no runs should have had forty-six — that is where a model earns its place, and it is the part that otherwise depends on whoever has the longest memory of the project.
Fixing is not automated here, and there is no hurry to change that. The harness can tell you a connection reference points at a connection owned by someone who has left. A person decides what to do about it. On a production tenant, the distance between reading and writing is a feature, not a limitation to engineer away.
And it does not replace monitoring. A periodic snapshot finds slow rot. It will not tell you that an integration broke an hour ago. Different problem, different tool.
If you build one
- Separate collection from interpretation, and make the snapshot a file you can open and read.
- Solve authentication once, with a cached token and silent refresh across every audience you need.
- Fix the window, state the time zone, bucket by day.
- Keep the previous snapshot. Comparison is where the value is.
- Write the environment's facts and the operating rules down in one short file, and treat it as code.
- Give the agent read-only credentials and let a person approve anything that writes.
The result is not impressive to look at. It is a folder of small scripts, a markdown file of rules, and output that is right. On a platform that quietly accumulates failure, that turns out to be worth a lot.
Cover image: Luke Chesser on Unsplash. Diagrams and terminal output are illustrative, with generic environment names and sample numbers.

Comments
No comments yet. Start the conversation.