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

# Add External API Integrations

> Enable agents to call external APIs, query databases, and perform actions during conversations using function calling.

Give your agent the ability to take action. Tools let the LLM call external APIs, query databases, book appointments, and check order status — anything your webhook can handle.

**What you'll learn:** How to define tools with JSON Schema, configure webhooks, handle responses, and test tool execution.

***

## Quick start: Add a tool

**1. Navigate to Tools tab**

When creating or editing an agent, select the **Tools** tab.

**2. Add a new tool**

Click **Add Tool** to create a new tool configuration.

**3. Configure settings**

* **Tool Name**: Unique identifier (e.g., `get_weather`)
* **Description**: What the tool does and when to use it
* **Schema**: Define parameters using JSON Schema
* **Webhook URL**: Your endpoint
* **Headers**: Authentication and custom headers

**4. Test your tool**

Click **Test Tool**, enter sample arguments, and verify the response.

**5. Save and enable**

Save the agent and toggle **Allow this agent to take calls**.

> [accordion] How function calling works
>
> When you configure tools, the LLM gains awareness of available functions and autonomously decides when to call them during conversation. Dasha BlackBox sends requests to your webhook, your webhook executes the function, and the LLM incorporates results into its response.
>
> **Key capabilities:** JSON Schema for tool definitions, call metadata (callId, agentId, orgId) in webhook requests, automatic retry with exponential backoff, and built-in testing.

***

## Define a tool

> [accordion] Tool structure
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "get_weather",
>   "description": "Get current weather for a city",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "city": {
>         "type": "string",
>         "description": "City name"
>       },
>       "units": {
>         "type": "string",
>         "enum": ["celsius", "fahrenheit"]
>       }
>     },
>     "required": ["city"]
>   },
>   "webhook": {
>     "url": "https://api.example.com/tools/weather",
>     "headers": {
>       "Authorization": "Bearer your-api-key"
>     }
>   },
>   "fallBackResult": {
>     "temperature": "unknown",
>     "conditions": "unavailable"
>   }
> }
> ```

### Required fields

| Field | Type | Description |
| - | - | - |
| `name` | string | Unique identifier. Pattern: `^[a-zA-Z_][a-zA-Z0-9_]*$`. No hyphens. |
| `description` | string | Clear explanation of what the tool does. Helps LLM decide when to use it. |
| `schema` | object | JSON Schema defining parameters. |
| `webhook` | object | URL and headers for the endpoint. |

### Optional fields

| Field | Type | Description |
| - | - | - |
| `fallBackResult` | any | Default result if webhook fails. Allows conversation to continue gracefully. |
| `timeoutSeconds` | integer | Max wait time (1–300). Note: Currently uses fixed 60s HTTP timeout. |
| `retryCount` | integer | Retry attempts (0–5). Uses global retry policy with exponential backoff. |
| `isLongRunning` | boolean | Run the tool in the background instead of making the agent wait for it. |
| `longRunningAdditionalInstructions` | string | What the agent should say while a slow call is still pending. |

***

## Slow tools

By default the agent waits for the webhook to answer before it says anything, so a slow endpoint leaves the caller listening to silence. Set `isLongRunning` and the call runs in the background instead: the agent gets an immediate acknowledgement, keeps the conversation going, and the result is added to the conversation history the moment the webhook answers.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "name": "check_order_status",
  "isLongRunning": true,
  "longRunningAdditionalInstructions": "Tell the caller the order lookup usually takes about a minute."
}
```

**How it behaves during a call:**

1. The agent calls the tool and immediately receives a pending acknowledgement instead of the result, together with your `longRunningAdditionalInstructions`.
2. The agent keeps talking to the caller — it can answer other questions or fill the wait.
3. When the webhook answers, the outcome is written into the conversation history as `Result of tool <toolName>(<arguments>) = <result>`, and the agent takes one extra speaking turn to tell the caller about it.
4. The result carries a short instruction with it: tell the caller the outcome in the next reply, casually and in passing if the conversation has moved on, and leave it unsaid only when it is no longer needed at all.

