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 | } |
| 286 | group := []Message{history[owner]} |
| 287 | for i := owner + 1; i < len(history); i++ { |
| 288 | if history[i].Role == RoleTool && ids[history[i].ToolCallID] { |
| 289 | group = append(group, history[i]) |
| 290 | } |
| 291 | } |
| 292 | return group |
| 293 | } |
| 294 | |
| 295 | // newestToolIndex returns the index of the newest tool-result message in |
| 296 | // history, or -1. Everything after it can only be non-tool (a system nudge, an |
| 297 | // assistant summary), so it marks the current turn's newest tool exchange. |