Overview
Overview of functions including creation, invocation, and secret retrieval
Functions are custom Python scripts designed to handle tasks requiring deterministic logic or API integrations. They enhance the assistant’s ability to interact with external systems and allow for advanced customization of responses.
For detailed guides, explore the subpages below:
Subpages
-
How to create a function: Learn the step-by-step process for creating a function. This guide covers everything from naming conventions and parameter definitions to writing the function code in Python.
-
How to invoke a function in the knowledge base: Discover how to integrate your functions into the knowledge base. This guide explains different methods to add functions and provides tips for testing and optimizing their use.
-
How to retrieve secrets: Understand how to securely retrieve secrets within your functions. This guide provides best practices for handling sensitive information and integrating it into your function logic.
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 assistant 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 assistant’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 assistant’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 assistant’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 assistant struggles to trigger them appropriately.
-
Monitoring user interactions:
- Analyze real-world usage data to identify and resolve any inconsistencies in function behavior.