Action API
This page describes the Action API and how to use it.
This API is available only on the Professional Plan and above.
Introduction
Conversations can be made even more engaging if they result in driving the behaviour of your character and give it the ability to manipulate the environment. The Action API enables this by allowing you to define various actions that the character can perform. The actions are often tied to the available objects in the environment.
To get the most use of the Action API, a few things must be understood to get the most out of it. Here we explain some principles that should guide how to write each of these.
This tutorial will use code examples and comments to show how to use the Action API effectively.
Setup
The following things need to be set up in order to successfully follow along with this tutorial. Make a colab notebook would suffice without installing any packages to be able to follow along.
# Importing a couple of libraries
import base64
import json
import requests
# Use your character id here
CHAR_ID = "<your character id>"
# You should set your Convai API key here
CONVAI_KEY = "<your convai api key>"
# This is the URL which will generate actions and responses
action_url = "https://api.convai.com/character/getResponse"
# URL for updating the backstory
url = "https://api.convai.com/character/update"Components of the Action API
The building blocks of what is needed to generate actions in an environment are the following.
Actions
Objects
Characters
Backstory
Let us now discuss these in some detail. We are listing these out here, but you should return to each section as you are setting them up.
Objects
Same as actions, there are a few details regarding objects that the user should be aware of. If you have multiple similar objects, it's best to number them. For example, instead of putting “5 Chairs”, you should put “Chair#1”, “Chair#2”, and so on. If you need your character to bring you a specific object, you should also ask specifically for it, i.e. “Bring me chair number 3”. You can also mention the action which can interact with the object to increase effectiveness.
Below we provide two examples of how to define objects and describe how to best define them.
Backstory
It is important to know that the backstory also influences how the action API performs. The most important thing that can be done for effective action generation is to put some information about the objects, characters and actions in the backstory itself. (You can also use the knowledge bank to put this information in, but we recommend using the backstory to do this instead) We shall provide an example of how to do this here. You can see how we state what kind of objects are in the scene and some information about them. It is also good to specify some information about the environment here if you can.
Any information about the character itself can be placed in the knowledge bank.
Actions
Actions are the core of this API. To create effective actions, you need to ensure that the actions can be applied generally and are simple. Try not to make the actions too specific. For example, an action called “Show” will be more effective than “Demonstrate”. Similarly, “Walks To” or “Runs To” would be less effective than “Moves To” or “Go To” since the second set is in some sense more “general” than the first.
You should also maintain consistent casing while defining actions. If you go with lowercase, then write all actions in lowercase and so on. To get the best performance, the actions must also make sense in the context of the character’s background.
Actions can be sent via the API call or can be set in the Playground UI. We demonstrate the API call version here. If you want to set them using the UI, go to https://convai.com/pipeline/dashboard/character and click on the Actions button and add your actions and finally, click the Update button.
Characters
This is pretty simple, just provide the characters that are present in the scene. You can add more than two characters; for example, if you are in a restaurant with multiple people, you can add all of them here.
You should make sure that you include important information about your characters in the either the knowledge bank or the backstory. And not use the bio for any truly important information.
API Reference
We now we can finish up this tutorial with an API reference and all the ways you can call the Action API.
Last updated
Was this helpful?