|
132 | 132 |
|
133 | 133 | [:execution-approved :execution-start] |
134 | 134 | {:status :executing |
135 | | - :actions [:send-toolCallRunning]} |
| 135 | + :actions [:set-start-time :send-toolCallRunning]} |
136 | 136 |
|
137 | 137 | [:executing :execution-end] |
138 | 138 | {:status :completed |
|
216 | 216 | :name (:name event-data) |
217 | 217 | :arguments (:arguments event-data) |
218 | 218 | :error (:error event-data) |
| 219 | + :total-time-ms (:total-time-ms event-data) |
219 | 220 | :outputs (:outputs event-data)} |
220 | 221 | :details (:details event-data) |
221 | 222 | :summary (:summary event-data))) |
|
254 | 255 | (swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :decision-reason] |
255 | 256 | (:reason event-data)) |
256 | 257 |
|
| 258 | + :set-start-time |
| 259 | + (swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :start-time] |
| 260 | + (:start-time event-data)) |
| 261 | + |
257 | 262 | ;; Logging actions |
258 | 263 | :log-rejection |
259 | 264 | (logger/info logger-tag "Tool call rejected" |
|
379 | 384 | past-messages (get-in db [:chats chat-id :messages] []) |
380 | 385 | all-tools (f.tools/all-tools behavior @db* config) |
381 | 386 | received-msgs* (atom "") |
382 | | - received-thinking* (atom "") |
| 387 | + reasonings* (atom {}) |
383 | 388 | add-to-history! (fn [msg] |
384 | 389 | (swap! db* update-in [:chats chat-id :messages] (fnil conj []) msg))] |
385 | 390 | (when-let [expires-at (get-in db [:auth provider :expires-at])] |
|
494 | 499 | {:origin origin |
495 | 500 | :name name |
496 | 501 | :arguments arguments |
| 502 | + :start-time (System/currentTimeMillis) |
497 | 503 | :details details |
498 | 504 | :summary summary}) |
499 | 505 | ;; assert: In :executing |
500 | 506 | (let [result (f.tools/call-tool! name arguments @db* config messenger behavior) |
501 | | - details (f.tools/tool-call-details-after-invocation name arguments details result)] |
| 507 | + details (f.tools/tool-call-details-after-invocation name arguments details result) |
| 508 | + {:keys [start-time]} (get-tool-call-state @db* chat-id id)] |
502 | 509 | (add-to-history! {:role "tool_call" :content (assoc tool-call |
503 | 510 | :details details |
504 | 511 | :summary summary |
|
515 | 522 | :arguments arguments |
516 | 523 | :error (:error result) |
517 | 524 | :outputs (:contents result) |
| 525 | + :total-time-ms (- (System/currentTimeMillis) start-time) |
518 | 526 | :details details |
519 | 527 | :summary summary}))) |
520 | 528 | ;; assert: In :rejected state |
|
540 | 548 | :on-reason (fn [{:keys [status id text external-id]}] |
541 | 549 | (assert-chat-not-stopped! chat-ctx) |
542 | 550 | (case status |
543 | | - :started (send-content! chat-ctx :assistant |
544 | | - {:type :reasonStarted |
545 | | - :id id}) |
| 551 | + :started (do |
| 552 | + (swap! reasonings* assoc-in [id :start-time] (System/currentTimeMillis)) |
| 553 | + (send-content! chat-ctx :assistant |
| 554 | + {:type :reasonStarted |
| 555 | + :id id})) |
546 | 556 | :thinking (do |
547 | | - (swap! received-thinking* str text) |
| 557 | + (swap! reasonings* update-in [id :text] str text) |
548 | 558 | (send-content! chat-ctx :assistant |
549 | 559 | {:type :reasonText |
550 | 560 | :id id |
551 | 561 | :text text})) |
552 | 562 | :finished (do |
553 | 563 | (add-to-history! {:role "reason" :content {:id id |
554 | 564 | :external-id external-id |
555 | | - :text @received-thinking*}}) |
| 565 | + :text (get-in @reasonings* [id :text])}}) |
556 | 566 | (send-content! chat-ctx :assistant |
557 | 567 | {:type :reasonFinished |
| 568 | + :total-time-ms (- (System/currentTimeMillis) (get-in @reasonings* [id :start-time])) |
558 | 569 | :id id})) |
559 | 570 | nil)) |
560 | 571 | :on-error (fn [{:keys [message exception]}] |
|
0 commit comments