Skip to main content

Assistants API

Use Connery actions with OpenAI Assistants API.

IMPORTANT

This page is compatible with the Connery Runner (v0.0.8). In the meantime, we released v0.1.0 with the breaking changes, where we pivoted the project from the Connery Runner to the Connery SDK.

The Slack client does not yet support the plugins built using Connery SDK, but we are working on that. Stay tuned for updates.

If you have any questions or need help with the migration, please let us know in this discussion: Connery SDK v0.1.0.

Information

The Assistants API allows you 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.

Function Calling allows you to describe functions to the Assistants and have it intelligently return the functions that need to be called along with their arguments. The Assistants API will pause execution during a Run when it invokes functions, and you can supply the results of the function call back to continue the Run execution.

Connery actions can easily be used with the OpenAI Assistants API. See below how to configure and use it.

Helpful resources

Usage

Prerequisites

  1. Make sure you have a Connery runner up and running. You can use the Quickstart guide to set it up.
  2. Install plugins with actions you want to use with the Assistants API. You can find the list of available plugins in the Plugins page.

Add Connery actions to your assistant

Note on terminology

In Connery, we use the term "action". OpenAI also uses the term "action" in the GPTs context. However, in the Assistants API context, they use the term "function" instead of "action". Below, we use the term "function" to refer to the OpenAI Assistants API function and the term "action" to refer to the Connery action. But they are the same thing.

  1. Get OpenAI Functions specification for Connery actions installed on the runner.

Use the following API call to get the specification:

curl -L '<PUBLIC_RUNNER_URL>/v1/actions/specs/openai-functions' \
-H 'x-api-key: <CONNERY_RUNNER_API_KEY>'

The <PUBLIC_RUNNER_URL> and <CONNERY_RUNNER_API_KEY> you should get during the runner setup in the Quickstart guide.

In response, you will get an OpenAI Function specification for every action available on your Connery runner. For example, below is the specification for the "Send email" action from the connery-io/gmail plugin installed on the runner.

[
{
"name": "CABC80BB79C15067CA983495324AE709", // This is Connery Action ID that you will use later to run the action
"description": "Send email: Send an email to the recipient with the specified subject and body.",
"parameters": {
"type": "object",
"properties": {
"recipient": {
"type": "string",
"description": "Email Recipient: Email address of the email recipient."
},
"subject": {
"type": "string",
"description": "Email Subject: Subject of the email."
},
"body": {
"type": "string",
"description": "Email Body: Body of the email."
}
},
"required": ["recipient", "subject", "body"]
}
}
]
  1. Use the specification to add functions to your assistant.

You can do it using Assistant API. See the Defining functions section of the Assistants AI documentation for more information.

Once you add the functions, you can use them as any other functions in the Function Calling tool of the Assistants API.

Run Connery actions with the Assistants API

  1. Get functions from the model that have to be called.

When you initiate a run with a user message that triggers the function, the model can provide you with the list of functions that must be called.

See the Reading the functions called by the Assistant section of the Assistants AI documentation for more information on this step.

  1. Run the action on the runner and get the result.

Once you have the list of actions to run, you can run them on the Connery runner using the following API call for each function:

curl -L '<PUBLIC_RUNNER_URL>/v1/actions/<ACTION_ID>/run' \
-H 'Content-Type: application/json' \
-H 'x-api-key: <CONNERY_RUNNER_API_KEY>' \
-d '<ARGUMENTS>'

Replace <ACTION_ID> with the value you got from the model in the name field of the function.

Replace <ARGUMENTS> with the arguments you got from the model. It should be a flat JSON object like this:

{
"argument1": "value1",
"argument2": "value2"
}

After the action is executed on the runner, you will get the result in the response which you can send back to the model.

  1. Send the result back to the model.

See the Submitting functions outputs section of the Assistants AI documentation for more information on this step.