/** * Adaptive reasoning policy — SP-245, #166 (partial). * * Computes the effective `reasoning` / thinking intensity for a delegated * provider call from turn signals so chatty models stay concise on routine * tool loops and only "think hard" when planning / escalation demands it. * * Policy table (defaults): * - tool_result turns → minimal * - main_loop turns → low * - planning turns / planning_delegate → medium * - frontier escalation (tier or loop_escalation) → high * * Merge invariants: * 1. pi's ambient session default (`SESSION_AMBIENT_THINKING_LEVEL`, pi's * DEFAULT_THINKING_LEVEL = 'medium') is adjustable by policy — that is * the dogfood case (#166): the host passes the session level on every * turn and the router chooses a smart default instead of blindly passing * it through. * 2. Any other caller `reasoning` is treated as an explicit operator * `/thinking` choice and is never lowered — policy may only raise it when * the turn class upgrades. * 3. Pin continuation inherits the session level unless the turn class * upgrades above it. * 4. Policy never raises past the model-supported max (levels mapped to * `null` in `thinkingLevelMap` are unsupported; policy level clamps down). * 5. Fail open: models without reasoning support pass caller options through * unchanged; providers that ignore reasoning options degrade to a no-op. * 6. Operator knobs (SP-246): `enabled: false` skips the policy entirely; * floor/ceiling bound only policy-derived levels and never lower an * explicit operator `/thinking` choice. * * Telemetry (`reasoning_level_requested` / `reasoning_level_applied` / * `reasoning_reason_code`) is emitted by the extension delegation path (SP-246). */ import type { Api, Context, Model, ThinkingLevel } from '@earendil-works/pi-ai/compat'; import type { ModelProfile, RoutingDecision, TurnType } from '../types/index.js'; /** * pi's DEFAULT_THINKING_LEVEL — the ambient session level the host passes on * every stream call when the operator has not chosen an explicit `/thinking`. * Policy may adjust this level; any other caller level is an explicit operator * floor (never lowered). */ export declare const SESSION_AMBIENT_THINKING_LEVEL: ThinkingLevel; /** Profiles at or above this verbosity_factor are "chatty" (GLM-class). */ export declare const HIGH_VERBOSITY_FACTOR_THRESHOLD = 1.5; /** Light conciseness nudge appended to the delegated system prompt. */ export declare const CONCISENESS_SUFFIX = "Be concise: answer directly and keep narration before tool calls to a minimum."; /** Reason codes for the adaptive reasoning decision (telemetry in SP-246). */ export type AdaptiveReasoningReasonCode = 'adaptive_reasoning_disabled' | 'reasoning_unsupported' | 'no_policy_signal' | 'turn_envelope_tool_result' | 'turn_envelope_main_loop' | 'planning_turn' | 'frontier_escalation' | 'operator_thinking_floor' | 'operator_thinking_upgrade' | 'operator_floor_applied' | 'operator_ceiling_applied' | 'pin_inherit_session' | 'pin_turn_class_upgrade'; /** Turn-class signals available at route/delegation time. */ export interface AdaptiveReasoningSignal { /** Turn envelope classification from the routing request. */ readonly turnType?: TurnType | undefined; /** Routing decision for this delegation (tier / stage / reason_code). */ readonly decision?: RoutingDecision | undefined; /** Fleet profile of the delegation target (verbosity_factor). */ readonly profile?: ModelProfile | undefined; } export interface AdaptiveReasoningResult { /** * Effective reasoning level to merge into delegation stream options. * `undefined` → leave caller options untouched (fail open / no signal). */ readonly reasoning: ThinkingLevel | undefined; readonly reasonCode: AdaptiveReasoningReasonCode; /** True when a light conciseness suffix should be appended to the prompt. */ readonly concisenessHint: boolean; } /** * Operator knobs (SP-246, #166): enable/disable + optional floor/ceiling on * policy-derived levels. Floor/ceiling are discrete thinking levels — never a * free-form verbosity percent. They bind only what the policy itself derives; * an explicit operator `/thinking` choice is never lowered (and never raised * by the floor — live session choice beats static config). */ export interface AdaptiveReasoningOptions { /** When false, skip the policy: caller reasoning passes through unchanged. */ readonly enabled?: boolean; /** Floor: policy-derived levels are raised to at least this level. */ readonly floor?: ThinkingLevel; /** Ceiling: policy-derived levels are capped at this level. */ readonly ceiling?: ThinkingLevel; } export declare function rankReasoningLevel(level: ThinkingLevel): number; /** * Clamp a policy level down to the nearest supported level at or below it. * Returns undefined when the model supports no level at or below `level`. */ export declare function clampToSupportedLevel(level: ThinkingLevel, model: Model): ThinkingLevel | undefined; export type ReasoningTurnClass = 'routine' | 'planning' | 'escalation' | 'unknown'; export declare function classifyReasoningTurn(signal: AdaptiveReasoningSignal): ReasoningTurnClass; /** * Resolve the effective reasoning level for a delegated call. * * `callerReasoning` is the host-provided `options.reasoning` (pi session * thinking level). See module doc for the merge invariants. * * `options` (SP-246, #166) carries the operator enable/disable + floor/ceiling * knobs. Semantics: * - `enabled: false` → pass caller reasoning through unchanged * (`adaptive_reasoning_disabled`). * - `floor` raises policy-derived levels to at least the floor. * - `ceiling` caps policy-derived levels (including turn-class upgrades) at * the ceiling. When floor > ceiling the ceiling wins (cost-safe). * - Neither knob ever *lowers* an explicit operator `/thinking` choice. */ export declare function resolveAdaptiveReasoning(targetModel: Model, signal: AdaptiveReasoningSignal, callerReasoning?: ThinkingLevel, options?: AdaptiveReasoningOptions): AdaptiveReasoningResult; /** * Append the light conciseness suffix to the delegated system prompt when the * policy result calls for it (effective level low/minimal + high * verbosity_factor profile). Not a prompt rewrite — a single nudge line. */ export declare function applyConcisenessHint(context: Context, result: AdaptiveReasoningResult | undefined): Context; //# sourceMappingURL=adaptive-reasoning.d.ts.map