getCurrentAgent (客户端 API 参考)

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

Syntax

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

Parameters

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

返回值

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

Remarks

如果未启用智能 Microsoft 365 Copilot 副驾驶®,则不执行任何操作。

返回的对象 agentIdmode 属性已配对:

  • agentId是非 null 字符串,是mode"agentPage""mentioned":代理处于活动状态。
  • agentIdnullmodenull:用户处于主线智能 Microsoft 365 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 参考)