# How to configure a custom function

### Accessing the functions section

To create a new custom function in AIsuru, follow these steps:

1. Go to your Agent's management panel;
2. Select "Functions" in the sidebar;
3. Click the "Advanced functions" tab at the top of the page;
4. Press "New function" to start the configuration.

### Configuring a new function

On the new function creation screen, you'll need to fill in the following fields:

**Basic information**

* **Name**: enter a unique, descriptive name for your function. This name is used internally by the system to identify the function.
  * **Limit**: the name can be at most 64 characters
  * **Format**: use only letters, numbers, and underscores (\_), no spaces or special characters
  * **Valid examples**: `get_weather`, `search_products`, `send_customer_email`
* **Description**: provide a complete description of the function — you should always specify:
  * What the function does
  * When to use it
  * What output it should return and how to format it

This description is essential because it helps the generative AI understand when and how to use the function in a conversation.

> **Note**: If you use OpenAI models (like GPT-4o and GPT-4o mini), the description can't exceed 1,024 characters. If you need a longer description, we recommend using other models for Q\&A, or moving part of the description into the [instructions](/en/generative-ai/ai-instructions.md).

### **Function description examples**

#### **Example of a function for sending emails**

```
Use this function to send email notifications. The function should ONLY be called when:
- The user explicitly requests to be contacted;
- The user wants to receive specific informational material;
- The user asks for a demo.

Required parameters:
- email: the recipient's email address (ALWAYS ask the user)
- type: the type of information requested (DON'T ask the user, infer from the conversation)
- message: the specific content to send (compose an appropriate text based on the request)

Before calling the function, make sure you fully understand what type of information the user wants to receive.
```

#### **Example of a function for searching products in a catalog**

```
Use this function to get information from the product catalog based on the category requested by the user. The function should be called when the user asks about specific product categories.

Available categories are:
- computers: for information on laptops and desktops;
- phones: for information on smartphones and phones;
- tablets: for information on tablets and e-readers.

Use the {category} parameter, setting it in the webhook to the appropriate category based on the request. For example, if the user asks about laptops, use "computers" as the parameter value.

Never show the parameter value to the user — only use the information returned by the function to formulate the response.
```

### Webhook configuration

* **Webhook**: enter the full web address that will be called when the function is triggered. For example, if you use Zapier, you'll need to enter the address Zapier provides (this is called a webhook).
* **HTTP method**: select the appropriate HTTP method for your webhook request. The choice depends on the action the function needs to perform:
  * GET (default) -> to retrieve information, like reading an article online
  * POST -> to send new information, like submitting a form
  * PATCH -> to partially modify existing information, like updating only some fields in an online profile;
  * DELETE -> to delete information, like removing an account

✅ If you don't need to pass parameters or other information, you can stop here.

#### Request details

If you need to send additional information to your service (like a name, a date, or an email address), you may need to specify more details:

* **HTTP headers**: here you can add extra information needed for your request. This may include access codes or other details required by the service you're using. Press "Add" to add information to the request header.
* **Query string template**: define the format of the information to send in the URL. Use {parameter} to indicate where variable values should go. E.g. location={city}\&period={date}. City and date are variables (or "parameters").
* **HTTP body template**: specify the information to send in the request body. Same as above, use {parameter} to indicate where variable values should go.

#### Contextual information

**Send extension headers**: select the additional conversation information you want to include in the request:

* Session ID;
* User tags;
* Current date and time;
* Location;
* Context;
* User email.

#### Parameter definition

In the "Parameters" section, you can define the dynamic values (variables) that your function will accept.

To add a parameter, click "Add" and specify:

* **Name**: the parameter name that will be used (the one you put in curly braces, for example "city" if you wrote "location={city}" in the request details);
* **Description**: a detailed description of what the parameter represents; more detail means greater accuracy from the AI;
* **Type**: specify whether the parameter is a string, number, integer, or boolean;
* **Possible values**: click the "add" button to enter possible values;
* **Required**: this field tells the AI whether the parameter is mandatory or optional: if you're asking for weather data, the city is probably required, while the scale (Celsius or Fahrenheit) might be optional.

> These parameters represent values that the AI can ask the user for or infer from the conversation.

{% hint style="danger" %}
**Note**: parameter names must not contain accented characters or special characters.
{% endhint %}

#### Testing the function

Before deploying your function, we recommend testing it:

1. On your function's configuration page, press "Test"
2. Enter sample values for the defined parameters
3. Click "Run test" to verify the function performs as expected

This step lets you identify and fix any issues before putting the function into production.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aisuru.com/en/advanced-features/integrations/functions/advanced-functions/how-to-configure-a-custom-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
