about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-04-12 03:51:54 +0100
committerArun Isaac2026-04-12 03:51:54 +0100
commitf1224eed4ab9676fbfb50392cda7f14669586dcf (patch)
treea94cfcbf6756fc1541ce7d987a72daa3958bac28
parentf94644bcfaa76ac73ba7e7ff58890089fdbc7c0d (diff)
downloadkaagum-f1224eed4ab9676fbfb50392cda7f14669586dcf.tar.gz
kaagum-f1224eed4ab9676fbfb50392cda7f14669586dcf.tar.lz
kaagum-f1224eed4ab9676fbfb50392cda7f14669586dcf.zip
Strip message fields based on role.
-rw-r--r--kaakaa/tea.scm23
1 files changed, 15 insertions, 8 deletions
diff --git a/kaakaa/tea.scm b/kaakaa/tea.scm
index 05881f3..3986340 100644
--- a/kaakaa/tea.scm
+++ b/kaakaa/tea.scm
@@ -141,14 +141,21 @@ in @var{state}."
       ;; progress; dispatch to LLM.
       (list (llm-request session-id
                          (map (lambda (message)
-                                ;; Strip out all fields (such as reasoning
-                                ;; fields) other than role, content and
-                                ;; tool_calls.
-                                (filter (match-lambda
-                                          ((key . _)
-                                           (member key (list "role" "content"
-                                                             "tool_calls"))))
-                                        message))
+                                ;; Strip unnecessary fields (such as reasoning
+                                ;; fields) based on role.
+                                (let* ((role (focus (key-ref "role") message))
+                                       (allowed-fields
+                                        (cond
+                                         ((string=? role "user")
+                                          '("role" "content"))
+                                         ((string=? role "assistant")
+                                          '("role" "content" "tool_calls"))
+                                         ((string=? role "tool")
+                                          '("role" "content" "tool_call_id")))))
+                                  (filter (match-lambda
+                                            ((key . _)
+                                             (member key allowed-fields)))
+                                          message)))
                               ;; Reverse because we have been prepending new
                               ;; messages onto the list.
                               (reverse (focus (state-messages session-id)