https://retellai.com/?utm_source=discord&utm_medium=seo logo
how do custom functions trigger
# ❓・ai-evy-support
h
@AI Evy how do custom functions trigger? Can I set up conditions to trigger them?
a
Thanks for tagging me @hhbuddy. I'll look through relevant sources and get back to you shortly.
### Answer Custom functions in Retell AI are triggered intelligently by the LLM (Large Language Model) based on the conversation context and the function descriptions you provide [(1) ]() . The LLM decides when to call these functions by outputting structured JSON objects containing the necessary arguments [(2) ]() . ## How Custom Functions Trigger The LLM intelligently chooses to output a JSON object containing arguments to call one or many functions based on the function name and description you provide [(1) ]() . When a custom function is called, Retell sends a request (POST, GET, PUT, PATCH, DELETE) to your specified URL with the function name and parameters [(3) ]() . ## Setting Up Conditions You can influence when functions trigger by: 1. **Function Description**: Add a clear name and description for the custom function that helps the LLM understand when to call it . For example: - Name:
get_user_details
- Description:
Get user details based on name and age
2. **Prompt Engineering**: You can add specific prompts to make function calls more reliable [(4) ]() . As suggested in the community, you could try adding prompts like: "If xxxx, please immediately and reliably call the 'function_name' function" . ## Function Configuration When setting up custom functions, you can: - Configure function details with unique names separated by underscores [(3) ]() - Select HTTP methods (GET, POST, PATCH, PUT, DELETE) - Define parameters using JSON schema format
- Set request headers and query parameters - Extract response values as dynamic variables for later use The system is designed so the LLM makes intelligent decisions about when to call functions based on the conversation flow and the descriptions you provide, rather than having explicit conditional triggers you can set up directly.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
h
@AI Evy Sweet, so give me an example that calls a custom function when we transfer the call
a
Thanks for the follow-up, @hhbuddy. I'll get back to you soon.
### Answer Based on the sources, I can provide you with an example of how custom functions work with call transfers. The documentation shows how to create custom functions that can trigger transfers through external APIs [(1) ]() . ## Custom Function for Call Transfer Here's an example from the documentation that shows how to set up a custom function for transferring calls [(2) ](

▾

) :
Copy code
javascript
// Custom function configuration
{
  "name": "transfer_call", 
  "description": "Transfer the call to a specific extension",
  "parameters": {
    "type": "object",
    "properties": {
      "extension": {
        "type": "string",
        "description": "The extension number to transfer to"
      }
    },
    "required": ["extension"]
  }
}
[(1) ]() ## How It Works When you create a custom function for transfers, Retell sends a request to your specified URL with the function name and parameters . The example from the video shows creating a webhook that receives the transfer request and processes it using the session token [(2) ](

▾

) . The key parameters you need are: - The extension you want to transfer to - The session token (which is already available in the call metadata) ## Alternative: Built-in Transfer Functions However, it's worth noting that Retell AI provides built-in transfer capabilities: 1. Call Transfer - Traditional phone-based transfers to external numbers [(3) ]() 2. Agent Transfer - Switching between AI agents within the same call [(4) ]() The built-in transfer call function allows you to configure warm transfers with settings like on-hold music, human detection, and whisper messages [(3) ]() . ## Important Note There's a community report indicating potential issues with custom transfer_call functions [(5) ]() , so you may want to test thoroughly or consider using the built-in transfer capabilities instead.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Smarter Call Transfers with Alex & Nir (Cloudonix)](

