Conditional Templates allow you to use saved values from API calls to change the instructions for a given task. GenerativeAgent uses the conditional templates to render API and Prompt instructions based on the conditions and values in each template.Documentation Index
Fetch the complete documentation index at: https://docs.asapp.com/llms.txt
Use this file to discover all available pages before exploring further.
Conditional Templates must be referenced in Jinja2 templating language conditional statements.
Head to the Jinja Documentation to dive further into Conditional Statements
Write Conditional Templates
Conditional templating supports rendering based on the presence of data in an API Response Model Action. The system pulls this data at run-time from the input model context (list of ModelActions) and stores it in reference variables that you can use in Jinja2 conditional statements.If you want to render based on ModelActions that are not API Responses, it will require further help from your ASAPP Team.
- Identify the Function and the keypath to the value from the API response you want to use for conditional rendering.
- Add a reference variable to the list of reference_vars for the Function in the company’s functions.yaml. It should include name and response_keypath at minimum, with the response_keypath format being response.<your_keypath>. You can optionally define a transform expression with val as the keypath value to be transformed. Note that these reference variables are used across the company’s Tasks, so the name parameter must be unique.
- Use the conditional in two places by referencing vars.get(“my_reference_var_name”):
- In a Task, add Jinja2 conditional statements in the prompt_instructions and define conditions for each TaskFunction so they only render when the condition evaluates to True.
- Conditions on TaskFunctions are optional, and functions will always render in the final prompt if no conditions are provided.
- In a Function, add Jinja2 conditional statements to the Function’s description.
Available Variables
The following variables are available to use in the conditional templates:| Variable | Description | Example |
|---|---|---|
vars | A dictionary of reference variables. | vars.get("my_reference_var_name") |
input_vars | A dictionary of input variables. | input_vars.get("my_input_var_name") |
function_responses | A dictionary where keys are function names and values are the corresponding function response data. If the system finds no function responses in the actions, it returns an empty dictionary. | function_responses.get("my_function_response_name") |
current_datetime | The current date and time. | current_datetime |
channel_type | The type of channel the conversation is on. Can be either voice or messaging. | channel_type |
queue_status | A dictionary of queues and a boolean of whether the queue is open. | queue_status.get("general_queue") |
Use Case Example - Mobile Bill
This use case example makes GenerativeAgent behave as follows:- If CPNI compliance is unknown, only render the identity API without its description about checking the response field “data[‘cpniCompliance’]”, and render in the prompt_instructions that tell the LLM it must first confirm the customer is CPNI compliant.
- If a customer is not CPNI compliant, only render the identity API with its description about checking the response field “data[‘cpniCompliance’]”, and do not render in the prompt_instructions that tell the LLM it must first confirm the customer is CPNI compliant.
- If a customer is CPNI compliant, do not render the identity API and render the APIs that require CPNI compliance instead, and do not render in the prompt_instructions that tell the LLM it must first confirm the customer is CPNI compliant.