| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/sha256" |
| 6 | |
| 7 | "reasonix/internal/provider" |
| 8 | "reasonix/internal/tool" |
| 9 | ) |
| 10 | |
| 11 | // readDelivery contains no source text. References always name an original |
| 12 | // delivery, never another reference. Both maps are owned by the run loop. |
| 13 | type readDelivery struct { |
| 14 | digest [32]byte |
| 15 | } |
| 16 | |
| 17 | // freezeVisibleReads is called for the exact request used by a sampling |
| 18 | // attempt, after projection, interception and admission. Missing or rewritten |
| 19 | // original text makes a reference ineligible, even if RawContent is retained. |
| 20 | func (a *Agent) freezeVisibleReads(messages []provider.Message) { |
| 21 | visible := make(map[string]readDelivery) |
| 22 | for _, msg := range messages { |
| 23 | if msg.Role != provider.RoleTool || msg.LocalOnly { |
| 24 | continue |
| 25 | } |
| 26 | if d, ok := a.reads.deliveries[msg.ToolCallID]; ok && sha256.Sum256([]byte(msg.Content)) == d.digest { |
| 27 | visible[msg.ToolCallID] = d |
| 28 | } |
| 29 | } |
| 30 | a.reads.visible = visible |
| 31 | } |
| 32 | |
| 33 | func (a *Agent) finalizedReadEnvelope(ctx context.Context, call provider.ToolCall, o toolOutcome) (tool.ReadResultEnvelope, bool) { |
| 34 | return a.readResultEnvelopeFor(ctx, call, o) |
| 35 | } |
| 36 |