> [!NOTE]
>
> `longRunningAdditionalInstructions` is guidance for what the agent should say *while waiting*, not a description of the tool. Repeating the same call with the same arguments while one is still pending does not start a second request.

> [!WARNING]
>
> The result does not interrupt the agent mid-sentence. It is written into the conversation history and the agent takes one extra speaking turn as soon as it is free, so the caller hears the answer without having to ask again.

> [!NOTE]
>
> With [Enhanced tooling](https://blackbox.dasha.ai/docs/create/llm-configuration.md#enhanced-tooling) enabled in the LLM configuration, `isLongRunning` and `longRunningAdditionalInstructions` are not used.

***

## JSON Schema examples

> [accordion] Simple parameters
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "send_sms",
>   "description": "Send an SMS message",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "phone_number": {
>         "type": "string",
>         "pattern": "^\\+[1-9]\\d{1,14}$",
>         "description": "Phone in E.164 format"
>       },
>       "message": {
>         "type": "string",
>         "maxLength": 160,
>         "description": "Message content"
>       }
>     },
>     "required": ["phone_number", "message"]
>   }
> }
> ```

> [accordion] Nested objects
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "book_appointment",
>   "description": "Schedule an appointment",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "customer": {
>         "type": "object",
>         "properties": {
>           "name": { "type": "string" },
>           "email": { "type": "string", "format": "email" },
>           "phone": { "type": "string" }
>         },
>         "required": ["name", "email"]
>       },
>       "appointment": {
>         "type": "object",
>         "properties": {
>           "datetime": { "type": "string", "format": "date-time" },
>           "duration_minutes": { "type": "integer", "minimum": 15 },
>           "service_type": {
>             "type": "string",
>             "enum": ["consultation", "follow-up", "emergency"]
>           }
>         },
>         "required": ["datetime", "service_type"]
>       }
>     },
>     "required": ["customer", "appointment"]
>   }
> }
> ```

> [accordion] Arrays
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "search_products",
>   "description": "Search product catalog",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "keywords": {
>         "type": "array",
>         "items": { "type": "string" },
>         "minItems": 1
>       },
>       "categories": {
>         "type": "array",
>         "items": {
>           "type": "string",
>           "enum": ["electronics", "clothing", "home", "books"]
>         }
>       },
>       "in_stock_only": {
>         "type": "boolean",
>         "default": true
>       }
>     },
>     "required": ["keywords"]
>   }
> }
> ```

> [accordion] Enumerations
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "update_ticket_status",
>   "description": "Update support ticket status",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "ticket_id": {
>         "type": "string",
>         "pattern": "^TKT-[0-9]{6}$"
>       },
>       "status": {
>         "type": "string",
>         "enum": ["open", "in_progress", "waiting_customer", "resolved", "closed"]
>       },
>       "priority": {
>         "type": "string",
>         "enum": ["low", "medium", "high", "urgent"]
>       }
>     },
>     "required": ["ticket_id", "status"]
>   }
> }
> ```

***

## Configure webhooks

> [accordion] Request format
>
> When your tool is invoked, Dasha BlackBox sends a POST request:
>
> ```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
> POST https://api.example.com/webhooks/tools
> Content-Type: application/json
> Authorization: Bearer sk-abc123...
>
> {
>   "type": "ToolWebHookPayload",
>   "status": "Running",
>   "callId": "67890abcdef123456789",
>   "agentId": "12345abcdef67890",
>   "orgId": "org_abc123xyz",
>   "toolName": "get_weather",
>   "arguments": {
>     "city": "San Francisco",
>     "units": "fahrenheit"
>   },
>   "callAdditionalData": {
>     "campaign_id": "summer_outreach"
>   },
>   "agentAdditionalData": {
>     "department": "sales"
>   }
> }
> ```

> [!NOTE]
>
> Only headers configured in your tool definition are sent. The `callAdditionalData`, `agentAdditionalData`, `serverJobId`, and `sip` fields are optional.

> [accordion] Response format
>
> Return a JSON response within the timeout period:
>
> **Success (200 OK):**
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "temperature": 68,
>   "conditions": "sunny",
>   "humidity": 65
> }
> ```

> [accordion] Error Response (4xx/5xx)
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "error": "Invalid city name",
>   "errorCode": "INVALID_CITY"
> }
> ```

