返回 DeepSeek-Reasonix
tool_recovery_prompt.go
根目录 / internal / agent / tool_recovery_prompt.go
1 package agent
2
3 import (
4 "slices"
5
6 "reasonix/internal/provider"
7 )
8
9 func (a *Agent) SilentToolRecovery() bool {
10 r := a.transcriptInterruptedRecovery()
11 return r != nil && r.SilentInterruption
12 }
13
14 // Durable effect evidence is independent of the old, consumable prompt-tail
15 // handoff. Facts remain bounded and never include raw arguments or output.
16 func (a *Agent) pendingInterruptedRecovery() *provider.InterruptedTurnRecovery {
17 r := a.transcriptInterruptedRecovery()
18 if a == nil || a.sess.conversation == nil {
19 return r
20 }
21 seen := map[string]bool{}
22 latest := map[string]*provider.ToolCallRecord{}
23 for _, m := range a.Session().Snapshot() {
24 for _, c := range m.ToolCalls {
25 if c.Recovery != nil {
26 latest[c.ID] = c.Recovery
27 }
28 }
29 }
30 if r != nil {
31 r.UnknownTools = slices.DeleteFunc(slices.Clone(r.UnknownTools), func(c provider.InterruptedToolSummary) bool {
32 record := latest[c.ID]
33 return record != nil && record.State == provider.ToolRunUserConfirmed
34 })
35 for _, c := range r.UnknownTools {
36 seen[c.ID] = true
37 }
38 }
39 for _, record := range a.PendingToolRecovery() {
40 if seen[record.Identity.CallID] {
41 continue
42 }
43 if r == nil {
44 r = &provider.InterruptedTurnRecovery{Pending: true}
45 }
46 r.UnknownTools = append(r.UnknownTools, provider.InterruptedToolSummary{ID: record.Identity.CallID, Name: record.Identity.CanonicalTool})
47 seen[record.Identity.CallID] = true
48 }
49 for _, m := range a.Session().Snapshot() {
50 for _, c := range m.ToolCalls {
51 if c.Recovery == nil || c.Recovery.State != provider.ToolRunUserConfirmed || latest[c.ID] != c.Recovery {
52 continue
53 }
54 if r == nil {
55 r = &provider.InterruptedTurnRecovery{Pending: true}
56 }
57 r.UserConfirmedTools = append(r.UserConfirmedTools, provider.InterruptedToolSummary{ID: c.ID, Name: c.Recovery.Identity.CanonicalTool})
58 }
59 }
60 return r
61 }
62
62 lines GO