npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

clevagent

v0.1.0

Published

Monitor your AI agents in 2 lines of code — heartbeat watchdog, loop detection, cost tracking, auto-restart

Readme

ClevAgent Node.js/TypeScript SDK

npm version License: MIT Node.js 16+

Runtime monitoring for AI agents. Heartbeat watchdog, loop detection, cost tracking, auto-restart — in 2 lines of code.

Installation

npm install clevagent

Quick Start

import clevagent from "clevagent";

// Initialize at agent startup — starts background heartbeats
clevagent.init({
  apiKey: "cv_your_api_key",  // from ClevAgent dashboard
  agent: "my-agent",          // unique name in your project
});

// Your agent runs normally...
// Heartbeats are sent automatically every 60 seconds.
// If the process crashes or hangs, alerts fire automatically.

API

clevagent.init(options)

Initialize monitoring. Call once at startup.

clevagent.init({
  apiKey: "cv_xxx",           // required
  agent: "my-agent",          // required
  interval: 60,               // heartbeat interval in seconds (default: 60)
  endpoint: "https://clevagent.io",  // override for self-hosted
  onLoop: "stop",             // "stop" | "alert_only" | () => void  (default: "stop")
  onCostExceeded: "alert_only",      // "stop" | "alert_only" | () => void  (default: "alert_only")
});

clevagent.ping(options?)

Send a manual heartbeat with status/metrics.

clevagent.ping({
  status: "ok",              // "ok" | "warning" | "error"
  message: "Processed 100 items",
  tokensUsed: 1500,
  costUsd: 0.023,
  iterationCount: 42,
});

clevagent.logPrompt(text)

Record a prompt for semantic loop detection. Hashes the text (SHA-256, 16 hex chars) and stores it in a rolling window of 5. The server detects 3/4+ identical hashes as a suspected stuck loop.

const userMsg = "Summarize the Q3 earnings report";
clevagent.logPrompt(userMsg);
const response = await openai.chat.completions.create({
  messages: [{ role: "user", content: userMsg }],
});

clevagent.logToolCall(name, argsSummary?)

Record a tool call for semantic drift analysis (Pro+ feature).

The last 20 tool calls are included in each heartbeat. The ClevAgent semantic detector compares them against the agent's task_description and fires an intent_drift alert if the agent's behavior diverges from its stated goal.

// Record manually:
clevagent.logToolCall("db_query", "SELECT * FROM orders WHERE status='pending'");
clevagent.logToolCall("send_email", "[email protected] subject=Report");

clevagent.logCost(tokens, costUsd)

Manually record cost data (use when you need precise accounting).

const response = await anthropic.messages.create({ ... });
clevagent.logCost(
  response.usage.input_tokens + response.usage.output_tokens,
  0.0045
);

clevagent.logIteration(count)

Update the current loop iteration count.

for (let i = 0; i < MAX_ITER; i++) {
  clevagent.logIteration(i);
  // ... agent work
}

clevagent.shutdown()

Stop monitoring gracefully. Sends a final "shutdown" heartbeat. Auto-called on SIGTERM / SIGINT.

await clevagent.shutdown();

Example: LangChain Agent

import clevagent from "clevagent";

clevagent.init({ apiKey: process.env.CLEVAGENT_API_KEY!, agent: "langchain-agent" });

async function runAgent() {
  for (let i = 0; i < 100; i++) {
    clevagent.logIteration(i);

    const result = await chain.call({ input: userQuery });

    // Log tool calls manually for semantic analysis
    for (const step of result.intermediateSteps) {
      clevagent.logToolCall(step.action.tool, step.action.toolInput?.toString() ?? "");
    }

    clevagent.ping({ status: "ok", message: `Completed iteration ${i}` });
  }
}

runAgent().finally(() => clevagent.shutdown());

Example: OpenAI Function Calling

import OpenAI from "openai";
import clevagent from "clevagent";

clevagent.init({ apiKey: process.env.CLEVAGENT_API_KEY!, agent: "openai-agent" });

const openai = new OpenAI();

async function callWithTools() {
  const response = await openai.chat.completions.create({
    model: "gpt-4o",
    messages: [{ role: "user", content: "What's the weather?" }],
    tools: [weatherTool],
  });

  // Log token usage and tool calls
  clevagent.logCost(response.usage?.total_tokens ?? 0, 0);
  for (const choice of response.choices) {
    for (const tc of choice.message.tool_calls ?? []) {
      clevagent.logToolCall(tc.function.name, tc.function.arguments);
    }
  }
}

Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | required | Project API key (cv_xxx) | | agent | string | required | Agent name | | interval | number | 60 | Heartbeat interval (seconds) | | endpoint | string | "https://clevagent.io" | API base URL | | onLoop | string \| () => void | "stop" | Action on loop detection | | onCostExceeded | string \| () => void | "alert_only" | Action on cost threshold |

Requirements

  • Node.js >= 16
  • No runtime dependencies (uses built-in https and crypto modules)

Links

License

MIT — see LICENSE.