Overview

Learn how to implement AI tracking using Handit.AI's wrapper-based approach.

Basic Implementation

import { startAgentTracing, traceAgentNode } from '@handit.ai/node';
import { OpenAI } from 'openai';

const openai = new OpenAI();

// Define your agent function
async function myAgent(input) {
  // Define a node (e.g., GPT call)
  const gptNode = async (messages) => {
    const response = await openai.chat.completions.create({
      messages,
      model: "gpt-4"
    });
    return response;
  };
  
  // Wrap node with tracing
  const tracedGpt = traceAgentNode({
    agentNodeId: agentsTrackingConfig.mariaManager.documentCompressor,
    callback: gptNode
  });
  
  // Execute traced node
  return await tracedGpt(input);
}

// Wrap entire agent with tracing
const tracedAgent = startAgentTracing(myAgent);

// Use the agent
const result = await tracedAgent({ 
  messages: [{ role: "user", content: "Hello!" }] 
});

Advanced Usage

Multiple Node Tracing

Track multiple nodes within a single agent:

async function complexAgent(input) {
  // First node: Document compression
  const compressNode = traceAgentNode({
    agentNodeId: agentsTrackingConfig.mariaManager.documentCompressor,
    callback: async (doc) => {/* compression logic */}
  });
  
  // Second node: Task assignment
  const assignNode = traceAgentNode({
    agentNodeId: agentsTrackingConfig.mariaManager.taskAssigner,
    callback: async (task) => {/* assignment logic */}
  });
  
  const compressed = await compressNode(input);
  const assigned = await assignNode(compressed);
  return assigned;
}

const tracedComplexAgent = startAgentTracing(complexAgent);

Tracking AI Tools

Software Tools

  • APIs

  • Databases

  • External AI models

Non-Software Tools

  • Hardware sensors

  • Human escalations

Last updated