If you are looking for a function that only exists inside a single flow, visit the transition functions page.
Subpages
- How to set up a function: Learn how to set up a function, including naming conventions, parameter definitions, and writing Python code.
- How to import libraries: Understand how to use standard and non-standard libraries within your function, enabling external API integrations.
-
How to start a function:
Discover the role of the
start_function
in initializing conversation context and preparing data before user interactions. - Understanding return values: Explore how to use string and dictionary return values to dynamically guide the agent’s behavior.
-
Using the
conv
object: Reference theconv
object to manage conversation states, flows, and telephony-related attributes effectively. - Working with variables: Learn how to define, update, and persist variables across turns using the conversation state.
- Invoking functions in the knowledge base: Discover methods for integrating functions into the knowledge base and testing their usage effectively.
- The delay controls interface: Keep the conversation on track in high-latency functions by adding delay phrases.
If you are looking to use functions to enable multi-site configuration, like handling reservations for multiple restaurant locations, visit the variant management feature page.
Design best practices
-
Clear naming conventions:
- Always use descriptive, action-oriented names (e.g.,
book_reservation
,send_notification
). - Avoid vague or misleading names that might confuse the agent or developers.
- Always use descriptive, action-oriented names (e.g.,
-
Comprehensive descriptions:
- Provide explicit descriptions of what the function does, its parameters, and expected outputs.
- Ensure the description aligns with the agent’s broader purpose and use case.
-
Precise argument definitions:
- Use clear and meaningful argument names (e.g.,
date
,time
,guest_count
). - Document the purpose of each argument in the function’s docstring.
- Use clear and meaningful argument names (e.g.,
-
Control over triggering:
- Define specific rules and conditions in the agent’s prompts to ensure functions are only called when necessary.
- Avoid over-triggering or under-triggering by refining language inputs and prompts.
-
Readable parameter names:
- Use user-friendly parameter names to improve LLM comprehension (e.g.,
reservation_date
overr_date
).
- Use user-friendly parameter names to improve LLM comprehension (e.g.,
Using functions
-
Avoid misleading triggers:
- Ensure the rules and knowledge base accurately describe when to call a function.
- Use precise language in prompts to reduce ambiguity.
-
Provide detailed metadata:
- Add comprehensive descriptions in function definitions to guide the LLM effectively.
- Metadata should include the function’s purpose, parameters, and conditions for triggering.
-
Implement fallback mechanisms:
- Use stop keywords or catch-all conditions to prevent functions from misfiring.
- Test functions in simulated environments to ensure reliability.
-
Define in the knowledge base:
- Clearly state the function’s purpose and conditions for usage in the knowledge base rules.
-
Add function descriptions:
- Provide detailed explanations in the agent’s system prompts to guide its behavior effectively.
-
Iterative testing:
- Test functions in multiple scenarios to refine behavior and improve reliability.
Troubleshooting tips
-
Debugging triggers:
- Review logs to ensure functions are called at the appropriate time and with the correct parameters.
-
Checking outputs:
- Validate function outputs against expected results, especially when integrating external APIs.
-
Improving LLM comprehension:
- Simplify function descriptions and prompts if the agent struggles to trigger them appropriately.
-
Monitoring user interactions:
- Analyze real-world usage data to identify and resolve any inconsistencies in function behavior.