Skip to main content
Because generate-document is exposed as a tool, an AI agent can call it. Let’s add an agent and a skill so users can just say “generate a proposal for Jeffery Griffin”.

The skill

A skill is reusable instructions — knowledge you attach to agents. Ours teaches the model how to use the tool.
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'),
});

The agent

An agent pairs a prompt with a model. Set responseFormat explicitly to avoid a build warning.
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(' '),
});
The agent can only call the tool if its role allows it. We already set canAccessAllTools: true and canBeAssignedToAgents: true on the app’s role in Chapter 2.

Try it

Open a chat with Document Assistant and ask it to draft a document for a person in your CRM. It finds the record, calls generate-document, and reports back the document it created — which now appears in your Documents view, exactly like the command-menu and workflow paths. That’s the payoff of exposing logic as a tool: one function, many front doors — command menu, HTTP, workflow step, and now natural language. After this step: the app is feature-complete and genuinely useful. Time to ship it.

Next: publishing →

Add marketplace metadata and publish.