|
297 | 297 | msg-conv/parse-messages-tool-arguments)] |
298 | 298 | (println "\n=== Session History ===") |
299 | 299 |
|
300 | | - ;; Display user and AI messages |
301 | | - (doseq [msg edn-messages] |
302 | | - (case (:type msg) |
303 | | - "USER" |
304 | | - (when-let [contents (:contents msg)] |
305 | | - (println "\n--- User ---") |
306 | | - (doseq [content contents] |
307 | | - (when (= "TEXT" (:type content)) |
308 | | - (println (:text content))))) |
309 | | - |
310 | | - "AI" |
311 | | - (when-let [text (:text msg)] |
312 | | - (when-not (str/blank? text) |
313 | | - (println "\n--- AI Response ---") |
314 | | - (println text))) |
315 | | - |
316 | | - ;; Skip SYSTEM and TOOL_EXECUTION_RESULT for now |
317 | | - nil)) |
318 | | - |
319 | | - ;; Print tool executions |
320 | | - (when-let [executions (extract-tool-executions edn-messages)] |
321 | | - (println "\n--- Tool Executions ---") |
322 | | - (print-tool-executions executions)) |
| 300 | + ;; Display messages with inline tool executions |
| 301 | + (loop [msgs edn-messages] |
| 302 | + (when (seq msgs) |
| 303 | + (let [[msg & rest-msgs] msgs] |
| 304 | + (case (:type msg) |
| 305 | + "USER" |
| 306 | + (do |
| 307 | + (when-let [contents (:contents msg)] |
| 308 | + (println "\n--- User ---") |
| 309 | + (doseq [content contents] |
| 310 | + (when (= "TEXT" (:type content)) |
| 311 | + (println (:text content))))) |
| 312 | + (recur rest-msgs)) |
| 313 | + |
| 314 | + "AI" |
| 315 | + (do |
| 316 | + ;; If this AI message has tool requests, show them first |
| 317 | + (when (seq (:toolExecutionRequests msg)) |
| 318 | + (let [requests (:toolExecutionRequests msg) |
| 319 | + results (take (count requests) rest-msgs)] |
| 320 | + (when (every? #(= "TOOL_EXECUTION_RESULT" (:type %)) results) |
| 321 | + (let [executions (mapv (fn [req res] |
| 322 | + {:type :tool-execution |
| 323 | + :request req |
| 324 | + :result res}) |
| 325 | + requests |
| 326 | + results)] |
| 327 | + (when (> (count executions) 1) |
| 328 | + (println "\nTool calls count:" (count executions))) |
| 329 | + (doseq [{:keys [request result]} executions] |
| 330 | + (println (tool-format/format-tool-request request)) |
| 331 | + (println (tool-format/format-tool-result result)) |
| 332 | + (println)))))) |
| 333 | + |
| 334 | + ;; Then show AI response text if any |
| 335 | + (when-let [text (:text msg)] |
| 336 | + (when-not (str/blank? text) |
| 337 | + (println "\n--- AI Response ---") |
| 338 | + (println text))) |
| 339 | + |
| 340 | + (recur rest-msgs)) |
| 341 | + |
| 342 | + ;; Skip SYSTEM and TOOL_EXECUTION_RESULT (already handled above) |
| 343 | + (recur rest-msgs))))) |
323 | 344 |
|
324 | 345 | (println "========================\n")) |
325 | 346 |
|
|
0 commit comments