Action Transformer API

The Action Transformer uses built-in API methods to make informed decisions while interacting with users. You can leverage these methods to control how the Action Transformer manages queries, processes data and generates responses.

API method name

Description

alan.actQueryCorpus

Queries data corpuses to retrieve relevant information for the user query.

alan.actMergeResponses

Combines information from different corpuses into a unified response and prioritizes data.

alan.actApplyTransform

Applies a specified transform to modify or enhance the collected data before delivering the final output.

alan.ActResult

Returns the final output from the Action Transformer after processing a query.

Example of use

Assume you want to provide detailed instructions to the Action Transformer and control every step of making a decision. To achieve this:

  1. To the dialog script, add data corpuses:

    Dialog script
    corpus({
        title: `Cleveland Clinic`,
        urls: [`https://my.clevelandclinic.org/health/treatments/penicillin`],
        depth: 1,
        maxPages: 1
    });
    
    corpus({
        title: `Health Direct`,
        urls: [`https://www.healthdirect.gov.au/penicillin`],
        depth: 1,
        maxPages: 1
    });
    
  2. Under Transforms, create the act_execute transform with the following instructions:

    Dialog script
    #import alan.actQueryCorpus, alan.actMergeResponses, alan.actApplyTransform, alan.ActResult
    
    The [[Input]] field contains a list of corpuses to answer the query.
    The [[Query]] field contains the user query.
    
    1. Analyze the user query and build a detailed plan how to answer the query.
    2. Find information in corpuses using the actQueryCorpus API.
    3. Prioritize information from the Health Direct corpus and merge results using the actMergeResponses API.
    4. Generate a JavaScript async function answerQuestion() with no arguments that follows the plan. The function must return Promise<ActResult>.
    
    If it is not possible to generate the function, generate null with a comment explaining why it is not possible.
    
    ../../../_images/act-functions.png
  3. To the dialog script, add the act() function with the execution parameter:

    Dialog script
    act({
        execution: transforms.act_execute
    });
    
  4. In the Debugging Chat, ask a question, for example: What are side effects of penicillin?

    ../../../_images/act-functions-chat.png
  5. Under Transforms, click the act_execute transform and in the top right corner, click History. In the top left corner of any cell of the query, click the Magnifying glass icon to zoom into the query. Make sure the Action Transformer has followed the instructions provided in the act_execute transform.

    ../../../_images/act-functions-history.png