1- import type { ThinkingLevel } from "@mariozechner/pi-agent-core" ;
1+ import type { ThinkingLevel as AgentThinkingLevel } from "@mariozechner/pi-agent-core" ;
2+ import type { ThinkingLevel as ProviderThinkingLevel } from "@mariozechner/pi-ai" ;
23import { z } from "zod" ;
34
45const CLASSIFIER_CONFIDENCE_THRESHOLD = 0.75 ;
56const MAX_ROUTER_CONTEXT_CHARS = 1_200 ;
7+ const TURN_REASONING_EFFORTS = [ "none" , "low" , "medium" , "high" ] as const ;
68
79const turnExecutionProfileSchema = z . object ( {
8- reasoning_effort : z . enum ( [ "none" , "low" , "medium" , "high" ] ) ,
10+ reasoning_effort : z . enum ( TURN_REASONING_EFFORTS ) ,
911 confidence : z . number ( ) . min ( 0 ) . max ( 1 ) ,
1012 reason : z . string ( ) . min ( 1 ) ,
1113} ) ;
1214
15+ type TurnReasoningEffort = ( typeof TURN_REASONING_EFFORTS ) [ number ] ;
16+
1317export interface TurnExecutionProfile {
1418 confidence ?: number ;
1519 modelId : string ;
16- reasoningEffort : "none" | "low" | "medium" | "high" ;
20+ reasoningEffort : TurnReasoningEffort ;
1721 reason : string ;
1822}
1923
@@ -31,12 +35,12 @@ function trimContextForRouter(text: string | undefined): string | undefined {
3135
3236function buildClassifierSystemPrompt ( ) : string {
3337 return [
34- "You route coding- assistant turns to the cheapest reasoning effort that is still likely to succeed." ,
38+ "You route assistant turns to the cheapest reasoning effort that is still likely to succeed." ,
3539 "Choose exactly one bucket: none, low, medium, or high." ,
3640 "" ,
3741 "Use none for greetings, acknowledgments, and trivial single-step asks." ,
3842 "Use low for straightforward explanations or simple one-step work." ,
39- "Use medium for repo investigation , multi-file analysis, ambiguous asks , or likely multi-tool work." ,
43+ "Use medium for investigations, ambiguous asks , multi-step analysis, or likely multi-tool work." ,
4044 "Use high for code changes, debugging/root-cause analysis, research-heavy work, non-trivial drafting, or explicit requests to be thorough." ,
4145 "" ,
4246 "Return JSON only with reasoning_effort, confidence, and reason." ,
@@ -49,20 +53,24 @@ function buildClassifierPrompt(args: {
4953 conversationContext ?: string ;
5054 messageText : string ;
5155} ) : string {
52- const sections = [
53- "Latest user request:" ,
54- args . messageText . trim ( ) || "[empty]" ,
55- "" ,
56- "Turn context:" ,
57- `- active_skills: ${ args . activeSkillNames . join ( ", " ) || "none" } ` ,
58- `- attachment_count: ${ args . attachmentCount } ` ,
59- ] ;
56+ const sections : string [ ] = [ ] ;
6057
6158 const context = trimContextForRouter ( args . conversationContext ) ;
6259 if ( context ) {
63- sections . push ( "" , "Recent conversation context:" , context ) ;
60+ sections . push ( "<thread-background> " , context , "</thread-background>" , "" ) ;
6461 }
6562
63+ sections . push (
64+ "<turn-context>" ,
65+ `- active_skills: ${ args . activeSkillNames . join ( ", " ) || "none" } ` ,
66+ `- attachment_count: ${ args . attachmentCount } ` ,
67+ "</turn-context>" ,
68+ "" ,
69+ '<current-instruction priority="highest">' ,
70+ args . messageText . trim ( ) || "[empty]" ,
71+ "</current-instruction>" ,
72+ ) ;
73+
6674 return sections . join ( "\n" ) ;
6775}
6876
@@ -76,7 +84,7 @@ export async function selectTurnExecutionProfile(args: {
7684 maxTokens : number ;
7785 metadata : Record < string , string > ;
7886 prompt : string ;
79- reasoningEffort ?: "minimal" | "low" | "medium" | "high" | "xhigh" ;
87+ reasoningEffort ?: ProviderThinkingLevel ;
8088 system : string ;
8189 temperature : number ;
8290 } ) => Promise < { object : unknown } > ;
@@ -144,7 +152,7 @@ export async function selectTurnExecutionProfile(args: {
144152/** Convert a routing effort bucket into the Pi Agent thinking level for a main turn. */
145153export function toAgentThinkingLevel (
146154 effort : TurnExecutionProfile [ "reasoningEffort" ] ,
147- ) : ThinkingLevel | "off" {
155+ ) : AgentThinkingLevel | "off" {
148156 switch ( effort ) {
149157 case "none" :
150158 return "off" ;
0 commit comments