https://www.youtube.com/watch?v=H9UgBB7qnGk▾

) [[3] Transfer call](https://docs.retellai.com/build/single-multi-prompt/transfer-call) [[4] Agent Transfer](https://docs.retellai.com/build/single-multi-prompt/transfer-agent) [[5] custom_function: transfer_call not possible](https://discord.com/channels/1186424376300679209/1256294924819763271) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
h
@AI Evy can I send my custom varriables in the custom function?
a
Thanks for the follow-up, @hhbuddy. I'll get back to you soon.
### Answer Yes, you can use dynamic variables in custom functions! [(1) ]() [(2) ]() ## Where You Can Use Dynamic Variables Dynamic variables can be used in several parts of custom functions [(2) ]() : - tool call url - Include dynamic variables in your endpoint URL - tool call description - Personalize function descriptions - custom tool call properties description - Make parameter descriptions dynamic ## Setting Dynamic Variables For custom functions, you can set dynamic variables through : ### For Outbound Calls When using the Create Phone Call API, set your variables in the
retell_llm_dynamic_variables
field :
Copy code
json
{
 "user_name": "John Smith",
 "product_name": "Premium Plan",
 "account_status": "active"
}
### For Inbound Calls You can supply dynamic variables in the Inbound Call Webhook . ## Using Variables in Custom Functions You can configure custom functions to include dynamic variables in [(1) ]() : - Request headers - Header values can include dynamic variables - Query parameters - Query parameter values can include dynamic variables - Endpoint URL - Your custom function URL can contain dynamic variables ## Important Notes All values in
retell_llm_dynamic_variables
must be strings [(2) ]() . Numbers, booleans, or other data types are not supported. When a dynamic variable is not assigned a value, it will remain unchanged in the output as
{{variable_name}}
rather than being replaced with an empty string .
​ To learn more, see the sources I considered: [[1] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
h
@AI Evy How can I get an agnet to update dynic vars in the call?
a
Thanks for the follow-up, @hhbuddy. I'll get back to you soon.
### Answer Based on the available sources, I can see that dynamic variables can be set initially when creating calls [(1) ]() [(2) ]() [(3) ]() , but I don't have specific information about how an agent can update dynamic variables during an active call. The documentation shows that dynamic variables are typically set at call creation time: For outbound calls, you set variables in the
retell_llm_dynamic_variables
field when using the Create Phone Call API [(1) ]() [(3) ]() :
Copy code
json
{
 "user_name": "John Smith",
 "product_name": "Premium Plan",
 "account_status": "active"
}
[(1) ]() For inbound calls, you can supply dynamic variables in the Inbound Call Webhook . The sources also mention that there are
collected_dynamic_variables
which are "Dynamic variables collected from the call. Only available after the call ends" [(3) ]() , but don't provide details on how the agent updates these during the call. I don't have enough information in the available sources to provide a complete answer about how an agent can update dynamic variables during an active call. You might want to check these potentially helpful sources: - [Dynamic Variables]() - [Create Phone Call]() - [Update Call]() Would you like me to try to provide a general answer based on my knowledge instead?
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Register Phone Call](https://docs.retellai.com/api-references/register-phone-call) [[3] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
h
@AI Evy Ok I see extracted dynamic Variables, how do I instruct the AI to set tehm?
a
Thanks for the follow-up, @hhbuddy. I'll get back to you soon.
### Answer To instruct the AI to extract and set dynamic variables, you need to add an Extract Dynamic Variable tool and update your prompt with specific instructions [(1) ]() . ## For Single/Multi Prompt Agents ### 1. Add the Extract Dynamic Variable Tool First, add an Extract Dynamic Variable tool to give your agent the ability to extract variables . The description is optional . ### 2. Configure Variables Click "+Add" at the bottom and fill in the following details : - Variable Name – A short name to reference this variable - Description – A brief explanation of what this value should be - Variable Type – Choose from
Text
,
Number
,
Enum
, or
Boolean
- Enum Options - Options to choose from (only when type is enum) ### 3. Update Your Prompt It's best to include in the prompt explicitly when is the best time to invoke the extract variable function . For example:
Copy code
When user states his name and phone number, please extract the information by calling the `extract_user_details` function.
​ To learn more, see the sources I considered: [[1] Extract Dynamic Variables](https://docs.retellai.com/build/single-multi-prompt/extract-dv) [[2] Extract Dynamic Variable Node](https://docs.retellai.com/build/conversation-flow/extract-dv-node) ​
## For Conversation Flow Agents Use the Extract Dynamic Variable Node, which is used to extract information from conversation and store them as dynamic variable [(2) ]() . It's not intended for having a conversation with the user . Configure the same variable details : - Variable Name – A short name to reference this variable - Description – A brief explanation of what this value should be - Variable Type – Choose from
Text
,
Number
,
Enum
, or
Boolean
## Variable Types Available You can create variables of the following types [(1) ]() [(2) ]() : - Text - Any word or sentence. Examples:
"headache"
,
"John Smith"
- Number - A numeric value. Examples:
42
,
98.6
- Enum - A value from a predefined list. Examples:
"Yes"
,
"No"
,
"Maybe"
- Boolean - True or false The key is providing clear instructions in your prompt about when the AI should call the extract function, along with well-defined variable descriptions so the AI knows what information to capture.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.