https://retellai.com/?utm_source=discord&utm_medium=seo logo
I'm looking for a way for an agent to have a conte...
# ❓・ai-evy-support
f
@AI Evy I'm looking for a way for an agent to have a contextual greeting like good morning and good evening but every time I set up a tool to run before the agent starts talking the agent never starts talking the tool runs in the call never starts Can you give me any ideas on how I can make this work
a
Thanks for tagging me @FullThrottleFu. I'll look through relevant sources and get back to you shortly.
### Answer For contextual greetings like "good morning" or "good evening," the recommended approach is to use Dynamic Variables rather than running a tool before the agent speaks. You can inject the appropriate greeting at call creation time using
retell_llm_dynamic_variables
. [(1) ]() How it works: 1. Determine the time of day in your backend before initiating the call 2. Pass the greeting as a dynamic variable when creating the call:
Copy code
javascript
const phoneCallResponse = await client.call.createPhoneCall({
  from_number: '+14157774444',
  to_number: '+12137774445',
  retell_llm_dynamic_variables: {
    greeting: "Good morning"  // or "Good evening" based on your backend logic
  }
}) ;
[(2) ]() 3. Reference
{{greeting}}
in your agent's first sentence or prompt
This avoids the issue you're experiencing where tool execution blocks the agent from speaking. The greeting is pre-computed and injected before the call even starts. Why tools before first speech can be problematic: There's a known issue in Flex Mode and conversation flows where tool calls can create race conditions that prevent speech from executing properly. [(3) ]() , [(4) ]() One community member noted that in Flex Mode, a "race condition" often causes the tool to terminate or block before TTS finishes. Alternative if you need runtime logic: If you must determine the greeting during the call, consider putting the time-check logic in your Global Prompt instructions rather than a tool, instructing the agent to greet appropriately based on context you provide via dynamic variables.
​ To learn more, see the sources I considered: [[1] Create Voice Agent](https://docs.retellai.com/api-references/create-agent) [[2] How can I create an outbound call](https://retell.discourse.group/t/how-can-i-create-an-outbound-call/132) [[3] Flex Mode](https://docs.retellai.com/build/conversation-flow/flex-mode) [[4] Speak During Execution not working for End Call node](https://discord.com/channels/1186424376300679209/1451006517909258352) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
f
@AI Evy So this is an incoming agent so I can't determine anything before the call starts because it's an incoming call. And anytime I let the prom try to determine the date and time It's inconsistent at best it it will book appointments for two years in the past without even thinking twice the underlying model has no concept of what time or day it is Is there some sort of built in variables when the call starts that I can reference In the dynamic variables?
a
Thanks for the follow-up, @FullThrottleFu. I'll get back to you soon.
### Answer --- Yes! Retell AI provides system default variables that are automatically available at call start—including current time and date. You can reference these directly in your prompt or first sentence without needing to compute anything beforehand. [(1) ]() Key variables for your use case: | Variable | Description | Example | |---|---|---| |
{{current_time}}
| Current time in
America/Los_Angeles
| "Thursday, March 28, 2024 at 11:46:04 PM PST" | |
{{current_time_[timezone]}}
| Current time in a specified timezone, e.g.,
{{current_time_Australia/Sydney}}
| "Thursday, March 28, 2024 at 11:46:04 PM AEDT" | |
{{current_calendar}}
| 14-day calendar in
America/Los_Angeles
| "Thursday, March 28, 2024 PST (Today) ..." | |
{{current_calendar_[timezone]}}
| 14-day calendar in a specified timezone | "Thursday, March 28, 2024 AEDT (Today) ..." | How to use for contextual greetings: In your agent's prompt or first sentence, you can include something like: > "The current time is {{current_time}}. Greet the caller appropriately based on the time of day (good morning, good afternoon, or good evening) ." For appointment booking accuracy: Reference
{{current_calendar}}
or
{{current_calendar_[timezone]}}
in your prompt to give the LLM an accurate 14-day calendar starting from today, which should help prevent it from booking appointments in the past.
​ To learn more, see the sources I considered: [[1] 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.
Thanks for the feedback, glad I was helpful.