### Answer
Welcome to Retell! Based on the sources, there are several common reasons why custom functions don't execute in conversation flows, especially when using agent transfers.
Key Issues to Check:
1. Separate the Custom Function into Its Own State
When you add a tool as "Optional" in a state, the LLM decides whether to call it based on conversation context. [(1) ](
) If your custom function and other tools (like end_call or transfer_call) are in the same state, the LLM might prioritize those over your webhook. [(2) ](
)
Solution: Create a dedicated state for your custom function that executes before any transfer or end-call actions.
2. Improve Your Prompt Instructions
Simply stating the function should execute isn't sufficient. You need to explicitly describe when the function should be invoked. [(3) ](
) For example:
When user provided the city name, please get the weather for that city by calling the `get_weather` function.