
Global Copy:增强 Action 响应可用性
Global Copy 为用户提供了一致的方式从 Agentforce 响应中的 UI 组件复制信息。在通过 Lightning Types 构建的自定义 LWC 中,实现一个 @api getFormattedValue() 公共方法即可启用此功能。当用户点击复制按钮时,系统调用此方法获取剪贴板内容,开发者可以完全控制复制内容和格式。
getFormattedValue() 方法要求
必须使用 @api 装饰
必须返回 String(纯文本或富 HTML)
由系统在用户点击复制按钮时调用
开发者可完全控制复制内容和格式
五步实现模式 —— 富 HTML 表格示例
- 初始化 HTML 表格:创建带内联 CSS 样式的表格字符串。
let table = '<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse;">';
2. 构建表头行:迭代 `this.fields`,为每个字段创建 `<th>` 单元格,内容为 `field.label`。
3. 构建表格主体:迭代 `this.records`,为每条记录创建 `<tr>` 行。
4. 填充数据单元格:嵌套循环 —— 对每条记录迭代字段,用 `record.fields[field.apiName].value` 创建 `<td>`。
5. 完成并返回:追加闭合 `</table>` 标签,返回完整 HTML 字符串。
当用户点击复制:方法运行 → 提供格式良好的结构化 HTML → 可直接粘贴到邮件、文档或其他系统中。

## Apex Citations:通过来源标注建立信任
Citations 让开发者能够程序化地向自定义动作添加来源引用。支持通过 Employee Agent 和 Agent API 使用。支持的来源包括非结构化数据:Knowledge 文章、PDF 文件和外部网页。

### 两种 Citation 方式
方式工作机制适用场景
GenAiCitationInput向推理引擎提供引用信息,引擎自动确定在何处和如何添加引用你希望 Agent 从提供的来源中自动确定相关引用
GenAiCitationOutput直接控制自定义动作如何展示引用,绕过推理引擎的逻辑你有应始终返回的特定、预定的引用
### 关键决策指南
- 让引擎决定 → GenAiCitationInput(从来源生成文本,自动确定引用)
- 你确切知道要引用什么 → GenAiCitationOutput(显式的预定引用)
前提条件:组织中已启用 Agentforce Agent、具有 Apex 自定义动作经验、平台生成的引用适用于 2025 年 5 月 26 日后创建的 Agent。对于 GenAiCitationInput,还需启用 Prompt Builder。

## 示例:带 RAG 的内联引用
KnowledgeBaseApex 类展示了完整的内联引用实现:
### 架构流程
- execute() 方法 —— 通过 Connect API 调用 Knowledge_Search Prompt Template,设置 `citationMode='post_generation'` 启用内联引用。返回 EinsteinPromptTemplateGenerationsRepresentation(LLM 响应 + 引用)
- transform() 辅助方法 —— 将 Connect API 引用格式转换为 AiCopilot 格式:`transform(GenAiSourceReference)` 映射 fieldName/objectName/content → GenAiSourceContentInfo、`transform(CitationOutput)` 迭代 sourceReferences → GenAiCitationInput
- InvocableMethod (executePrompt) —— Agent Action 的入口点,@InvocableMethod(label='Call Knowledge Prompt Apex'):输入 Request { Question } → 调用 execute() → 获取 LLM 响应 → 转换引用 → 返回 Response { Data (String), sources (GenAiCitationInput) }
### Response 类结构
`public class Response {
@InvocableVariable(required=true description='Generated text response from LLM')
public String Data;
@InvocableVariable(required=true description='Structured citation sources')
public AiCopilot.GenAiCitationInput sources;
}`
数据流
用户提问 → executePrompt() → Connect API(Prompt Template + RAG)→ LLM 生成文本 + 自动检测引用 → 将引用转换为 AiCopilot 格式 → 返回文本响应 + GenAiCitationInput → Agent 显示带内联引用的响应。
关键集成点
Prompt Template 开发者名称必须匹配(''Knowledge_Search'')
输入参数名称必须匹配模板变量('Input:Question')
citationMode: 'post_generation'启用自动内联引用检测

Global Copy 和 Apex Citations 从实用性和可信度两个维度增强 Agent Action 的响应质量 —— 一键复制格式化内容提升效率,来源标注建立用户信任。
发布来源:https://www.salesforcecrm.cn/article/agentforce/agentforce-action-responses-guide.html