If your webhook returns an error, the `fallBackResult` is used (if configured).

### Use call data in the URL and headers

The webhook URL and header values accept variables, so a tool can call a REST-style API with data you already have instead of asking the language model to repeat it:

| Field | Example |
| - | - |
| Webhook URL | `https://api.example.com/customers/{{callAdditionalData.customerId}}/orders` |
| Header value | `X-Call-Id: {{callId}}` |
| Query parameter | `status` = `{{arguments.status}}` |

Click **`{ }`** in a field to pick a variable: the tool's arguments, call fields such as `callId` and `endpoint`, SIP fields, and your own `callAdditionalData` and `agentAdditionalData` keys. Open **Advanced request settings** to change the HTTP method, add query parameters or build a custom request body.

> [!TIP]
>
> Identifiers such as customer or order IDs are more reliable from `callAdditionalData` than from a tool argument. The language model cannot mishear or invent them.

See [Request Templating](https://blackbox.dasha.ai/docs/webhooks-and-events/webhook-request-templating.md) for every variable, the rendering rules and the API reference.

### Response best practices

* **Return structured data** with clear field names
* **Include context** for the LLM to formulate complete responses
* **Handle errors gracefully** — return error objects instead of crashing
* **Be concise** — avoid massive datasets, summarize when possible
* **Respond quickly** — aim for sub-second responses

***

## Test webhooks

### Via dashboard

1. Navigate to agent's Tools tab
2. Click **Test Tool** on the tool card or in the tool editor. Arguments are generated from the tool's schema.
3. If the webhook uses `callAdditionalData` or `agentAdditionalData` variables, test from the tool editor and fill in **Test values for custom data** first. Sample values are not saved.
4. Review the response and **Request Sent**, the exact URL, headers and body that were sent

> [accordion] Via API
>
> ```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
> const response = await fetch('https://blackbox.dasha.ai/api/v1/webhooks/test', {
>   method: 'POST',
>   headers: {
>     'Authorization': 'Bearer YOUR_API_KEY',
>     'Content-Type': 'application/json'
>   },
>   body: JSON.stringify({
>     webHook: {
>       url: 'https://api.example.com/webhooks/tools',
>       headers: {
>         'Authorization': 'Bearer your-webhook-key'
>       }
>     },
>     webhookType: 'ToolWebHookPayload',
>     toolName: 'get_weather',
>     toolArguments: {
>       city: 'San Francisco',
>       units: 'fahrenheit'
>     }
>   })
> });
>
> const result = await response.json();
> console.log(result);
> // Output:
> // {
> //   "success": true,
> //   "httpStatus": 200,
> //   "httpStatusText": "OK",
> //   "responseData": { "temperature": 68, "conditions": "sunny" },
> //   "validationResult": { "isValid": true, "errors": [] },
> //   "timeTaken": 145
> // }
> ```

***

## Tool webhooks vs event webhooks

| Feature | Tool webhooks | Event webhooks |
| - | - | - |
| **Purpose** | Execute functions during conversation | Receive call lifecycle notifications |
| **Trigger** | LLM decides to invoke a tool | Specific events (call start, result, failure) |
| **Response** | Returns result to LLM | Acknowledgment only |
| **Timeout** | 60 seconds | 30 seconds |
| **Configure in** | Tools tab | Webhooks tab |

See [Webhook Events](https://blackbox.dasha.ai/docs/webhooks-and-events/webhook-events.md) for event webhook details.

***

## MCP tools

Dasha BlackBox integrates with Model Context Protocol (MCP) servers for pre-built tools without custom webhook development.

### MCP vs custom webhooks

| Feature | Custom webhooks | MCP servers |
| - | - | - |
| Setup | Write webhook handler | Connect to existing server |
| Tool discovery | Manual definition | Automatic from server |
| Hosting | Self-hosted or cloud | MCP server provider |
| Customization | Full control | Limited to server capabilities |

**Use custom webhooks** for full control or proprietary system integration.

**Use MCP connections** for standard integrations like databases, calendars, or public APIs.

See [MCP Connections](https://blackbox.dasha.ai/docs/create/mcp-connections.md) for setup instructions.

***

## Common use cases

> [accordion] CRM integration
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "lookup_customer",
>   "description": "Retrieve customer information by email or phone",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "identifier": {
>         "type": "string",
>         "description": "Customer email or phone number"
>       }
>     },
>     "required": ["identifier"]
>   },
>   "webhook": {
>     "url": "https://crm.example.com/api/webhooks/lookup",
>     "headers": {
>       "Authorization": "Bearer crm-api-key"
>     }
>   }
> }
> ```

> [accordion] Calendar booking
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "check_availability",
>   "description": "Check available appointment slots",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "start_date": {
>         "type": "string",
>         "format": "date",
>         "description": "Start date (YYYY-MM-DD)"
>       },
>       "end_date": {
>         "type": "string",
>         "format": "date",
>         "description": "End date (YYYY-MM-DD)"
>       },
>       "service_type": {
>         "type": "string",
>         "description": "Type of service"
>       }
>     },
>     "required": ["start_date", "end_date"]
>   }
> }
> ```

