Create a custom agent query

The agent query is a custom flexible (agent-person-level) query template that lets you extract agent activity and adoption data across Microsoft 365 apps - the same metrics that power the Agent 365 Dashboard - and deliver it through any of the standard query output channels, like .csv download, Power BI connection, or Azure Data Lake. Its reporting history covers the period after which your organization accepted the terms of use of Agent 365 licensing.

The agent query's scope covers all agents your organization manages, including agents built in Azure AI Foundry, and covers both active and inactive agents, so you can report on inventory as well as usage.

Prerequisites and eligibility

Your tenant must have at least 50 Microsoft 365 Copilot licenses, and at least 1 Agent 365 license and have agent activity.

The query is available to both global and partitioned analysts. Partitioning follows the same design used elsewhere in Viva Insights, based on person rows and HR attribute columns.

The analyzed population includes all employees who have had agent activity, regardless of their Copilot license status.

Use the steps below to set up and run the query.

1. Set up your query

In the Viva Insights web app, on the left, select Create analysis. Select Custom query, then select Agent query. This Agent 365 activity query includes insights for all agents that Agent 365 manages in your organization.

Under Basic query information:

  1. Name your query. Queries are assigned a default name, which follows this format: query type, user ID, date, and time. Make sure the name is unique.

  2. Type a description.

  3. Select a time period. Choose the range your query analyzes (for example, last 3 months, or a custom start and end date).

  4. Set Auto refresh. When turned on, your query runs automatically and refreshes whenever a new, complete set of data becomes available, based on the aggregation type (Group by) you selected.

  5. Set Group by to Days, Weeks, or Months.

2. Select your metrics

Select Add metrics, then choose the metrics you want. You can choose amongst these three metrics:

Metric Type
Returning agent user (most recent and prior 7 days) number
Returning agent user (most recent and prior 28 days) number
Conversational Agent Sessions number

To remove a metric, select the "X" on it.

3. Add conditions and condition groups

Use conditions and condition groups to identify which agent or employees to analyze in your query. The agent query supports two separate filter sections:

  • Set up filters for agents - filter on agent attributes, such as agent name, creator type, or publishing source.

  • Set up filters for employees - filter on HR attributes, such as Organization, Function, or Level.

In either section, select Add condition or Add condition group.

Note

The default conjunction for conditions and condition groups is "and." To select "or" instead, use the dropdown menu.

4. Select agent attributes and HR attributes

Select the Select attributes button, then use the checklist to add attributes to each output row. When you're done, select Add to query.

Agent attributes

The attribute set covers the full set of inactive and active agents.

Attribute Values
Agent name -
Creator name -
Creator Type
  • User: Agents built by users and optionally shareable with others
  • Your org: Admin-approved agents built by and for your organization
  • Microsoft: Agents built by Microsoft
  • Third party: Admin-approved agents built by a third party
  • Description -
    Publishing source Agent source is based on where an agent was built. The options might include:
  • Agent Builder: A quick and easy interface for end users to build Copilot agents for themselves or small teams. Learn more.
  • Microsoft Copilot Studio: The full agent building experience with advanced capabilities for building and publishing agents to broader audiences. Learn more.
  • Microsoft SharePoint: An experience for end users to build agents accessible SharePoint directly. Learn more.
  • Microsoft 365 Agents Toolkit: A pro-code suite of tools to build enterprise-ready agents that can be published across multiple channels. Learn more.
  • Other Microsoft: Used for agents built on Microsoft platforms when the exact source can't be identified.

    Visit the Microsoft Adoption AI Agents Hub to learn more about different options to build and deploy agents in your organization.
  • HR attributes

    The HR attribute set isn't fixed. The people metadata output file includes one column per attribute you select, so the file's columns vary from query to query. Select fewer attributes to keep your output file smaller.

    5. Run the query

    Select Run in the screen's upper right to run the query.

    After your query runs, access its results on the Analysis results page, where you can download the output, copy the connection link for Power BI or Azure Data Lake, and edit or clone your query.

    Output files

    Each run produces a set of .csv files. The Agent 365 activity output and the Agent 365 registry output use the same file structure.

    Use AgentId to join agent metadata to the activity metrics, and PeopleHistoricalId to join the activity metrics to the people metadata.

    File 1 - Agent metadata (AgentMetadata)

    One row per agent. This file includes both active and inactive agents.

    Column Type Description
    AgentId string Unique identifier for the agent
    AgentName string Display name of the agent
    AgentShortDescription string Description of the agent
    CreatorName string Name of the creator; null for Microsoft-published agents
    CreatorType string Who created the agent - for example, Microsoft, Your org, or User
    PublishingSource string Where the agent was published from - for example, Microsoft Copilot Studio or Other

    File 2 - Activity file (PersonAgentActivityMetrics)

    One row per PersonID, AgentId, and MetricDate.

    Column Type Description
    PersonID string Unique identifier for the user
    AgentId string Unique identifier for the agent or, for an agent with identity, the instance ID
    MetricDate date Day of activity
    Returning agent user (most recent and prior 7 days) number Whether the person is a returning agent user across the most recent and prior 7 days
    Returning agent user (most recent and prior 28 days) number Whether the person is a returning agent user across the most recent and prior 28 days
    Conversational Agent Sessions number Number of conversational sessions for the PersonID and AgentId on MetricDate
    PeopleHistoricalId string Join key to the people metadata file

    File 3 - People metadata file (PeopleMetadata)

    One row per person. Columns vary based on the HR attributes you selected during setup, plus the default column below.

    Column Type Description
    PeopleHistoricalId string Join key to the activity and session files
    <HR attribute 1...N> string One column per HR attribute selected during setup - for example, Organization or FunctionType

    Example query for agent adoption by team

    Let's say you want to see which teams are getting the most value from the agents your organization manages, broken out by week. You want to:

    • Analyze your company's "West" organization only

    • Include only agents that are created by Microsoft

    • See data for the last three months, grouped by week

    • Include each person's Organization and Level in the output

    Here's how you might do that:

    1. Set up your query.
    • Query name: Enter something like "A365_West_Weekly".

    • Time period: Select Last 3 months.

    • Auto refresh: Off.

    • Group by: Select Weeks.

    1. Select your metrics. Select Add metrics, then add Returning agent user (most recent and prior 28 days) and ConversationalAgentSessions.

    2. Specify the population. Under Set up filters for agents, select Add condition, select CreatorType, then next to the operator select = and select Microsoft. Under Set up filters for individuals, select Add condition, select Organizational data, select Organization, then select = and West.

    3. Select attributes. Select Select attributes, choose Agent name, Publishing source, Organization, and Level, then select Add to query.

    4. Run the query. Select Run. After it runs, download the output from the "Downloads" column on the Analysis results page.