Adding Secret to agent using Agentverse API
Introduction
This example provides details on how to use the hosting API 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.
Please check out the example code in our examples repo (opens in a new tab) to run this locally.
Prerequisites
- Before you begin, ensure you have the following:
- Python version greater than 3.9 and less than 3.11.
- The requests library installed. You can install it using
pip 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
Script to add secret to agent
Self hosted
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 the directory where the
agent-secret
script is located using the 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
usingpython agent-secret.py
. - Provide agent's address, secret name and secret value.
- Use the secret name in the script instead of the value, for example
APIKey
in our case.
Expected Output
- Provide details and response based on whether the secret was added to the agent in Agentverse or not.