> [accordion] Knowledge base search
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "name": "search_knowledge_base",
>   "description": "Search company knowledge base",
>   "schema": {
>     "type": "object",
>     "properties": {
>       "query": {
>         "type": "string",
>         "description": "Search query"
>       },
>       "category": {
>         "type": "string",
>         "enum": ["products", "policies", "troubleshooting"]
>       },
>       "max_results": {
>         "type": "integer",
>         "minimum": 1,
>         "maximum": 10,
>         "default": 5
>       }
>     },
>     "required": ["query"]
>   }
> }
> ```

***

## Best practices

### Tool design

* **Keep tools focused** — one tool, one purpose
* **Write clear descriptions** — explain when the LLM should use the tool
* **Use strong typing** — precise schemas with proper types, enums, formats
* **Provide defaults** — sensible fallback results for error handling

> [accordion] Schema guidelines
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> // ✅ Good: Descriptive with constraints
> {
>   "customer_email": {
>     "type": "string",
>     "format": "email",
>     "description": "Customer's email for order confirmation"
>   }
> }
>
> // ❌ Avoid: Vague and unconstrained
> {
>   "email": {
>     "type": "string",
>     "description": "Email"
>   }
> }
> ```

### Webhook implementation

**Security:**

* Always use HTTPS endpoints
* Implement authentication via headers
* Validate incoming requests
* Rate limit to prevent abuse

**Performance:**

* Respond within timeout (aim for \< 1 second)
* Use async processing for slow operations
* Implement caching where appropriate

**Reliability:**

* Use idempotent operations when possible
* Monitor webhook uptime
* Set up alerting for failures

***

## Troubleshooting

> [accordion] Tool not being called
>
> * Improve the tool description to be more specific
> * Mention the tool in system prompt if critical
> * Test with explicit user requests that should trigger the tool
> * Check that the tool name is clear and descriptive

> [accordion] Webhook timeouts
>
> * Optimize webhook processing time
> * Use async processing and return immediately
> * Configure appropriate `fallBackResult`

> [accordion] Schema validation errors
>
> * Review LLM-generated arguments in call logs
> * Simplify complex nested schemas
> * Add clear descriptions to all properties
> * Use enums to constrain values

> [accordion] Authentication failures
>
> * Verify header configuration in tool setup
> * Check that API keys are valid and not expired
> * Ensure webhook URL is correct and accessible
> * Test webhook independently with curl/Postman

***

## Next steps

> [card] [MCP connections](https://blackbox.dasha.ai/docs/create/mcp-connections.md)
>
> Connect to MCP servers for pre-built tools

> [card] [Webhook events](https://blackbox.dasha.ai/docs/webhooks-and-events/webhook-events.md)
>
> Configure call lifecycle notifications

> [card] [Test webhooks](https://blackbox.dasha.ai/docs/webhooks-and-events/testing-webhooks.md)
>
> Validate webhook implementations

> [card] [Dashboard testing](https://blackbox.dasha.ai/docs/test/dashboard-testing.md)
>
> Test tools in real conversations


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