Skip to content

Commit 433f6e6

Browse files
committed
Improve assert chat not finished
1 parent b6b58a5 commit 433f6e6

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/eca/features/chat.clj

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,30 @@
214214
;; Execute each tool call concurrently
215215
(future
216216
(if @approved?*
217-
(let [result (f.tools/call-tool! name arguments @db* config messenger)]
217+
(do
218218
(assert-chat-not-stopped! chat-ctx)
219-
(add-to-history! {:role "tool_call" :content (assoc tool-call
220-
:details details
221-
:summary summary
222-
:origin origin)})
223-
(add-to-history! {:role "tool_call_output" :content (assoc tool-call
224-
:error (:error result)
225-
:output result
226-
:details details
227-
:summary summary
228-
:origin origin)})
229-
(send-content! chat-ctx :assistant
230-
(assoc-some
231-
{:type :toolCalled
232-
:origin origin
233-
:name name
234-
:arguments arguments
235-
:error (:error result)
236-
:id id
237-
:outputs (:contents result)}
238-
:details details
239-
:summary summary)))
219+
(let [result (f.tools/call-tool! name arguments @db* config messenger)]
220+
(add-to-history! {:role "tool_call" :content (assoc tool-call
221+
:details details
222+
:summary summary
223+
:origin origin)})
224+
(add-to-history! {:role "tool_call_output" :content (assoc tool-call
225+
:error (:error result)
226+
:output result
227+
:details details
228+
:summary summary
229+
:origin origin)})
230+
(send-content! chat-ctx :assistant
231+
(assoc-some
232+
{:type :toolCalled
233+
:origin origin
234+
:name name
235+
:arguments arguments
236+
:error (:error result)
237+
:id id
238+
:outputs (:contents result)}
239+
:details details
240+
:summary summary))))
240241
(do
241242
(add-to-history! {:role "tool_call" :content tool-call})
242243
(add-to-history! {:role "tool_call_output"
@@ -253,6 +254,7 @@
253254
:id id}
254255
:details details
255256
:summary summary))))))))]
257+
(assert-chat-not-stopped! chat-ctx)
256258
;; Wait all tool calls to complete before returning
257259
(run! deref calls)
258260
(send-content! chat-ctx :system {:type :progress :state :running :text "Generating"})

0 commit comments

Comments
 (0)