https://retellai.com/?utm_source=discord&utm_medium=seo logo
Can you please explain to me how do dynamic variab...
# ❓・ai-evy-support
a
Can you please explain to me how do dynamic variables work? I understand how post-call variables operate, and also the basic ones like {{user_name}}, {{user_number}} but how does the process work if I want to create a variable that the agent will reference throughout the conversation. For example, if I want to create {{requested_app}} variable and want the agent to store data that came from the webhook there and mention it to the caller if they asked @AI Evy
a
Thanks for tagging me @anton333_50203. I'll look through relevant sources and get back to you shortly.
### Answer Dynamic variables are placeholders surrounded by double curly braces that allow you to inject data into various parts of your agent for specific calls [(1) ]() . They help personalize your agent's responses while keeping the core conversation flow intact . For your
{{requested_app}}
variable example, here's how the process works: Where you can use dynamic variables: - prompt - begin message - tool call description - custom tool call properties description - voicemail setting (both prompt and static text) - transfer call function number - warm transfer setting (both prompt and static text) Setting up your custom variable: 1. Add the variable to your prompts using the double curly brace syntax :
Copy code
json
"Hello {{user_name}}, I understand you're interested in {{requested_app}}. How can I help you today?"
2. For inbound calls, you supply dynamic variables through the Inbound Call Webhook . Your webhook response should include the
dynamic_variables
field [(2) ]() :
Copy code
json
{
  "call_inbound": {
    "override_agent_id": "agent_12345",
    "dynamic_variables": {
        "customer_name": "John Doe"
    },
    "metadata": {
        "random_id": "12345"
    }
  }
}
3. Configure agent-level defaults as fallback values when specific variables aren't included in the call request [(1) ]() . Important notes: - All dynamic variable values must be strings - When a dynamic variable is not assigned a value, it will remain unchanged in the output (showing as
{{variable_name}}
) [(3) ]() - You can test your dynamic variables using the web interface before deploying [(1) ]() The agent will reference your
{{requested_app}}
variable throughout the conversation once it's set via the webhook response, allowing personalized responses based on the data you provide.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Inbound call webhook](https://docs.retellai.com/features/inbound-call-webhook) [[3] 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.
a
So does it mean that for example, after "Ask for Preferred Time" node where the agent gather's the preferred times of the appointment, I execute a function that checks if the requested time is available, the webhook response payload should be structured like this: { "status": "available", "message": "The requested appointment time is available.", "requested_app": "Monday 3 December at 14:40" "original_request": } So that when the agent receives this response he will be able to reference {{requested_app}} throughout the conversation? @AI Evy
a
Thanks for the follow-up, @anton333_50203. I'll get back to you soon.
### Answer Not exactly. The payload structure you've shown is for a function/tool call response, not for setting dynamic variables. Dynamic variables in Retell AI are set at the beginning of a call, not during the conversation through function responses [(1) ]() . Dynamic variables are injected into various parts of the agent at call initiation and can be used in prompts, begin messages, tool call descriptions, and other agent configuration areas . They're designed to personalize the agent's responses while keeping the core conversation flow intact . For inbound calls, dynamic variables are set through the Inbound Call Webhook response with this structure [(2) ]() :
Copy code
json
{
  "call_inbound": {
    "override_agent_id": "agent_12345",
    "dynamic_variables": {
        "customer_name": "John Doe"
    },
    "metadata": {
        "random_id": "12345"
    }
  }
}
For outbound calls, dynamic variables are set in the
retell_llm_dynamic_variables
field when using the Create Phone Call API, where all values must be strings [(1) ]() :
Copy code
json
{
    "user_name": "John Smith",
    "product_name": "Premium Plan",
    "account_status": "active"
}
If you need to store and reference information gathered during the conversation (like appointment times) , you would typically handle this through your function/tool call logic and potentially update external systems, but not through dynamic variables which are set at call initialization.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Inbound call webhook](https://docs.retellai.com/features/inbound-call-webhook) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
But how can I set {{requested_app}} prior to a call if it will only be known during a call? Can you please make an example with some sample data and outline step-by-step process of setting up and using a dynamic variable like that so I would understand @AI Evy
a
Thanks for the follow-up, @anton333_50203. I'll get back to you soon.
### Answer You're correct that this presents a challenge - dynamic variables are designed to be set at the beginning of a call, not during the conversation [(1) ]() . However, there are a few approaches to handle this scenario: ## Approach 1: Use Default Values with Conditional Logic Set up a default value for
{{requested_app}}
and use conditional logic in your prompt : Step 1: Configure agent-level default dynamic variables Set a default value like "TBD" or "not yet specified" . Step 2: Use conditional logic in your prompt
Copy code
json
"Hello {{user_name}}, {% if requested_app == 'TBD' %}I'll help you find the right appointment time.{% else %}I understand you're interested in {{requested_app}}.{% endif %} How can I help you today?"
## Approach 2: Inbound Call Webhook for Known Information If you have some information about the caller beforehand (from CRM, previous interactions, etc.) , you can set
{{requested_app}}
through the inbound call webhook [(2) ]() : Step 1: Configure inbound call webhook Your webhook receives the caller information:
Copy code
json
{
  "event": "call_inbound",
  "call_inbound": {
    "agent_id": "agent_12345",
    "from_number": "+12137771234",
    "to_number": "+12137771235"
  }
}
Step 2: Look up caller data and respond Based on
from_number
, look up previous appointment requests and respond:
Copy code
json
{
  "call_inbound": {
    "override_agent_id": "agent_12345",
    "dynamic_variables": {
        "customer_name": "John Doe",
        "requested_app": "Monday 3 December at 14:40"
    },
    "metadata": {
        "random_id": "12345"
    }
  }
}
## Approach 3: Tool/Function Call for Dynamic Updates For information gathered during the call, you would handle this through tool/function calls rather than dynamic variables. The function response would inform the agent's next responses, but this data wouldn't be available as a
{{variable}}
throughout the conversation [(1) ]() . **Key limitation**: When a dynamic variable is not assigned a value, it will remain unchanged in the output as
{{requested_app}}
rather than being replaced . Dynamic variables are most effective when you have the data available at call initiation, not for information collected during the conversation.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Inbound call webhook](https://docs.retellai.com/features/inbound-call-webhook) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
So an agent receives a webhook reponse like this: { "status": "available", "message": "The requested appointment time is available.", "requested_app": "Monday 3 December at 14:40" "original_request": } Where is that information stored? @AI Evy
a
Thanks for the follow-up, @anton333_50203. I'll get back to you soon.
### Answer The webhook response you've shown is from a function/tool call, not from setting dynamic variables. When the agent receives this response from a function call, the information is processed by the LLM and can influence the agent's subsequent responses, but it's not stored as a persistent variable that can be referenced throughout the conversation using
{{variable}}
syntax [(1) ]() . The key distinction is: **Function/Tool Call Responses**: The data from your example response is processed by the LLM in the context of that specific function call. The agent can use this information to formulate its next response, but this data doesn't become a dynamic variable that persists throughout the conversation [(2) ]() . **Dynamic Variables**: These are set at call initiation and can be referenced throughout the conversation using
{{variable_name}}
syntax. For inbound calls, they're set through the Inbound Call Webhook response structure [(3) ]() :
Copy code
json
{
  "call_inbound": {
    "override_agent_id": "agent_12345",
    "dynamic_variables": {
        "customer_name": "John Doe"
    },
    "metadata": {
        "random_id": "12345"
    }
  }
}
So in your example, the information from the function response (
"status": "available"
,
"message": "The requested appointment time is available."
, etc.) is available to the LLM for generating the immediate response, but it doesn't get stored as a persistent
{{requested_app}}
variable that can be referenced later in the conversation.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Webhook](https://www.retellai.com/glossary/webhook) [[3] Inbound call webhook](https://docs.retellai.com/features/inbound-call-webhook) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy Answer my questions, don't be stupid. If you don't know something -- say it. Do not hallucinate or try to fill your lack of knowledge about a specific area with something you have explained before. Now once again, from the beginning. When an agent receives a webhook response like this: { "status": "available", "message": "The requested appointment time is available.", "requested_app": "Monday 3 December at 14:40" "original_request": } Where is that information stored? I assume that if the conversation has moved forward and the caller will say "Hey, what time was my appointment again?" the agent will be able to say "Monday 3 December at 14:40" which means that this information is stored somewhere
a
Thanks for the follow-up, @anton333_50203. I'll get back to you soon.
### Answer I don't have specific information about where function/tool call response data is stored within Retell AI's system architecture. The documentation doesn't provide details about the internal storage mechanism for function call responses or how long that data persists in the agent's memory during a conversation. What I can tell you from the available documentation is that dynamic variables are set at call initiation through the inbound call webhook with the
dynamic_variables
field [(1) ]() or through the
retell_llm_dynamic_variables
field for outbound calls [(2) ]() , but these are different from function/tool call responses. For your specific question about whether an agent can recall "Monday 3 December at 14:40" later in the conversation after receiving it in a function response - I don't have documentation that explains how or where this information is stored internally within Retell AI's system.
​ 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.
Appreciate the feedback! Feel free to ask me again with additional guidance or context.