Saturday, February 7, 2026

Create a D365FO App Insight Agent to Execute KQL Queries with Natural Language

 Working with D365FO telemetry in Application Insights usually requires writing complex Kusto Query Language (KQL). This becomes a challenge for many functional or support users who need insights quickly but are not comfortable writing KQL.

To solve this, you can build an AI Agent that generates and executes KQL queries at runtime using simple natural language prompts. The agent uses a knowledge source containing KQL templates and builds the final query dynamically.

Agent flow / Architecture

Article content

Below are the simple steps to build your own D365FO App Insights Agent.

🧩 Step-by-Step Guide

Step 1 – Create the Agent

Go to copilotstudio.com → Create a new agent. Use a prompt like:

“Create an agent to generate and execute Kusto queries at runtime using Azure Monitor Logs. The agent will use a knowledge source file containing Kusto query templates to build runtime queries.”

Step 2 – Select the Model & Disable Web Search (Important)

For predictable and accurate KQL generation:

  • Model: Select Claude Sonnet 4.5 (recommended)

Article content

  • Web Search: Disable it This ensures the agent uses only your knowledge source file and does not hallucinate or pull irrelevant query patterns from the internet.

Article content

Step 3 – Add Azure Monitor Log Query Tools

Go to the Tools section → and search for below tools and add one by one

1. Run Query and List Results,

2.Run Query and Visualize Results (optional)

Article content

These enable the agent to execute the KQL it generates.

Please add the tool reference in the instruction by guiding agent to use these tools to run the KQL

Article content
Add tool reference in the instructions

Step 4 – Generate Your Knowledge Source File

Use M365 Copilot to convert your sample KQL dashboard JSON files into a clean template catalog.

Use public repsitory to get the sample dashboards

https://github.com/microsoft/Dynamics-365-FastTrack-FSCM-Telemetry-Samples/tree/main/Dashboards/AzureDataExplorer

Attach your files and use a prompt like:

“I built an agent to generate and execute Kusto queries at runtime using Azure Monitor Logs. I need a JSON knowledge source file with KQL templates based on the attached scenario files.”
Article content

Copilot will produce a structured JSON that your agent can consume. You can download the template file from copilot to upload as a knowledge source (LLM) for you agent.

Step 4 – Add Your Knowledge Source File

Go to Knowledge Sources → Upload the JSON file that contains your KQL template scenarios (batch telemetry, long-running forms, SQL issues, error lookups, etc.) generated from the previouse steps.

Article content

The agent will use these templates to build queries at runtime.

Step 6 – Test Your Agent

Your agent is now ready. you can try prompts like:

  • “Show top 5 slow-running forms”
  • “Find batch failures in the last 24 hours”
  • “Show SQL timeout errors today”
  • “List long-running batch jobs”
  • “Show errors for sales posting”

Article content
Agent prompts and results


The agent will:

  • Understand your question
  • Locate the relevant KQL template
  • Build the final KQL dynamically
  • Run it
  • Present results in natural language

No KQL knowledge required.


🎯 Why This Is Useful


  • Removes the need to learn KQL
  • Speeds up Root Cause Analysis (RCA)
  • Helps functional, support, and operations teams use telemetry effectively
  • Reduces dependency on senior engineers
  • Turns Application Insights into a natural-language analytics tool for D365FO

No comments: