getCurrentAgent (客户端 API 参考)

返回当前处于活动状态的Microsoft Copilot 智能体,如果未定义代理状态,则返回未知状态。

Syntax

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

Parameters

参数名称 类型 必需 Description
successCallback 函数 是的 作成功时要调用的函数。
errorCallback 函数 是的 作失败时要调用的函数。

返回值

类型: Promise<M365CopilotAgent | undefined> — 解析为描述活动代理的 M365CopilotAgent 对象,或者 undefined 代理状态尚未确定。

Remarks

如果未启用Microsoft Copilot,则不执行任何操作。

返回的对象 agentId 和 mode 属性已配对:

  • agentId是非 null 字符串,是mode"agentPage"或"mentioned":代理处于活动状态。
  • agentId是null且mode为 null:用户位于主线Microsoft Copilot(无代理活动)。

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 接口
Xrm.Copilot(客户端 API 参考)