# Agents

> What an agent is made of: instructions, a greeting, a voice, a model and its tools.

An agent is a saved set of decisions about a voice conversation: what it is for, how it opens, how it sounds and what it is able to do. Every call runs on one agent.

## What an agent is made of

- `systemInstruction` (Instructions): Who the agent is, what it helps with and how it should speak. This is the part you will spend the most time on.
- `greetingMode` (Greeting): How the call opens: the model writes a line from `greetingInstruction` (`generate`), a fixed `greetingText` is spoken (`static`), or the agent waits for the caller (`none`).
- `voice` (Voice): The voice engine, the language, the voice itself, and its speed, volume and emotion.
- `llm` (Model): The model that writes replies, its temperature and how long a reply may be.
- `variables` (Variables): Named blanks in the instructions that each call fills in, such as the caller’s name.
- `toolIds` (Tools): Your HTTP endpoints the agent may call while it talks.
- `documentIds` (Knowledge): The documents it answers from: price lists, policies, FAQs.
- `systemTools` (Built-in tools): Things the agent may do on its own: end the call, switch language.
- `webhookUrl` (Webhook): A URL that is sent every event of this agent’s calls.
- `embed` (Call button): Whether its publishable key may start calls from a web page, and the limits on that.

## Create an agent

Only `name` and `systemInstruction` are required. Whatever you leave out starts from the platform’s defaults, which you can read from [Get the catalog](https://www.cracklehq.com/docs/reference/catalog).

Request:

cURL:

```bash
curl -X POST "https://goblins-call-api.onrender.com/v1/agents" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Front desk",
  "systemInstruction": "You answer calls for Sunrise Dental. Help callers book, move or cancel an appointment. Keep every reply to one or two short sentences.",
  "greetingInstruction": "Greet {{customer_name}} warmly in one short sentence.",
  "voice": {
    "language": "en"
  },
  "variables": {
    "customer_name": {
      "defaultValue": "there"
    }
  },
  "systemTools": {
    "endCall": true
  }
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/agents', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Front desk',
    systemInstruction: 'You answer calls for Sunrise Dental. Help callers book, move or cancel an appointment. Keep every reply to one or two short sentences.',
    greetingInstruction: 'Greet {{customer_name}} warmly in one short sentence.',
    voice: {
      language: 'en',
    },
    variables: {
      customer_name: {
        defaultValue: 'there',
      },
    },
    systemTools: {
      endCall: true,
    },
  }),
});
if (!response.ok) throw new Error(await response.text());
const { agent } = await response.json();
```

Python:

```python
import os
import requests

response = requests.post(
    "https://goblins-call-api.onrender.com/v1/agents",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "name": "Front desk",
        "systemInstruction": "You answer calls for Sunrise Dental. Help callers book, move or cancel an appointment. Keep every reply to one or two short sentences.",
        "greetingInstruction": "Greet {{customer_name}} warmly in one short sentence.",
        "voice": {
            "language": "en",
        },
        "variables": {
            "customer_name": {
                "defaultValue": "there",
            },
        },
        "systemTools": {
            "endCall": True,
        },
    },
    timeout=30,
)
response.raise_for_status()
agent = response.json()["agent"]
```

The response carries the agent’s `id`. That is what you send as `agentId` to [start a call](https://www.cracklehq.com/docs/reference/calls/start).

## Change an agent

[Update an agent](https://www.cracklehq.com/docs/reference/agents/update) changes the fields you send and leaves the rest. `voice`, `llm` and `stt` are merged field by field, so you can change the speed without restating the voice. `variables` is replaced as a whole.

Request:

cURL:

```bash
curl -X PATCH "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "voice": {
    "speed": 1.1
  }
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b', {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    voice: {
      speed: 1.1,
    },
  }),
});
if (!response.ok) throw new Error(await response.text());
const { agent } = await response.json();
```

Python:

```python
import os
import requests

response = requests.patch(
    "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "voice": {
            "speed": 1.1,
        },
    },
    timeout=30,
)
response.raise_for_status()
agent = response.json()["agent"]
```

> A call uses the agent as it was saved when the call started. Changing an agent never alters a call that is already under way.

## Writing instructions

The agent is heard, not read, and that changes what good instructions look like.

- **Ask for short replies.** One or two sentences per turn keeps a conversation moving. `llm.maxTokens` also caps how long a reply can run.
- **Say what to do when it does not know.** An agent that may say “I’ll have someone call you back” is more useful than one that guesses.
- **Name the tools.** Mention a tool as `@check_order_status` where the instructions say when to use it. See [Tools](https://www.cracklehq.com/docs/tools).
- **Leave blanks for what changes per caller.** Write `{{customer_name}}` and fill it in on each call. See [Variables](https://www.cracklehq.com/docs/variables).

### What is added to your instructions

When a call starts, your instructions are combined with a few things you do not have to write yourself: how to run the tools you have switched on, how to use the built-in tools, and writing rules for the agent’s voice, such as how to write numbers so they are read out properly. To leave the writing rules out, save the agent with `voice.speechRules` set to `false`.

## What an agent costs

Each agent has a `costPerMinute`, set by the platform, which is what a minute of its calls takes from your balance. See [Pricing and billing](https://www.cracklehq.com/docs/billing).

Source: https://www.cracklehq.com/docs/agents
