This page explains all the required steps to successfully make an API call to collect the conversations with an agent.

Relevance Keys

When on API keys page, scroll down and you will see the Region code and your Project Id. Region

To generate your Relevance API key, click on "Create new secret key", with the role "Admin". Click on "Generate API key". Copy the values shown on the modal.

  • Authorization token
  • API key
  • Region
  • Project

Authorization tokens are formed under Project Id:API Key.

Agent Id

Currently, the easiest way to access Agent Ids is from URLs. For instance, when on the "Edit agent" page, the last piece after project id and before /edit shows the Agent Id. The URL is structured as

https://app.relevanceai.com/agents/REGION/Project-Id/Agent-Id/edit

Conversation Id

From URL

Currently, the easiest way to access a conversation Id is from the page URL. Click on the target conversation. In the URL, the last piece after the Agent id and before ?studioId= shows the Conversation Id. The URL is structured as

https://app.relevanceai.com/agents/REGION/Project-Id/Agent_Id/Conversation_Id?studioId=agent_....

API call to list all conversation Ids

Relevance stores agent conversations in knowledge. To list all conversations with your Agent, provide the corresponding values for Region, Agent Id and Authorization token in the code snippet below.

authorization_token = f"{project_id}:{api_key}"   # Both values can be found in the API Keys page
region = Region       # Can be found in the API Keys page
agent_id = Agent_id   # Can be found in the Agent page URL

The endpoint to list all conversation Ids:

https://api-{Region}.stack.tryrelevance.com/latest/knowledge/sets/list

<Region> can be found at API keys.

url = f"https://api-{region}.stack.tryrelevance.com/latest/knowledge/sets/list"
filters = [
            {
              "filter_type": "exact_match",
              "field": "type",
              "condition_value": "conversation",
            },
            {
                "filter_type": "exact_match",
                "field": "conversation.agent_id",
                "condition_value": agent_id
            }
]

headers = {
      "Authorization": authorization_token
  }

payload = {"filters":filters, "include_hidden":True}

payload_json = json.dumps(payload)

# Send the POST request
response = requests.post(url, headers=headers, data=payload_json)

response.json()["results"]

The output is a list of dictionaries. All conversation Ids associated with the target agent can be found under the knowledge_set field. In the sample below, 041157d4-61bb-4855-8202-cdf8fab7202a is a conversation that can be used in the next step.

'knowledge_set': '041157d4-61bb-4855-8202-cdf8fab7202a'

API call to list all conversations using the conversation Id(s)

To list all conversations with your Agent, provide the corresponding values for Region, Conversation Id and Authorization token in the code snippet below. The output is a list of all conversations registered between the Agent and the user under the provided conversation Id.

authorization_token = f"{project_id}:{api_key}"   # Both values can be found in the API Keys page
region = Region                                   # Can be found in the API Keys page
conversation_id = Conversation_Id                 # From the previous step

The endpoint to list all conversations with an agent:

https://api-{Region}.stack.tryrelevance.com/latest/knowledge/list

<Region> can be found at API keys.

url = f"https://api-{region}.stack.tryrelevance.com/latest/knowledge/list"

headers = {"Authorization": authorization_token}

payload = {
    "knowledge_set": conversation_id,
    "filters": [],
    "sort": [
        {
            "insert_date_": "desc"
        }
    ]
}
payload_json = json.dumps(payload)

# Send the POST request
response = requests.post(url, headers=headers, data=payload_json)

conversation_messages = response.json()["results"]