| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/provider" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // ToolRecoveryStatistics counts evidence retained in the current session, not |
| 9 | // a telemetry estimate or a claim about external effects. |
| 10 | type ToolRecoveryStatistics struct { |
| 11 | Unknown int `json:"unknown"` |
| 12 | Confirmed int `json:"confirmed"` |
| 13 | Retried int `json:"retried"` |
| 14 | Rejected int `json:"rejected"` |
| 15 | Blocked int `json:"blocked"` |
| 16 | } |
| 17 | |
| 18 | func (a *Agent) ToolRecoveryStatistics() ToolRecoveryStatistics { |
| 19 | var stats ToolRecoveryStatistics |
| 20 | seen := map[string]bool{} |
| 21 | for _, m := range a.Session().Snapshot() { |
| 22 | if m.Role == provider.RoleTool && strings.HasPrefix(m.Content, "blocked: recovery_required:") { |
| 23 | stats.Blocked++ |
| 24 | } |
| 25 | for _, c := range m.ToolCalls { |
| 26 | r := c.Recovery |
| 27 | if r == nil || seen[r.Identity.AttemptID] { |
| 28 | continue |
| 29 | } |
| 30 | seen[r.Identity.AttemptID] = true |
| 31 | if unresolvedToolRecord(*r) { |
| 32 | stats.Unknown++ |
| 33 | } |
| 34 | if r.State == provider.ToolRunUserConfirmed { |
| 35 | stats.Confirmed++ |
| 36 | } |
| 37 | if r.SupersededBy != "" { |
| 38 | stats.Retried++ |
| 39 | } |
| 40 | if r.Resolution == "reject" { |
| 41 | stats.Rejected++ |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | return stats |
| 46 | } |
| 47 |