/** * Route Classifier — Short-Circuit Routing for Network-AI * * Classifies an incoming goal into one of three categories before any * DAG planning occurs. Simple factual lookups are routed directly to a * single agent, bypassing the Blackboard/locking layer entirely to save * latency and token cost. Complex synthesis uses the full DAG pipeline. * System failures are surfaced immediately. * * Zero external dependencies — the classifier function is pluggable so * callers can use any model (Haiku, Llama-3-8B, rule-based heuristic, …). * * @module RouteClassifier * @version 1.0.0 */ /** The three routing categories. */ export type RouteCategory = 'FACTUAL_LOOKUP' | 'COMPLEX_SYNTHESIS' | 'SYSTEM_FAILURE'; /** Result produced by the classifier. */ export interface ClassificationResult { /** The routing decision. */ category: RouteCategory; /** Human-readable explanation from the classifier. */ rationale: string; /** Confidence score 0–1 (optional — classifiers may omit this). */ confidence?: number; /** When classification completed (epoch ms). */ classifiedAt: number; } /** * A function that classifies a goal string. * * Implement this with a fast model call, a rule-based heuristic, or a * combination. Must resolve — never reject — returning SYSTEM_FAILURE * instead of throwing when the input is unclassifiable. */ export type ClassifierFunction = (goal: string) => Promise; /** * Result of a routed execution attempt (FACTUAL_LOOKUP path). * For COMPLEX_SYNTHESIS the caller handles execution via the normal DAG pipeline. */ export interface RouteResult { /** The classification that drove this route. */ classification: ClassificationResult; /** True when the request was short-circuited (FACTUAL_LOOKUP). */ shortCircuited: boolean; /** Agent output for the short-circuit path, undefined otherwise. */ answer?: unknown; /** Error message for SYSTEM_FAILURE. */ error?: string; } /** Options for {@link RouteClassifier}. */ export interface RouteClassifierOptions { /** * Agent ID to call for FACTUAL_LOOKUP responses. * Required when `executor` is provided. */ lookupAgentId?: string; } /** * A simple keyword / length heuristic classifier for when you don't want to * spend tokens on a model call for every request. * * Treats goals of ≤ 15 words with question-like phrasing as FACTUAL_LOOKUP * and everything else as COMPLEX_SYNTHESIS. */ export declare function createHeuristicClassifier(): ClassifierFunction; /** * Build a classifier backed by an LLM via the Network-AI executor API. * * @param executor - The executor function from the adapter system * @param classifierAgentId - Agent ID for the fast classification model */ export declare function createLLMClassifier(executor: (agentId: string, payload: { action: string; params: Record; }, context: { agentId: string; taskId: string; metadata?: Record; }) => Promise<{ success: boolean; data?: unknown; error?: { message: string; }; }>, classifierAgentId: string): ClassifierFunction; /** * RouteClassifier evaluates a goal before DAG planning begins and decides * whether to short-circuit to a single agent (FACTUAL_LOOKUP) or proceed * with the full multi-agent pipeline (COMPLEX_SYNTHESIS). * * @example * ```typescript * const classifier = new RouteClassifier(createHeuristicClassifier()); * const { category } = await classifier.classify('What is the capital of France?'); * // category === 'FACTUAL_LOOKUP' * ``` */ export declare class RouteClassifier { private classifierFn; private options; constructor(classifierFn: ClassifierFunction, options?: RouteClassifierOptions); /** * Classify a goal. */ classify(goal: string): Promise; /** * Classify a goal and, if FACTUAL_LOOKUP, short-circuit to a single agent. * * Returns the classification result and, when short-circuited, the agent's * direct answer. The caller should check `result.shortCircuited` — if false, * proceed with the normal DAG pipeline. * * @param goal - Natural language goal * @param executor - Agent executor (required for FACTUAL_LOOKUP short-circuit) * @param fallbackAgentId - Agent to call on FACTUAL_LOOKUP (overrides options.lookupAgentId) */ route(goal: string, executor?: (agentId: string, payload: { action: string; params: Record; }, context: { agentId: string; taskId: string; metadata?: Record; }) => Promise<{ success: boolean; data?: unknown; error?: { message: string; }; }>, fallbackAgentId?: string): Promise; } //# sourceMappingURL=route-classifier.d.ts.map