Adding Secret to Agents using Agentverse APIs
Introduction
This guide provides details on how to use the Agentverse hosting APIs to add a secret to an agent. Secrets are added to an agent to ensure they remain hidden from end users and to enhance security. Before you begin, ensure you satisfy the following pre-requisites:
- Python version greater than 3.9 and less than 3.11.
- The
requests
library installed. You can install it usingpip install requests
. - Agentverse (opens in a new tab) credentials.
Steps to get API Tokens
- Go to Profile section in Agentverse (opens in a new tab).
- Click on button
+ New API Key
. - Give name to your API key.
- Click on
write
forAccess to all resources in Agentverse
and click onGenerate API Key
Let's explore the script for this example!
Script to add secret to agent
-
Create a Python script and name it
agent_secret.py
using:windowsecho. > agent_secret.py
-
Within the script have just created, import the
requests
library:# Importing libraries import requests
-
Define the token variable with your Fauna access token:
# Decode the refresh token token = 'Bearer fauna_access_token'
-
Now, input the agent's address, the name for the secret, and the value of the secret:
# Take name of agent and secret details from user address = input('Please enter address of agent to which you want to add the secret: ') name = input("Please enter name for your secret: ") secret = input("Please enter value for your secret: ")
-
Create the payload for the POST request to add the secret:
# Create Payload for post request data = { 'address': address, 'name': name, 'secret': secret }
-
Send the POST request to the Agentverse API to add the secret:
# Post request to add secret to agent response_agent = requests.post("https://agentverse.ai/v1/hosting/secrets", json=data, headers={"Authorization": token})
-
Check if the response status code is 200 (success) and print an appropriate message:
# Check if the response code is 200 if response_agent.status_code == 200: print("Secret added successfully.") else: print(f"Failed to add secret. Status code: {response_agent.status_code}")
The full script should look as follows:
agent_secret.py# Importing libraries import requests # Decode the refresh token token = 'Bearer fauna_access_token' # Take name of agent and secret details from user address = input('Please enter address of agent to which you want to add the secret: ') name = input("Please enter name for your secret: ") secret = input("Please enter value for your secret: ") # Create Payload for post request data = { 'address': address, 'name': name, 'secret': secret } # Post request to add secret to agent response_agent = requests.post("https://agentverse.ai/v1/hosting/secrets", json=data, headers={"Authorization": token}) # Check if the response code is 200 if response_agent.status_code == 200: print("Secret added successfully.") else: print(f"Failed to add secret. Status code: {response_agent.status_code}")
Steps to add secret to Agent using API
-
Navigate to th directory where
agent-secret.py
script is located using your terminal. -
Open Agentverse (opens in a new tab) and generate API keys .
-
Open script in editor and replace
fauna_access_token
. -
Run
agent-secret.py
file using:python agent-secret.py
-
Provide agent's address, secret name and secret value.
-
Try using secret name in script instead of value, for example
APIKey
in our case.
Expected Output
Provide details and response on basis of secret added or not to the Agent in Agentverse.
We encourage everyone operating on DeltaV to select the Next Generation AI Engine personality type. This AI Engine personality stands as a significant personality type offering enhanced scalability, reliability, and flexibility. The major key features include advanced context understanding, improved function recommendations, and the ability to handle multiple dialogue formats.