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

@reaatech/agent-mesh-classifier

v1.0.0

Published

Gemini Flash intent classifier for agent-mesh

Downloads

167

Readme

@reaatech/agent-mesh-classifier

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Gemini Flash intent classifier for the agent-mesh orchestrator. Dynamically builds prompts from the agent registry, classifies user requests with confidence scoring and language detection, and falls back to a mock keyword-based classifier when Gemini is unavailable.

Installation

npm install @reaatech/agent-mesh-classifier
# or
pnpm add @reaatech/agent-mesh-classifier

Feature Overview

  • Gemini Flash classification — Vertex AI-powered intent classification with temperature-controlled output
  • Dynamic prompt construction — agent descriptions and few-shot examples from the registry are injected verbatim into the classifier prompt
  • Exponential backoff retry — automatic retry on rate-limit errors (429, quota exceeded, resource exhausted)
  • Mock classifier fallback — keyword-matching classifier for development/testing when GCP is unavailable
  • Language detection — heuristic-based detection for 58 languages with regex pattern scoring
  • Localized clarification questions — 58-language fallback question bank for when Gemini cannot generate contextual clarifications

Quick Start

import { classifierService } from "@reaatech/agent-mesh-classifier";
import { registryState } from "@reaatech/agent-mesh-registry";

const classification = await classifierService.classify(
  "I need to reset my Okta password",
  registryState.registry!,
);

console.log(classification);
// → { agent_id: "serval", confidence: 0.92, ambiguous: false, detected_language: "en", intent_summary: "User needs password reset" }

API Reference

Classifier Service

classifierService (singleton)

The global ClassifierService instance. In production, it initializes Gemini Flash on first use. Falls back to the mock classifier if Gemini is unavailable or if NODE_ENV === "test".

import { classifierService } from "@reaatech/agent-mesh-classifier";

const result = await classifierService.classify(userInput, registry, priorLanguage?);

classifierService.classify(userInput, registry, priorLanguage?): Promise<ClassifierOutput>

Classifies a user request against the available agents. Returns a structured ClassifierOutput with agent ID, confidence score (0–1), ambiguity flag, detected language, intent summary, and entities.

classifierService.isMock(): boolean

Returns true if the classifier is currently using the mock (keyword-based) implementation.

isRateLimitError(error: unknown): boolean

Utility to check if an error is a Gemini rate-limit error. Returns true for 429, quota exceeded, and resource exhausted errors.

Prompt Builder

buildClassifierPrompt(registry, userInput, detectedLanguage?): string

Builds the full Gemini classifier prompt from the agent registry. Each agent's description, examples, and clarification context are injected into the prompt. An optional language hint is included from prior turns.

parseClassifierOutput(jsonStr: string): ClassifierOutput

Parses and validates the Gemini JSON response. Strips markdown code fences, validates required fields (agent_id, confidence, detected_language, intent_summary), and returns a typed ClassifierOutput.

Localization

detectLanguage(text: string): SupportedLanguage

Detects the language of input text using regex pattern scoring across 58 languages. Returns an ISO 639-1 language code.

import { detectLanguage } from "@reaatech/agent-mesh-classifier";

detectLanguage("¿Cómo puedo restablecer mi contraseña?"); // → "es"
detectLanguage("パスワードをリセットする方法");           // → "ja"

isValidLanguageCode(code: string): boolean

Validates that a string is one of the 58 supported language codes.

getClarificationQuestion(language: string): string

Returns a localized clarification question for a given language. Falls back to English if the language is unsupported.

import { getClarificationQuestion } from "@reaatech/agent-mesh-classifier";

getClarificationQuestion("es"); // → "¿Podría proporcionar más detalles sobre lo que necesita ayuda?"
getClarificationQuestion("en"); // → "Could you please provide more details about what you need help with?"

FALLBACK_QUESTIONS

A constant record mapping all 58 supported language codes to their localized fallback questions.

Classifier Output Shape

interface ClassifierOutput {
  agent_id: string;              // ID of the best-matching agent
  confidence: number;            // 0.0–1.0 confidence score
  ambiguous: boolean;            // Whether the request could match multiple agents
  detected_language: string;     // ISO 639-1 language code
  intent_summary: string;        // One-sentence summary
  entities: Record<string, unknown>; // Extracted key-value entities
}

Usage Patterns

Rate-Limit Handling

import { classifierService, isRateLimitError } from "@reaatech/agent-mesh-classifier";

try {
  const result = await classifierService.classify(input, registry);
} catch (error) {
  if (isRateLimitError(error)) {
    // The service internally retries with backoff, but if it exhausts retries:
    console.warn("Gemini rate-limited, using fallback");
  }
}

Language-Aware Classification

// First classification detects language
const first = await classifierService.classify("Bonjour", registry);
// first.detected_language === "fr"

// Subsequent turns pass the prior language as a hint
const second = await classifierService.classify(
  "Je voudrais réinitialiser mon mot de passe",
  registry,
  first.detected_language
);

Mock Mode for Development

import { classifierService } from "@reaatech/agent-mesh-classifier";

// When Gemini is unavailable (no GCP credentials, NODE_ENV=test, or init failure):
// The mock classifier uses keyword matching against agent examples

if (classifierService.isMock()) {
  console.log("Running in mock classifier mode");
}

Related Packages

License

MIT