Skip to content

Custom Tool Format

Custom tools in Cognipeer follow a specific JSON format that defines their properties, actions, API endpoints, and parameters. This document explains the structure and required fields in detail.

JSON Structure Overview

A custom tool definition is a JSON object with the following main sections:

  1. Tool metadata: Basic information about the tool
  2. Actions: Array of operations the tool can perform
  3. API configuration: HTTP endpoints and request details
  4. Parameters: Input schema for each action

Complete Example

Below is a complete example of a custom tool definition:

json
{
  "name": "ExampleTool",
  "label": "Example Tool",
  "actions": [
    {
      "name": "getInfo",
      "description": "Retrieves general information from the Example API.",
      "displayName": "Get General Information",
      "api": {
        "url": "https://api.example.com/v1/info",
        "method": "GET",
        "headers": {
          "Authorization": "Bearer <YOUR_API_KEY>",
          "Content-Type": "application/json"
        }
      },
      "parameters": {
        "type": "object",
        "properties": {
          "infoType": {
            "type": "string",
            "description": "Type of information to retrieve (e.g., 'summary', 'details').",
            "required": true
          }
        }
      }
    },
    {
      "name": "createItem",
      "description": "Creates a new item in the Example system.",
      "displayName": "Create New Item",
      "api": {
        "url": "https://api.example.com/v1/items",
        "method": "POST",
        "headers": {
          "Authorization": "Bearer <YOUR_API_KEY>",
          "Content-Type": "application/json"
        }
      },
      "parameters": {
        "type": "object",
        "properties": {
          "itemName": {
            "type": "string",
            "description": "The name of the item to create.",
            "required": true
          },
          "itemDescription": {
            "type": "string",
            "description": "A brief description of the item.",
            "required": false
          }
        }
      }
    }
  ]
}

Field Definitions

Root Level Properties

PropertyTypeRequiredDescription
namestringYesUnique identifier for the tool. Use camelCase without spaces.
labelstringYesHuman-readable name for the tool displayed in the UI.
actionsarrayYesArray of action objects that define the operations the tool can perform.

Action Properties

Each item in the actions array has the following properties:

PropertyTypeRequiredDescription
namestringYesUnique identifier for the action within this tool. Use camelCase.
descriptionstringYesDetailed description of what the action does. This helps the AI understand when to use it.
displayNamestringYesHuman-readable name for the action displayed in the UI.
apiobjectYesConfiguration for the HTTP request to be made.
parametersobjectYesJSON Schema defining the expected input parameters.

API Configuration

The api object defines the HTTP request configuration:

PropertyTypeRequiredDescription
urlstringYesFull URL of the API endpoint.
methodstringYesHTTP method: "GET", "POST", "PUT", "DELETE", etc.
headersobjectNoHTTP headers to include with the request.

Parameters Schema

The parameters object uses JSON Schema to define the input structure:

PropertyTypeRequiredDescription
typestringYesAlmost always "object" for a parameters schema.
propertiesobjectYesDefines each parameter that can be passed to the action.

Each parameter in the properties object has:

PropertyTypeRequiredDescription
typestringYesData type: "string", "number", "boolean", "array", or "object".
descriptionstringYesExplains the purpose of the parameter. Helps the AI use it correctly.
requiredbooleanNoWhether the parameter must be provided. Default is false.
enumarrayNoFor string types, limits the values to a specific set of options.
formatstringNoFor strings, specifies format like "date-time", "email", etc.

Parameter Types

Custom tools support these parameter types:

String

json
"customerName": {
  "type": "string",
  "description": "Full name of the customer",
  "required": true
}

Number

json
"amount": {
  "type": "number",
  "description": "Transaction amount in USD",
  "required": true
}

Boolean

json
"isPriority": {
  "type": "boolean",
  "description": "Whether this is a priority request",
  "required": false
}

Array

json
"items": {
  "type": "array",
  "description": "List of item IDs to process",
  "items": {
    "type": "string"
  },
  "required": true
}

Object

json
"address": {
  "type": "object",
  "description": "Customer shipping address",
  "properties": {
    "street": {
      "type": "string",
      "required": true
    },
    "city": {
      "type": "string",
      "required": true
    },
    "zipCode": {
      "type": "string",
      "required": true
    }
  },
  "required": false
}

Request Flow

When a Peer invokes a custom tool:

  1. User asks a question or makes a request
  2. Peer determines a custom tool action is needed
  3. Peer extracts necessary parameters from the conversation
  4. Cognipeer system makes the HTTP request to your API as configured
  5. API response is returned to the Peer
  6. Peer incorporates the response into its answer to the user

Best Practices

  1. Clear Descriptions: Write detailed descriptions for both actions and parameters
  2. Specific Names: Use clear, specific action names that describe what they do
  3. Required Parameters: Only mark parameters as required if they're truly needed
  4. Proper Authentication: Use appropriate API authentication methods
  5. Error Handling: Ensure your API returns clear error messages
  6. Response Format: Structure API responses for easy parsing by the AI

Next Steps

Built with VitePress