OpenAI: Run Assistant action

The OpenAI: Run Assistant action uses OpenAI's Assistant API to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries. The Assistants API currently supports three types of tools: Code Interpreter, Retrieval, and Function calling.

Prerequisites

  • You must have the Bot creator role to use the OpenAI Run Assistant action in an automation.
  • Ensure that you have the necessary credentials to send a request and have included Authenticate action before calling any OpenAI actions.
  • Understanding the assistant limitations: Knowing the assistant's capabilities and limitations helps you to set realistic expectations.

This example shows how to load an existing assistant in the OpenAI Run Assistant action and get an appropriate response. If you are interested to learn how to create your own assistant, see OpenAI Create Assistant.

Procedure

  1. In the Automation Anywhere Control Room, navigate to the Actions pane, select Generative AI > OpenAI, drag OpenAI: Run Assistant, and place it in the canvas.
  2. Enter or select the following fields:

    OpenAI: Run Assistant

    1. Click Load assistants, to select an existing assistant. You need to authenticate ( see Authenticate action) with the API Key.Open AI: Connect
      1. Connect to Open AI appears. You can input the API Key either through a saved credential in the Credential tab or select Insecure string tab to directly paste the API Key.
      2. The Assistant ID of the assistant selected is displayed in the Assistant ID field.
      Note: Understanding an assistant's limitations before selecting it is crucial for a smooth user experience. Imagine requesting a flight reservation, only to discover the assistant cannot access booking systems. By familiarizing yourself with the assistant's capabilities beforehand, you can avoid such frustrating scenarios.
    2. Enter a Message to use by the model to generate a response.
      Note:

      The Run Assistantaction retains the results of the previous action within the same conversation. If you call Run Assistantactions consecutively, the assistant will remember the context of the conversation within the same thread and be able to relate subsequent messages to the previous ones. However, this conversation history is cleared once the session ends. A new thread is created for each new session.

    3. Enter Default as the session name to confine to the current session.
    4. To manage the optional parameters, select Yes under Show more options to add additional parameters such as:Model, Instructions, Additional instructions, Files and Metadata. You can also enable Code interpreter, Retrieval or Function options to expand the capabilities of your assistant and allow it to perform more complex tasks. For information about these optional parameters, see OpenAI Create Run.
      Note: By selecting these optional parameters, to define Model, Instructions and so on allows you to fine-tune the behavior of the assistant by overriding its default settings.
      • Code Interpreter: Enables assistants to execute custom Python code, facilitating data manipulation, logic integration, and automation tasks. For example
      • Retrieval: Allows assistants to search for and process information from external sources, enriching conversations and providing contextually relevant responses.
      • Function: Allows assistants to search for and process information from external sources, enriching conversations and providing contextually relevant responses.
    5. Save the response to a variable. In this example, the response is saved to a string variablestr_asst_Response. The output is a JSON and here below is a sample output from the above run:
      {
         "metadata":{
            
         },
         "data":[
            {
               "role":"assistant",
               "content":[
                  {
                     "type":"text",
                     "text":{
                        "value":"New York is a bustling metropolis known as \"The Big Apple,\" renowned for its iconic skyline, cultural diversity, and status as a major global financial, entertainment, and cultural center.",
                        "annotations":[
                           
                        ]
                     }
                  }
               ]
            }
         ],
         "status":"completed"
      }
Code interpreter:

The following example demonstrates how to use the assistant with the code interpreter enabled to generate the first eight terms of the Fibonacci sequence.

OpenAI Run Assistant Code Interpreter

The response of the above automation is as follows:

{
   "metadata":{
      
   },
   "data":[
      {
         "role":"assistant",
         "content":[
            {
               "type":"text",
               "text":{
                  "value":"The first 8 terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13.",
                  "annotations":[
                     
                  ]
               }
            }
         ]
      }
   ],
   "status":"completed"
}
Retrieval:

The following example demonstrates how to use the assistant with retrieval enabled. In this scenario, the assistant reads the attached file to generate the response.

OpenAI Run Assistant Code retrieval

The response of the above automation is as follows:

{
   "metadata":{
      
   },
   "data":[
      {
         "role":"assistant",
         "content":[
            {
               "type":"text",
               "text":{
                  "value":"The holidays listed in the 2024 USA holiday schedule are as follows:\n\n1. New Year\u0027s Day: January 1, Monday\n2. MLK Day: January 15, Monday\n3. President\u0027s Day: February 19, Monday\n4. Memorial Day: May 27, Monday\n5. Juneteenth: June 19, Wednesday\n6. Independence Day: July 4, Thursday\n7. Labor Day: September 2, Monday\n8. Thanksgiving Day: November 28, Thursday\n9. Day after Thanksgiving: November 29, Friday\n10. Christmas Eve: December 24, Tuesday\n11. Christmas Day: December 25, Wednesday\n12. New Year\u0027s Eve: December 31, Tuesday",
                  "annotations":[
                     
                  ]
               }
            }
         ]
      }
   ],
   "status":"completed"
}
Note: To upload multiple files, you can add a list of File IDs. These File IDs are unique identifiers assigned to files uploaded using the OpenAI API. For more information on uploading and retrieving Files in a Assistant, see OpenAI Files Operations.

OpenAI Run Assistant multiple File IDs

Function:

The following example demonstrates how to use the assistant with a function. In this scenario, imagine you want your assistant to retrieve weather information. By feeding it a new function named get_weather (along with a description and parameters), you equip the assistant with this new skill.

{
    "name": "get_weather",
    "description": "Determine weather in my location",
    "parameters": 
    {
       "type": "object",
       "properties": {
          "location": {
             "type": "string",
             "description": "The city and state e.g. San Francisco, CA"
          },
          "unit": {
             "type": "string",
             "enum": [
                "c",
                "f"
             ]
          }
       },
       "required": [
          "location"
       ]
    }
 }

The JSON output following the below image highlights the assistant's status as requires_action. This indicates that the assistant awaits your input on how to proceed. You can now leverage the OpenAI: Run Assistant Function action to instruct the assistant on how to use the newly introduced get_weather function and formulate an appropriate response based on the retrieved data.

Open AI Run Assistant Action Function

The response of the above automation is as follows:

{
   "data":{
      "thread_id":"thread_Aq8I25CKOFAZ50GkVDH4gZXw",
      "tool_calls":[
         {
            "id":"call_zkehFEVLaXyuEND9kSRgq4O1",
            "type":"function",
            "function":{
               "name":"get_weather",
               "arguments":"{\"location\":\"Chicago, IL\"}"
            }
         }
      ],
      "id":"run_s3jWsc8H2xaGV6E28CevuXsG"
   },
   "status":"requires_action"
}
You can use the thread id, call id and run id from the JSON to call the OpenAI: Run Assistant Function action.