The OpenAI: Run Assistant function action unlocks a new level of
capability for your OpenAI Assistant. It utilizes the OpenAI Assistants API, actively enabling assistants to call upon
external functionalities during conversations. This feature acts as a bridge, actively
connecting your assistant to a vast toolbox of additional powers.
Before you begin
- You must have the Bot creator role to use the OpenAI Run Assistant function action in an automation.
- Ensure that you have the necessary credentials to send a request and have
included OpenAI: Authenticate action before calling any OpenAI actions.
- You must have a OpenAI: Run Assistant action prior to
calling OpenAI Run Assistant function.
About this task
This example delves into using OpenAI Run assistant functions that
extends your assistant's capabilities. You will explore how to call an existing
assistant within the Run environment, extract crucial information (Thread
ID, Call ID, and Run ID), and
leverage these IDs to define a tailored function response. For instance, here a
Stock market assistant is loaded and the function results are defined
using the tools output list (Function response).
Procedure
-
In the Automation Anywhere Control Room, navigate to the
Actions pane, select , drag Authenticate action, and place it
in the canvas. To authenticate you need an API Key. For more information on
generating an API key and authentication, see OpenAI: Authenticate action.
-
Place the Open AI: Run Assistant action below the
Authenticate action and use Load assistants, to load an
assistant (Stock market assistant). Enter a
Message (Get Stock price for AAINC). The
response is saved to a string variable str_Response. For more
information on using Open AI: Run Assistant action, see
OpenAI: Run Assistant action.

Note: For illustrative purposes only, the fictional stock
code AAINC is used in this example. The price of $3200 assigned to AAINC is
a sample value and does not represent the price of any real stock.
The Stock market assistant loaded from OpenAI contains the following
instruction and function:
You are a stock market assistant. When asked a question related to stocks use the function and get the stock price.
{
"name":"get_stock_price",
"description":"Get the current stock price",
"parameters":{
"type":"object",
"properties":{
"symbol":{
"type":"string",
"description":"The stock symbol"
}
},
"required":[
"symbol"
]
}
}
-
From the Actions pane, drag the action and drop it into the canvas below the Open AI:
Run Assistant action.
-
In the Data Source field, select
Text and
enter
$str_Response$.
-
In the JSON Object session field,
select Local session and enter
Default.
You now have the entire JSON. The next task is to extract the required fields from
the body. The following snippet shows a sample
JSON:
{
"data":{
"thread_id":"thread_hiCr3najXMSxuuiIntJDXDXd",
"tool_calls":[
{
"id":"call_Beu0XFPGR91RZGoXBA8ODSke",
"type":"function",
"function":{
"name":"get_stock_price",
"arguments":"{\n\"symbol\": \"AAINC\"\n}"
}
}
],
"id":"run_LnR669bHLcMAaIGOcvIE0nVa"
},
"status":"requires_action"
}
Note: The tool_calls and
tool_outputs within an OpenAI
Assistant message can handle scenarios where the user makes multiple
requests in a single message. For instance, Get the stock price of AAINC
and BBINC. This single message actually contains two distinct
requests: finding the stock price for AAINC and finding the stock price for
BBINC.
-
Extract the required fields from the JSON to execute the OpenAI:
Run Assistant Function.
-
From the Actions pane, drag the
action and drop it into the canvas below the action. For more information on JSON: Get node value
action, see Get node value action in JSON.
-
Specify the nodes to be extracted. For example, to extract the
thread_id, you can use
data.thread_id
-
Create a variable thread_id and assign the output to this
variable.
-
Similarly extract
run_id and
call_id(data.id and
data.tool_calls[0].id) and save it in a variable
run_id and call_id.
-
Navigate to the Actions pane, select , drag OpenAI: Run Assistant Function
action, and place it in under the last Get node value
action.
-
Use the extracted $thread_id$ in the Thread
ID field.
-
Use the extracted $run_id$ in the Run ID
field.
-
Define a Function response using the standard
schema below. The schema is a JSON object containing information about
the output of a tool (function) used by the OpenAI Assistant.
{
"tool_outputs":[
{
"tool_call_id":"Enter the call ID",
"output":"{Enter your output}"
}
]
}
After processing your request and running the appropriate function,
you need to communicate the results back to the OpenAI Assistant
API. To do this, you need to create a special list as shown above
called the tools output list. This list contains
the following properties:
- tool_call_id (string): This property holds a unique
identifier for the specific call of the tool (function) that
generated the output. This ID helps track and reference the
specific execution instance of the tool.
- output (any): This property holds the actual output data
generated by the tool. The data type of output can vary
depending on the specific tool and its purpose. It could be:
- A string (such as a text generated by a creative writing
function)
- A number (such as a calculation result)
- A list (such as a collection of retrieved data
points)
- A dictionary (such as complex data structure with
multiple values)
- Any other valid JSON data type
For instance, in this example input the following JSON:
{
"tool_outputs":[
{
"tool_call_id":"$call_id$",
"output":"{3200}"
}
]
}
-
Enter Default as the session name to confine to the current
session.
-
Save the response to a variable. In this example, the response is saved
to a string variable str_FunctionResponse. The output
is a JSON that displays the value you asked to output and here below is
a sample output from the above run:
:
{
"data":[
{
"metadata":{
},
"role":"assistant",
"content":[
{
"type":"text",
"text":{
"value":"The current stock price for AAINC is $3200.",
"annotations":[
]
}
}
]
}
],
"status":"completed"
}}
The OpenAI: Run Assistant Function action
revolutionizes how OpenAI Assistants operate, transforming them from simple
information providers to powerful tools that can take action and fulfill
requests. By leveraging external functionalities, assistants can now tackle
complex tasks, deliver personalized recommendations as shown in the above
example, and ultimately provide a more comprehensive and helpful user
experience.