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-confidence

v1.0.0

Published

Confidence gate and clarification for agent-mesh routing

Readme

@reaatech/agent-mesh-confidence

npm version License: MIT CI

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

Confidence-gated routing decision engine for the agent-mesh orchestrator. Implements a 5-rule decision tree that evaluates classifier output against agent thresholds to route, ask for clarification, or fall back to the default agent. Includes an LRU clarification cache with deferred-clear semantics.

Installation

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

Feature Overview

  • 5-rule decision tree — deterministic routing logic: unknown agent → default, default agent → route, confidence ≥ threshold → route, clarification enabled → clarify, otherwise → fallback
  • Session bypass — active sessions skip the confidence gate and route directly to the session's agent
  • Clarification cache — LRU cache with TTL expiration and deferred clear (waits for in-flight requests)
  • Language-aware questions — clarification questions returned in the user's detected language
  • Metric recording — emits confidence.clarification.count counter on every clarification event

Quick Start

import { evaluateConfidenceGate } from "@reaatech/agent-mesh-confidence";

const decision = evaluateConfidenceGate(
  { agent_id: "serval", confidence: 0.55, ambiguous: false, detected_language: "en", intent_summary: "Password reset", entities: {} },
  registry,
  false, // bypassClassifier
);

console.log(decision);
// → { action: "clarify", agent_id: "serval", confidence: 0.55, clarification_question: "Could you please provide...", reason: "Below threshold 0.7, clarification required" }

API Reference

Decision Engine

evaluateConfidenceGate(classifierOutput, registry, bypassClassifier?): ConfidenceDecision

Evaluates the multi-agent routing decision tree. Returns a ConfidenceDecision with one of three actions.

Decision rules (in order):

| Rule | Condition | Action | |------|-----------|--------| | 1 | Classified agent ID is not in the registry | route to default agent | | 2 | Matched agent is the default agent | route directly (no threshold check) | | 3 | bypassClassifier is true (active session) | route to the session's agent | | 4 | confidence ≥ threshold AND !ambiguous | route to the matched agent | | 5 | clarification_required is true AND ENABLE_CLARIFICATION | clarify with a localized question | | 6 | Otherwise | fallback to the default agent |

ConfidenceDecision

interface ConfidenceDecision {
  action: "route" | "clarify" | "fallback";
  agent_id: string;
  confidence: number;
  clarification_question?: string; // Only set when action === "clarify"
  reason: string;
}

Clarification Questions

generateClarificationQuestion(agent, userInput, language): Promise<string>

Generates a contextual clarification question for a specific agent. Uses the cache to avoid redundant generation. Returns a localized fallback question.

import { generateClarificationQuestion } from "@reaatech/agent-mesh-confidence";

const question = await generateClarificationQuestion(
  servalAgent,
  "I need help with my computer",
  "en",
);
// → "Could you please provide more details about what you need help with?"

Clarification Cache

clarificationCache (singleton)

An LRU cache for clarification questions with TTL expiration and deferred-clear semantics.

import { clarificationCache } from "@reaatech/agent-mesh-confidence";

// Cache a question
clarificationCache.set("serval:en", "What specific IT issue are you having?");

// Retrieve (respects TTL)
const cached = clarificationCache.get("serval:en");

// Track in-flight requests (prevents cache clear during active requests)
clarificationCache.startRequest();
// ... process request ...
clarificationCache.endRequest();

// Clear when deferred
clarificationCache.clear();

// Inspect
const stats = clarificationCache.getStats();
// → { size: 3, pendingClear: false, activeRequests: 0 }

Routing Decision Flow

Classifier Output
        │
        ▼
┌─── Unknown agent? ──→ Route to default
│
├─── Is default? ──→ Route directly
│
├─── Session bypass? ──→ Route to session agent
│
├─── Confidence ≥ threshold && !ambiguous? ──→ Route to agent
│
├─── Clarification enabled? ──→ Generate question
│
└─── Otherwise ──→ Fallback to default

Configuration

| Variable | Default | Description | |----------|---------|-------------| | ENABLE_CLARIFICATION | true | Whether to generate clarification questions when confidence is below threshold |

Each agent also has its own confidence_threshold (0.0–1.0) and clarification_required boolean in the registry.

Usage Patterns

In the Orchestrator Pipeline

import { evaluateConfidenceGate } from "@reaatech/agent-mesh-confidence";

const classification = await classifierService.classify(input, registry);
const decision = evaluateConfidenceGate(classification, registry, false);

switch (decision.action) {
  case "route":
    return dispatchToAgent(registry.getAgent(decision.agent_id), input);
  case "clarify":
    return { clarification: decision.clarification_question, suggestedAgent: decision.agent_id };
  case "fallback":
    return dispatchToAgent(registry.defaultAgent, input);
}

Session Bypass

// Active session found — skip classification and confidence gate
const decision = evaluateConfidenceGate(
  { agent_id: session.active_agent, confidence: 1, ambiguous: false, detected_language: "en", intent_summary: "Session bypass", entities: {} },
  registry,
  true, // bypassClassifier
);
// → { action: "route", agent_id: session.active_agent, reason: "Session bypass, routing directly to session agent" }

Related Packages

License

MIT