The GoGo Agent API

The API serves requests through Bittensor's Subnet 20 to enable tool-based workflows.

The API has a single endpoint for all queries - https://api.gogoagent.ai/v1

OpenAI Chat Completions Example
Python Example
Curl Example

Parameters:

Below are the available parameters for interfacing with the API:

prompt - a simple string with the user query - for use with the /completions endpoint

Example:

"I need help calculating the tip, what is 10% tip on a bill totalling $100"

messages - an array of role-based content dicts for user, assistant and system - for use with the /chat/completions endpoint

Example:

[
  {"role": "user", 
   "content": "I need help calculating the tip, what is 10% tip on a bill totalling $100"}
]

tools - an array of tool dicts with name, description and arguments

Example:

[
  {"name": "tip_calculator", 
   "description": "calculate tip for a total amount", 
   "arguments": {
     "bill_amount": {
        "required": True, "type": "number", 
        "description": "the bill amount in dollars"}, 
     "tip_percent": {
        "required": True, "type": "number", 
        "description": "the tip percentage as a whole number"}
  }}
]

Complete example with OpenAI Chat Completions:

Below is a complete Python example demonstrating how to use OpenAI Chat Completions with custom tools. This example includes a function to parse API responses and sample tool functions that can be dynamically executed.

import openai  # Import OpenAI SDK for API interaction

# Define API endpoint and model details
MODEL_API = "https://api.gogoagent.ai/v1"
MODEL_NAME = "BitAgent/GoGoAgent"
GOGO_API_KEY = "YOUR_API_KEY_HERE"

# Sample tool: Tip Calculator
def tip_calculator(bill_amount, tip_percent):
  return float(bill_amount) * (float(tip_percent) / 100)

# Sample tool: Summation Calculator
def calculator_for_summation(num1, num2):
  return float(num1) + float(num2)

# Function to parse the tool call response from GoGoAgent
def parse_tool_call(tool_call):
  result = {"name": "", "parameters": {}}
  
  # Remove outer brackets and extract tool name with parameters
  tool_call = tool_call.strip("[]")  # Strip brackets if present
  tool_name, params = tool_call.split("(", 1)
  tool_name = tool_name.strip()
  params = params.rstrip(")")

  # Initialize an empty dictionary for parameters
  params_dict = {}

  # Extract parameters in key="value" format
  for param in params.split(", "):
      if "=" in param:
          key, value = param.split("=", 1)
          value = value.strip('"')  # Remove quotes around the value
          params_dict[key.strip()] = value

  # Store the extracted tool name and parameters
  result = {"name": tool_name, "parameters": params_dict}

  # Return a list containing the parsed result (supporting future multiple tool calls)
  return [result]

# Initialize the OpenAI client with GoGoAgent API credentials
client = openai.OpenAI(
  api_key=GOGO_API_KEY,
  base_url=MODEL_API
)

# Define the user prompt (requesting help with a tip calculation)
messages = [
  {"role": "user",
  "content": "I need help calculating the tip; what is 10% tip on a bill totaling $210"}
]

# Define the available tools (functions) for GoGoAgent to select
tools = [
  {
    "name": "tip_calculator",
    "description": "Calculate the tip amount",
    "arguments": {
      "bill_amount": {
          "required": True, "type": "number",
          "description": "The bill amount in dollars"
      },
      "tip_percent": {
          "required": True, "type": "number",
          "description": "The tip percentage as a whole number"
      }
    }
  },
  {
    "name": "calculator_for_summation",
    "description": "Calculate the sum of two numbers",
    "arguments": {
      "num1": {
          "required": True, "type": "number",
          "description": "The first number for summation"
      },
      "num2": {
          "required": True, "type": "number",
          "description": "The second number for summation"
      }
    }
  }
]

# Send request to GoGoAgent LLM to determine which tool to use
completion = client.chat.completions.create(
  model=MODEL_NAME,  # Specify the model name
  messages=messages,  # Pass user messages
  tools=tools,  # Provide available tools for LLM to choose from
)

# Extract the tool call response from LLM output
result = completion.choices[0].message.content

# Parse the tool call response into a structured format
tool_calls = parse_tool_call(result)

# Dynamically execute the appropriate function with extracted parameters
tool_name = tool_calls[0]['name']
tool_params = tool_calls[0]['parameters']
result = globals()[tool_name](**tool_params)

# Output the result
print(result)

Example in Python:

Here’s a similar example using python and requests:

import json
import requests
# Define the tools
tip_calc_tool = {
  "name": "tip_calculator",
  "description": "Calculate the tip amount",
  "arguments": {
    "bill_amount": {
      "required": True, "type": "number",
      "description": "the bill amount in dollars"
    },
    "tip_percent": {
      "required": True, "type": "number",
      "description": "the tip percentage as a whole number"
    }
  }
}
# Define a summation calculator
sum_calc_tool = {
  "name": "sum_calculator",
  "description": "Calculate the sum of two numbers",
  "arguments": {
    "num1": {
      "required": True, "type": "number",
      "description": "the first number for summation"
    },
    "num2": {
      "required": True, "type": "number",
      "description": "the second number for summation"
    }
  }
}
tools = [tip_calc_tool, sum_calc_tool]
# Setup the messages / prompt
messages = [
  {"role": "user",
   "content": "I need help calculating the tip; what is 10% tip on a bill totalling $210"}
]
# Send the request to the API
api_endpoint = "https://api.gogoagent.ai/v1/chat/completions"
hdrs = {"Content-Type": "application/json",
        "Authorization": "API KEY GOES HERE"}
data = {"messages": messages, "tools": tools}
result = requests.post(api_endpoint, headers=hdrs, json=data)
# print out the results
print(result)
print(result.json())

Example in Curl:

And for fun, here’s the same query using curl (meaning you can use any libcurl-based library):

curl -X POST https://api.gogoagent.ai/query_subnet \
     -H "Content-Type: application/json" \
     -H "Authorization: API KEY GOES HERE" \
     -d '{
           "messages": [
             {
               "role": "user",
               "content": "Need help calculating the tip, what is 10% tip on a bill totalling $100"
             }
           ],
           "tools": [
             {
               "name": "tip_calculator",
               "description": "Calculate the tip amount",
               "arguments": {
                 "bill_amount": {
                   "required": true,
                   "type": "number",
                   "description": "the bill amount in dollars"
                 },
                 "tip_percent": {
                   "required": true,
                   "type": "number",
                   "description": "the tip percentage as a whole number"
                 }
               }
             }
           ]
         }'