| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | |
| 7 | "reasonix/internal/provider" |
| 8 | ) |
| 9 | |
| 10 | var errToolRecoveryRetired = fmt.Errorf("tool_recovery_retired: historical execution facts are read-only; invoke tools normally after checking external state") |
| 11 | |
| 12 | func (a *Agent) recoveryCall(attempt string) (provider.ToolCall, error) { |
| 13 | for _, message := range a.Session().Snapshot() { |
| 14 | for _, call := range message.ToolCalls { |
| 15 | if call.Recovery != nil && call.Recovery.Identity.AttemptID == attempt { |
| 16 | return call, nil |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | return provider.ToolCall{}, fmt.Errorf("recovery action is stale or unavailable") |
| 21 | } |
| 22 | |
| 23 | // InspectToolRecovery remains for binary compatibility. Inspection used to |
| 24 | // mutate the record and authorize a follow-up action; callers now receive the |
| 25 | // immutable historical fact and a stable retirement error. |
| 26 | func (a *Agent) InspectToolRecovery(_ context.Context, attempt string) (provider.ToolCallRecord, error) { |
| 27 | call, err := a.recoveryCall(attempt) |
| 28 | if err != nil { |
| 29 | return provider.ToolCallRecord{}, err |
| 30 | } |
| 31 | return *call.Recovery, errToolRecoveryRetired |
| 32 | } |
| 33 | |
| 34 | func (*Agent) ResolveToolRecovery(_, _, _ string) error { return errToolRecoveryRetired } |
| 35 | |
| 36 | func (*Agent) RetryToolRecovery(_ context.Context, _, _ string) error { return errToolRecoveryRetired } |
| 37 |