Integration Guide

Code examples for integrating your AI agents with Vector Decisions.

Python Wrapper

import requests
import time
from typing import Optional

class VectorDecisions:
    def __init__(self, api_key: str, base_url: str = "https://vectordecisions.com/api/v1"):
        self.api_key = api_key
        self.base_url = base_url
        self.headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
        self.agent_id: Optional[str] = None

    def register_agent(self, name: str, agent_type: str, purpose: str, **kwargs) -> str:
        response = requests.post(f"{self.base_url}/agents", headers=self.headers,
            json={"name": name, "type": agent_type, "purpose": purpose, **kwargs})
        response.raise_for_status()
        self.agent_id = response.json()["id"]
        return self.agent_id

    def log_event(self, action: str, category: str = "SYSTEM",
                  event_type: str = "ACTION", **kwargs):
        headers = {**self.headers, "X-Agent-ID": self.agent_id}
        response = requests.post(f"{self.base_url}/events", headers=headers,
            json={"eventType": event_type, "action": action, "category": category, **kwargs})
        response.raise_for_status()
        return response.json()

    def log_decision(self, decision: str, reasoning: str = None, **kwargs):
        headers = {**self.headers, "X-Agent-ID": self.agent_id}
        response = requests.post(f"{self.base_url}/decisions", headers=headers,
            json={"decision": decision, "reasoning": reasoning, **kwargs})
        response.raise_for_status()
        return response.json()

    def should_continue(self) -> bool:
        headers = {**self.headers}
        response = requests.get(
            f"{self.base_url}/agents/{self.agent_id}/status", headers=headers)
        response.raise_for_status()
        return response.json()["shouldContinue"]

    def health_check(self, is_healthy: bool, **kwargs):
        headers = {**self.headers, "X-Agent-ID": self.agent_id}
        response = requests.post(f"{self.base_url}/health", headers=headers,
            json={"isHealthy": is_healthy, **kwargs})
        response.raise_for_status()

# Usage:
# vd = VectorDecisions("your_api_key")
# vd.register_agent("My Bot", "CHATBOT", "Customer support")
# vd.log_event("Handled customer inquiry", "COMMUNICATE")
# if not vd.should_continue():
#     print("Agent stopped by governance dashboard")

Node.js / TypeScript

class VectorDecisions {
  private apiKey: string;
  private baseUrl: string;
  public agentId: string | null = null;

  constructor(apiKey: string, baseUrl = "https://vectordecisions.com/api/v1") {
    this.apiKey = apiKey;
    this.baseUrl = baseUrl;
  }

  private get headers() {
    return {
      "Authorization": `Bearer ${this.apiKey}`,
      "Content-Type": "application/json",
      ...(this.agentId ? { "X-Agent-ID": this.agentId } : {}),
    };
  }

  async registerAgent(name: string, type: string, purpose: string) {
    const res = await fetch(`${this.baseUrl}/agents`, {
      method: "POST",
      headers: this.headers,
      body: JSON.stringify({ name, type, purpose }),
    });
    const data = await res.json();
    this.agentId = data.id;
    return data;
  }

  async logEvent(action: string, category = "SYSTEM", eventType = "ACTION") {
    return fetch(`${this.baseUrl}/events`, {
      method: "POST",
      headers: this.headers,
      body: JSON.stringify({ eventType, action, category }),
    }).then(r => r.json());
  }

  async shouldContinue(): Promise<boolean> {
    const res = await fetch(
      `${this.baseUrl}/agents/${this.agentId}/status`,
      { headers: this.headers }
    );
    const data = await res.json();
    return data.shouldContinue;
  }
}

// Usage:
// const vd = new VectorDecisions("your_api_key");
// await vd.registerAgent("My Bot", "CHATBOT", "Customer support");
// await vd.logEvent("Processed request", "READ");