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

# Using variables in custom functions

> How Bolna substitutes prompt variables and auto-injected call data such as agent_id, call_sid, from_number and to_number into custom function calls.

[Context variables](/docs/prompting/using-context) defined in your agent prompt are automatically substituted into custom functions. The LLM won't ask the caller for these values - they're already available.

## Auto-injected system variables

| Variable | Description |
| - | - |
| `{{agent_id}}` | The `id` of the agent |
| `{call_sid}` | Unique `id` of the phone call (from Twilio, Plivo, etc.) |
| `{{from_number}}` | Phone number that **initiated** the call |
| `{{to_number}}` | Phone number that **received** the call |

## How variable substitution works

<CodeGroup>
  ```text agent_prompt theme={"system"}
  You are agent Sam speaking to {{customer_name}}.
  The agent ID is "{{agent_id}}".
  The call ID is "{call_sid}".
  The customer's phone is "{{to_number}}".
  ```

  ```json custom_function theme={"system"}
  {
    "name": "log_interaction",
    "description": "Log customer interaction to CRM",
    "parameters": {
      "type": "object",
      "properties": {
        "to_number": {
          "type": "string",
          "description": "Customer's phone number"
        },
        "agent_id": {
          "type": "string",
          "description": "Agent ID"
        },
        "customer_name": {
          "type": "string",
          "description": "Customer's name"
        },
        "customer_address": {
          "type": "string",
          "description": "Customer's address"
        }
      },
      "required": ["to_number", "agent_id", "customer_name", "customer_address"]
    },
    "key": "custom_task",
    "value": {
      "method": "POST",
      "param": {
        "to_number": "%(to_number)s",
        "agent_id": "%(agent_id)s",
        "customer_name": "%(customer_name)s",
        "customer_address": "%(customer_address)s"
      },
      "url": "https://my-api-dev.xyz",
      "api_token": "Bearer your_token",
      "headers": {}
    }
  }
  ```

  ```json runtime_substitution theme={"system"}
  {
    "to_number": "+19876543210",
    "agent_id": "7d86b904-da64-4b8e-8f51-6fef2c630380",
    "customer_name": "Bruce",
    "customer_address": "221B Baker Street"
  }
  ```
</CodeGroup>

| Parameter | Defined in Prompt? | Result |
| - | - | - |
| `to_number` | Yes (system) | Auto-substituted |
| `agent_id` | Yes (system) | Auto-substituted |
| `customer_name` | Yes (passed via call) | Auto-substituted |
| `customer_address` | No | LLM will collect from caller |

## Next steps

<CardGroup cols={2}>
  <Card title="Pre-call webhooks" href="/docs/tool-calling/pre-call-webhooks" />

  <Card title="Call your own API" href="/docs/tool-calling/custom-function-calls" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.