> ## 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

> Nechte agenta generovat dokumenty z chatu, pomocí vašeho nástroje.

Protože je `generate-document` vystaven jako **nástroj**, agent AI ho může zavolat.
Přidejme agenta a dovednosti, aby uživatelé mohli říci *"vygenerovat návrh
Jeffery Griffin"*.

## Dovednost

[skill](/l/cs/developers/extend/apps/logic/skills-and-agents) je opakovaně použitelné
– znalosti, které připojujete k agentům. Náš model učí jak použít
nástroj.

```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'),
});
```

## Zástupce

[agent](/l/cs/developers/extend/apps/logic/skills-and-agents) spáruje výzvu s modelem
. Nastavte `responseFormat` explicitně, abyste se vyhnuli varování sestavení.

```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>
  Zástupce může zavolat nástroj pouze v případě, že jej jeho role umožňuje. Již jsme nastavili
  `canAccessAllTools: true` a `canBeAssignedToAgents: true` na roli aplikace v
  [Chapter 2](/l/cs/developers/extend/apps/tutorials/document-generator/generating-documents#grant-it-access).
</Note>

## Vyzkoušejte

Otevřete chat s **asistentem dokumentu** a požádejte jej, aby připravil dokument pro osobu
ve vašem CRM. Najde záznam, volání `generate-document`, a nahlásí
dokument, který vytvořil – který se nyní zobrazí ve tvém **dokumentu** zobrazení,
přesně se líbí příkazové menu a cesty workflow.

To je výsledek odhalování logiky jako nástroje: **jedna funkce, mnoho předních dveří** —
příkaz menu, HTTP, krok workflow a nyní přirozený jazyk.

**Po tomto kroku:** je aplikace kompletní a opravdu užitečná. Čas do
lodi.

<Card title="Další: publikování →" icon="rocket" href="/l/cs/developers/extend/apps/tutorials/document-generator/publishing">
  Přidat metadata a publikovat tržiště.
</Card>
