# Variables

> Fill an agent’s instructions with what you know about each caller.

Variables let one agent serve every caller. You leave named blanks in the agent’s instructions, and each call fills them with what you know about that caller.

## Define them on the agent

Write a variable as `{{name}}` wherever it should appear, and list it under `variables` with a default:

An agent with two variables:

```json
{
  "systemInstruction": "You are calling {{customer_name}} about order {{order_id}}. Confirm the delivery slot.",
  "greetingInstruction": "Greet {{customer_name}} by name and say you are calling from Sunrise Stores.",
  "variables": {
    "customer_name": { "defaultValue": "there", "description": "The caller's first name" },
    "order_id": { "defaultValue": "your recent order" }
  }
}
```

Variables are filled in everywhere the agent has text of its own:

- the instructions (`systemInstruction`)
- the greeting (`greetingText` and `greetingInstruction`)
- its tools: the URL, the headers and the body of each request

## Fill them in on each call

Send `variables` when you start the call. Names and values are strings.

Request:

cURL:

```bash
curl -X POST "https://goblins-call-api.onrender.com/v1/calls" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "agentId": "ua_3f9a1c2b",
  "variables": {
    "customer_name": "Divya",
    "order_id": "A-1042"
  }
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/calls', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    agentId: 'ua_3f9a1c2b',
    variables: {
      customer_name: 'Divya',
      order_id: 'A-1042',
    },
  }),
});
if (!response.ok) throw new Error(await response.text());
const session = await response.json();
```

Python:

```python
import os
import requests

response = requests.post(
    "https://goblins-call-api.onrender.com/v1/calls",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "agentId": "ua_3f9a1c2b",
        "variables": {
            "customer_name": "Divya",
            "order_id": "A-1042",
        },
    },
    timeout=30,
)
response.raise_for_status()
session = response.json()
```

A variable you do not send takes its default. One with neither a value nor a default is left as written, braces and all, so give every variable a default that still reads naturally.

## Variables that are always there

Tools that run during a call can use two more, which come from the call itself:

- `{{call_id}}` (string): The ID of the call the tool is running in.
- `{{agent_id}}` (string): The ID of the agent on that call.

These, and the variables the call was started with, always win over anything the model supplies as a tool argument. Your endpoint can look a caller up from `{{call_id}}` and trust that it is the real one. See [Tools](https://www.cracklehq.com/docs/tools#trusting-what-reaches-your-endpoint).

## Where they end up

The variables a call started with are kept on the call as `metadata.variables`, so they come back when you [read the call](https://www.cracklehq.com/docs/reference/calls/get) and in every [webhook](https://www.cracklehq.com/docs/webhooks) for it. Sending `metadata.variables` yourself does the same thing as `variables`; where a name is in both, the one in `metadata` is used.

> **Variables are part of the prompt**
>
> Whatever you put in a variable is read by the model as part of its instructions. Do not pass text typed by a stranger straight into one without checking it first.

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