| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | // PauseClass names the guard that deliberately ended a run, so a host can |
| 10 | // classify an outcome without reaching into the unexported pause types. |
| 11 | // Empty for ordinary provider/tool failures. |
| 12 | func PauseClass(err error) string { |
| 13 | var maxSteps *maxStepsPause |
| 14 | if errors.As(err, &maxSteps) { |
| 15 | return "max_steps" |
| 16 | } |
| 17 | var stall *todoStallPause |
| 18 | if errors.As(err, &stall) { |
| 19 | return "todo_stall" |
| 20 | } |
| 21 | var readiness *FinalReadinessError |
| 22 | if errors.As(err, &readiness) { |
| 23 | return "final_readiness" |
| 24 | } |
| 25 | var recovery *RecoveryPauseError |
| 26 | if errors.As(err, &recovery) { |
| 27 | return "recovery_paused" |
| 28 | } |
| 29 | return "" |
| 30 | } |
| 31 | |
| 32 | // FinalReadinessError reports that the model exhausted its recovery attempts |
| 33 | // before satisfying the host-observed delivery checks. |
| 34 | type FinalReadinessError struct { |
| 35 | Attempts int |
| 36 | Reason string |
| 37 | Missing []string |
| 38 | } |
| 39 | |
| 40 | func (e *FinalReadinessError) Error() string { |
| 41 | if e == nil { |
| 42 | return "final-answer readiness failed" |
| 43 | } |
| 44 | return fmt.Sprintf("final-answer readiness failed %d times: %s", e.Attempts, e.Reason) |
| 45 | } |
| 46 | |
| 47 | // RecoveryPauseError reports that Auto recovery exhausted its Episode budget |
| 48 | // and the model either summarized or continued calling tools after the one-shot |
| 49 | // finalization round. It is a control-flow signal, not a provider failure: |
| 50 | // completed work is kept and the user can continue in the next message. |
| 51 | type RecoveryPauseError struct { |
| 52 | // Message is the user-facing English product copy for wire/CLI clients. |
| 53 | Message string |
| 54 | // StopReason is an internal classifier; never show it as product copy. |
| 55 | StopReason string |
| 56 | // Detail is optional expandable diagnostic text (last error / counts). |
| 57 | Detail string |
| 58 | } |
| 59 | |
| 60 | func (e *RecoveryPauseError) Error() string { |
| 61 | if e == nil { |
| 62 | return "automatic retries paused" |
| 63 | } |
| 64 | if strings.TrimSpace(e.Message) != "" { |
| 65 | return e.Message |
| 66 | } |
| 67 | return "Automatic retries paused. Reasonix stopped repeated attempts and kept completed work. Send \"continue\" to start a fresh attempt, or add instructions to change direction." |
| 68 | } |
| 69 |