跳转到主要内容
因为生成文档 暴露于一个 工具*,故AI 代理人可以调用它。 让我们添加一个代理人和技能,用户可以说*“生成一个 Jeffery Griffin”*。

技能

skill 是可重复使用的 说明 — — 您附加到代理的知识。 我们教的模型如何使用 这个工具。
import { defineSkill } from 'twenty-sdk/define';

export default defineSkill({
  universalIdentifier: DOCUMENT_SKILL_UNIVERSAL_IDENTIFIER,
  name: 'document-drafting',
  label: 'Document drafting',
  icon: 'IconFileText',
  content: [
    'To generate a document, call the `generate-document` tool with:',
    '- `templateId`: the id of the document template to use.',
    '- `recordId`: the id of the Person or Company the document is for.',
    '',
    'If the user names a template or person instead of an id, find the record first,',
    'then pass its id. Make sure the template target matches the record type.',
  ].join('\n'),
});

代理

agent 与 模型配对一个提示。 明确设置 “responseFormat” 以避免构建警告。
import { defineAgent } from 'twenty-sdk/define';

export default defineAgent({
  universalIdentifier: DOCUMENT_AGENT_UNIVERSAL_IDENTIFIER,
  name: 'document-assistant',
  label: 'Document Assistant',
  description: 'Generates documents from your templates and CRM records.',
  icon: 'IconFileText',
  responseFormat: { type: 'text' },
  prompt: [
    'You are the Document Assistant for a CRM.',
    'You help users generate personalized documents from reusable templates',
    'and the data already in their CRM. Use the generate-document tool, and',
    'always confirm what you created.',
  ].join(' '),
});
代理只能在其角色允许的情况下调用工具。 我们已经在应用的角色中设置了 canAccessAllTools: truecanBeAssignedToAgents: true, 详见第 2 章

试试

打开与 Document Assistant 的聊天,并要求它为您的 CRM 中的 人起草一份文档。 它找到记录, 调用 `generate-document’, 并报告 返回它创建的文档 — 现在出现在你的 Documents 视图中。 就像命令菜单和工作流路径。 这是显示逻辑作为工具的回报:一个函数、多个前门 - 命令菜单、HTTP、工作流步骤以及现在的自然语言。 在这一步之后: 应用程序是功能完整和真正有用的。 送货时间。

下一步:发布 →

添加市场元数据和发布。