https://retellai.com/?utm_source=discord&utm_medium=seo logo
I returned some values from a webhook and stored ...
# ❓・ai-evy-support
w
@AI Evy I returned some values from a webhook and stored them as response variables. How can I ensure to use these in follow on functions? so far it's not working, eventhough I formatted the use of the custom variable like this {{first_name}} as an example.
a
Thanks for tagging me @wolfgang074778. I'll look through relevant sources and get back to you shortly.
### Answer The issue with dynamic variables not working in follow-on functions is commonly related to how the webhook response is formatted [(1) ]() . For webhook responses to properly set dynamic variables, you need to structure your response correctly :
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
        "first_name": "John"
    }
  }
}
The key points for troubleshooting: 1. **Webhook Response Format**: Dynamic variables from webhooks must be returned in the specific nested structure shown above, not as flat key-value pairs . 2. **Variable Usage**: Once properly set, you can use them in prompts, tool descriptions, and other locations using the
{{first_name}}
syntax [(2) ]() . 3. **Testing Approach**: Try a simple test with a minimal prompt that only says "Hi {{first_name}}" to verify the variable is being passed correctly [(3) ]() . 4. **Edge Case Behavior**: If a dynamic variable isn't set properly, it will remain unchanged in its raw form (showing
{{first_name}}
literally) rather than being replaced [(2) ]() . Dynamic variables can be used in prompts, begin messages, tool call URLs, tool call descriptions, and other agent components . Make sure your webhook is returning the variables in the correct nested format as shown in the example above.
​ To learn more, see the sources I considered: [[1] Not receiving response from inbound webhook.](https://discord.com/channels/1186424376300679209/1355901739244585132) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[3] dynamic variables getting issue in prompt](https://discord.com/channels/1186424376300679209/1363771693914656880) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
w
could you give me an example of how the structure would look like for two different varaibles? called "display_name" and "first_name" @AI Evy
could you give me an example of how the structure would look like for two different varaibles? called "display_name" and "first_name" @AI Evy
could you give me an example of how the structure would look like for two different varaibles? called "display_name" and "first_name" @AI Evy
a
Thanks for the follow-up, @wolfgang074778. I'll get back to you soon.
### Answer Based on the sources, here's how you can structure the webhook response to set both
display_name
and
first_name
dynamic variables: For webhook responses, you need to use this specific nested structure [(1) ]() :
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
        "display_name": "John Smith",
        "first_name": "John"
    }
  }
}
Once these variables are properly set through your webhook response, you can use them in your agent configuration using the double curly brace syntax [(2) ]() : -
{{display_name}}
-
{{first_name}}
These dynamic variables can be used in prompts, begin messages, tool call URLs, tool call descriptions, custom tool call properties descriptions, voicemail settings, transfer call function numbers, and warm transfer settings . For outbound calls using the API, you would set them in the
retell_llm_dynamic_variables
field like this :
Copy code
json
{
 "display_name": "John Smith",
 "first_name": "John"
}
The key difference is that webhook responses require the nested
call_inbound.dynamic_variables
structure, while API calls use the flat
retell_llm_dynamic_variables
structure , [(1) ]() .
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://discord.com/channels/1186424376300679209/1356680357084135558) [[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.
w
@AI Evy I need the formatting for in inbound call, as a webhook response. I have a webhook that gives me the number, I lookup the name and then return the name via a 200 response back to retellai. I need that formatting of the body, the proper syntax for my two variables
a
Thanks for the follow-up, @wolfgang074778. I'll get back to you soon.
### Answer For inbound call webhook responses, you need to format your 200 response body with the exact structure shown in the documentation [(1) ]() . Here's the proper syntax for your two variables
display_name
and `first_name`:
Copy code
json
{
 "call_inbound": {
 "dynamic_variables": {
 "display_name": "John Smith",
 "first_name": "John"
 }
 }
}
This matches the expected response format where all fields are grouped under
call_inbound
. The
dynamic_variables
field allows you to set dynamic variables for the inbound call . Once set through your webhook response, you can use these variables in your agent configuration using the double curly brace syntax like
{{display_name}}
and
{{first_name}}
[(2) ]() . These dynamic variables can be used in prompts, begin messages, tool call URLs, tool call descriptions, and other agent components . All values in the dynamic variables must be strings , so make sure your webhook returns string values for both variables.
​ To learn more, see the sources I considered: [[1] Inbound call webhook](https://docs.retellai.com/features/inbound-call-webhook) [[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.
w
@AI Evy i'm looking up a callers name. how do I best do this asyncronously, without having to wait for the result of a function. not all callers will have a name in the DB.
a
Thanks for the follow-up, @wolfgang074778. I'll get back to you soon.
### Answer For asynchronous caller name lookup in Retell AI, you can leverage the inbound call webhook with dynamic variables to handle this efficiently [(1) ]() [(2) ]() . Here's the best approach: Set Default Dynamic Variables Configure default values at the agent level that will be used when the lookup doesn't find a name [(1) ]() :
Copy code
json
{
  "display_name": "Valued Customer",
  "first_name": "there"
}
Webhook Response Structure Your webhook should return immediately with either the found name or fall back to defaults [(1) ]() [(2) ]() :
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "display_name": "John Smith",
      "first_name": "John"
    }
  }
}
[(1) ]() Handle Missing Names Gracefully Since the webhook has a 10-second timeout and will retry up to 3 times if no success status is received [(3) ]() , you should: 1. Perform a quick database lookup (aim for under 2-3 seconds) 2. If no name is found, return the default values immediately 3. Use the dynamic variables in your prompt like "Hello {{first_name}}, how can I help you today?" [(1) ]() The dynamic variables can be used in prompts, begin messages, tool call descriptions, and other agent components . Default variables serve as fallbacks and will only be used when specific variables aren't included in the call request . This approach ensures your agent starts the conversation promptly while still personalizing when possible, without blocking the call flow for database lookups.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Receive calls](https://docs.retellai.com/deploy/inbound-call) [[3] Webhook Overview](https://docs.retellai.com/features/webhook-overview) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.