File size: 1,255 Bytes
95eb75a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// S515 — estratto da agentLoop.ts: fast-exit check iter===0 per risposte dirette
// S432-FIX2/FIX2b: evita il gauntlet retry per query semplici → risposta in <2s su iPhone.

import type { AgentStep } from "../storage";

export interface FastExitParams {
  iter:           number;
  steps:          AgentStep[];
  isCodeTask:     boolean;
  finalText:      string;
  isDirectAnswer: boolean;
}

/**
 * Verifica se la risposta soddisfa i criteri di fast-exit (iter 0, risposta diretta).
 * Restituisce `shouldReturn: true` se il caller deve emettere la risposta e fare `return`.
 *
 * - FIX2:  iter===0, nessun tool chiamato, query non-code, risposta ≥30 chars
 * - FIX2b: iter===0, isDirectAnswer===true, query non-code, risposta ≥20 chars
 */
export function checkFastExit(p: FastExitParams): { shouldReturn: boolean } {
  // S432-FIX2: iter 0, nessun tool, query non-code
  if (p.iter === 0 && p.steps.length === 0 && !p.isCodeTask && p.finalText.length >= 30) {
    return { shouldReturn: true };
  }
  // S432-FIX2b: isDirectAnswer=true, iter 0, query non-code (soglia più bassa)
  if (p.iter === 0 && p.isDirectAnswer && !p.isCodeTask && p.finalText.length >= 20) {
    return { shouldReturn: true };
  }
  return { shouldReturn: false };
}