Breyta

getCurrentAgent (Client API reference)

Returns the currently active Microsoft 365 Copilot agent, or undefined if the agent state is not yet known.

Syntax

Xrm.Copilot.getCurrentAgent().then(successCallback, errorCallback);

Parameters

Parameter Name Type Required Description
successCallback Function Yes A function to call when the operation succeeds.
errorCallback Function Yes A function to call when the operation fails.

Return Value

Type: Promise<M365CopilotAgent | undefined> — Resolves to an M365CopilotAgent object describing the active agent, or undefined if the agent state isn't determined yet.

Remarks

Does nothing if Microsoft 365 Copilot isn't enabled.

The returned object's agentId and mode properties are paired:

  • agentId is a non-null string and mode is "agentPage" or "mentioned": an agent is active.
  • agentId is null and mode is null: the user is on mainline Microsoft 365 Copilot (no agent active).

Example

const agent = await Xrm.Copilot.getCurrentAgent();
if (agent && agent.agentId) {
    console.log(`Active agent: ${agent.agentId}, mode: ${agent.mode}`);
} else if (agent) {
    console.log("User is on mainline M365 Copilot (no agent).");
} else {
    console.log("Agent state not yet determined.");
}

M365CopilotAgent interface
Xrm.Copilot (Client API reference)