Skip to content

Commit 71d4102

Browse files
committed
using :delta-reasoning? instead od :reasoning-content
1 parent 5509a54 commit 71d4102

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

src/eca/features/chat.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@
11421142
(add-to-history! {:role "reason"
11431143
:content {:id id
11441144
:external-id external-id
1145-
:reasoning-content reasoning-content
1145+
:delta-reasoning? (some? reasoning-content)
11461146
:total-time-ms total-time-ms
11471147
:text (get-in @reasonings* [id :text])}})
11481148
(send-content! chat-ctx :assistant {:type :reasonFinished :total-time-ms total-time-ms :id id})))

src/eca/llm_providers/openai_chat.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@
153153
:content (llm-util/stringfy-tool-result content)}
154154
"user" {:role "user"
155155
:content (extract-content content supports-image?)}
156-
"reason" (if-let [reasoning-content (:reasoning-content content)]
156+
"reason" (if (:delta-reasoning? content)
157157
;; DeepSeek-style: reasoning_content must be passed back to API
158158
{:role "assistant"
159-
:reasoning_content reasoning-content}
159+
:reasoning_content (:text content)}
160160
;; Fallback: wrap in thinking tags for models that use text-based reasoning
161161
{:role "assistant"
162162
:content [{:type "text"
@@ -323,14 +323,14 @@
323323

324324
(defn ^:private prune-history
325325
"Ensure DeepSeek-style reasoning_content is discarded from history but kept for the active turn.
326-
Only drops 'reason' messages WITH :reasoning-content before the last user message.
327-
Think-tag based reasoning (without :reasoning-content) is preserved and transformed to assistant messages."
326+
Only drops 'reason' messages WITH :delta-reasoning? before the last user message.
327+
Think-tag based reasoning (without :delta-reasoning?) is preserved and transformed to assistant messages."
328328
[messages]
329329
(if-let [last-user-idx (llm-util/find-last-user-msg-idx messages)]
330330
(->> messages
331331
(keep-indexed (fn [i m]
332332
(when-not (and (= "reason" (:role m))
333-
(get-in m [:content :reasoning-content])
333+
(get-in m [:content :delta-reasoning?])
334334
(< i last-user-idx))
335335
m)))
336336
vec)

test/eca/llm_providers/openai_chat_test.clj

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
thinking-start-tag
118118
thinking-end-tag))))
119119

120-
(testing "Reason messages - use reasoning_content if present, otherwise tags"
121-
;; Without :reasoning-content, uses think tags
120+
(testing "Reason messages - use reasoning_content if :delta-reasoning?, otherwise tags"
121+
;; Without :delta-reasoning?, uses think tags
122122
(is (match?
123123
{:role "assistant"
124124
:content [{:type "text" :text "<think>Reasoning...</think>"}]}
@@ -128,14 +128,14 @@
128128
true
129129
thinking-start-tag
130130
thinking-end-tag)))
131-
;; With :reasoning-content, uses reasoning_content field
131+
;; With :delta-reasoning?, uses reasoning_content field with :text value
132132
(is (match?
133133
{:role "assistant"
134-
:reasoning_content "opaque"}
134+
:reasoning_content "Reasoning..."}
135135
(#'llm-providers.openai-chat/transform-message
136136
{:role "reason"
137137
:content {:text "Reasoning..."
138-
:reasoning-content "opaque"}}
138+
:delta-reasoning? true}}
139139
true
140140
thinking-start-tag
141141
thinking-end-tag))))
@@ -193,22 +193,22 @@
193193
{:role "assistant" :reasoning_content "Thinking..."}])))))
194194

195195
(deftest prune-history-test
196-
(testing "Drops reason messages WITH reasoning-content before the last user message (DeepSeek)"
196+
(testing "Drops reason messages WITH :delta-reasoning? before the last user message (DeepSeek)"
197197
(is (match?
198198
[{:role "user" :content "Q1"}
199199
{:role "assistant" :content "A1"}
200200
{:role "user" :content "Q2"}
201-
{:role "reason" :content {:text "r2" :reasoning-content "e2"}}
201+
{:role "reason" :content {:text "r2" :delta-reasoning? true}}
202202
{:role "assistant" :content "A2"}]
203203
(#'llm-providers.openai-chat/prune-history
204204
[{:role "user" :content "Q1"}
205-
{:role "reason" :content {:text "r1" :reasoning-content "e1"}}
205+
{:role "reason" :content {:text "r1" :delta-reasoning? true}}
206206
{:role "assistant" :content "A1"}
207207
{:role "user" :content "Q2"}
208-
{:role "reason" :content {:text "r2" :reasoning-content "e2"}}
208+
{:role "reason" :content {:text "r2" :delta-reasoning? true}}
209209
{:role "assistant" :content "A2"}]))))
210210

211-
(testing "Preserves reason messages WITHOUT reasoning-content (think-tag based)"
211+
(testing "Preserves reason messages WITHOUT :delta-reasoning? (think-tag based)"
212212
(is (match?
213213
[{:role "user" :content "Q1"}
214214
{:role "reason" :content {:text "thinking..."}}
@@ -249,12 +249,12 @@
249249
(deftest external-id-test
250250
(testing "Tool call with external-id is preserved"
251251
(is (match?
252-
{:type :tool-call
253-
:data {:id "call-123"
254-
:type "function"
255-
:function {:name "eca__get_weather"
256-
:arguments "{\"location\":\"Paris\"}"}
257-
:extra_content {:google {:thought_signature "signature-abc-123"}}}}
252+
{:role "assistant"
253+
:tool_calls [{:id "call-123"
254+
:type "function"
255+
:function {:name "eca__get_weather"
256+
:arguments "{\"location\":\"Paris\"}"}
257+
:extra_content {:google {:thought_signature "signature-abc-123"}}}]}
258258
(#'llm-providers.openai-chat/transform-message
259259
{:role "tool_call"
260260
:content {:id "call-123"
@@ -373,15 +373,17 @@
373373
(is (not @on-reason-called?) "on-reason should not be called when :id is nil"))))
374374

375375
(deftest deepseek-non-stream-reasoning-content-test
376-
(testing "response-body->result captures reasoning_content and normalization preserves it"
376+
(testing "response-body->result captures reasoning_content and normalization uses :text with :delta-reasoning?"
377377
(let [body {:usage {:prompt_tokens 5 :completion_tokens 2}
378378
:choices [{:message {:content "hi"
379379
:reasoning_content "think more"}}]}
380380
result (#'llm-providers.openai-chat/response-body->result body (fn [& _]))
381+
;; Simulate how chat.clj would store this: :text has the content, :delta-reasoning? is the flag
381382
normalized (#'llm-providers.openai-chat/normalize-messages
382383
[{:role "user" :content "Q"}
383384
{:role "reason" :content {:id "r1"
384-
:reasoning-content (:reasoning-content result)}}]
385+
:text (:reasoning-content result)
386+
:delta-reasoning? true}}]
385387
true
386388
thinking-start-tag
387389
thinking-end-tag)]

0 commit comments

Comments
 (0)