> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twenty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 5. An AI agent

> エージェントに、あなたのツールを使用して、チャットからドキュメントを生成させます。

`generate-document` は **tool** として公開されているため、AI エージェントはそれを呼び出すことができます。
ユーザーが \*"
Jeffery Griffinの提案を生成する"\*と言えるように、エージェントとスキルを追加しましょう。

## スキル

[skill](/l/ja/developers/extend/apps/logic/skills-and-agents) は
命令を再利用できます — エージェントに付与する知識です。
ツールの使い方をモデルに教えます。

```ts filename="src/skills/document-drafting.skill.ts" theme={null}
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](/l/ja/developers/extend/apps/logic/skills-and-agents) はプロンプトを
モデルとペアリングします。 ビルド警告を避けるため、明示的に `responseFormat` を設定してください。

```ts filename="src/agents/document-assistant.agent.ts" theme={null}
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(' '),
});
```

<Note>
  エージェントは、そのロールが許可している場合にのみツールを呼び出すことができます。 すでにアプリのロールに対して
  `canAccessAllTools: true` と `canBeAssignedToAgents: true` を設定済みです。
  詳しくは、[第2章](/l/ja/developers/extend/apps/tutorials/document-generator/generating-documents#grant-it-access) を参照してください。
</Note>

## お試しください

**ドキュメントアシスタント** とのチャットを開き、CRM内の
人のためのドキュメントを下書きするように依頼します。 レコードを見つけて `generate-document` を呼び出し、作成したドキュメントを返します — そのドキュメントは、コマンドメニューやワークフロー経由の場合とまったく同様に、**Documents** ビューに表示されます。

これは、ロジックをツールとして公開するための報酬です: **1つの関数、多くのフロントドア** —
コマンドメニュー、HTTP、ワークフローステップ、そして現在の自然言語。

**このステップの後:** アプリは機能が完了し、本当に便利です。
に出荷しましょう。

<Card title="次へ: 公開 →" icon="rocket" href="/l/ja/developers/extend/apps/tutorials/document-generator/publishing">
  マーケットプレイスのメタデータを追加して公開します。
</Card>
