newestToolIndex returns the index of the newest tool-result message in history, or -1. Everything after it can only be non-tool (a system nudge, an assistant summary), so it marks the current turn's newest tool exchange.
(history []Message)
| 285 | // newestToolIndex returns the index of the newest tool-result message in |
| 286 | // history, or -1. Everything after it can only be non-tool (a system nudge, an |
| 287 | // assistant summary), so it marks the current turn's newest tool exchange. |
| 288 | func newestToolIndex(history []Message) int { |
| 289 | for i := len(history) - 1; i >= 0; i-- { |
| 290 | if history[i].Role == RoleTool { |
| 291 | return i |
| 292 | } |
| 293 | } |
| 294 | return -1 |
| 295 | } |
| 296 | |
| 297 | // onlyNonSubstantive reports whether kept carries no substantive conversation: |