|
91 | 91 | Note: all choices (i.e. conditionals) have to be made in code and result |
92 | 92 | in different events sent to the state machine. |
93 | 93 | For example, from the :check-approval state you can either get |
94 | | - a :config-ask event, a :config-allow event, or a :config-deny event." |
| 94 | + a :approval-ask event, a :approval-allow event, or a :approval-deny event." |
95 | 95 | {;; Note: transition-tool-call! treats no existing state as :initial state |
96 | 96 | [:initial :tool-prepare] |
97 | 97 | {:status :preparing |
|
106 | 106 | :actions [:init-approval-promise :send-toolCallRun]} |
107 | 107 | ;; TODO: What happens if the promise is created, but no deref happens since the call is stopped? |
108 | 108 |
|
109 | | - [:check-approval :config-ask] |
| 109 | + [:check-approval :approval-ask] |
110 | 110 | {:status :waiting-approval |
111 | 111 | :actions [:send-progress]} |
112 | 112 |
|
113 | | - [:check-approval :config-allow] |
| 113 | + [:check-approval :approval-allow] |
114 | 114 | {:status :execution-approved |
115 | 115 | :actions [:set-decision-reason :deliver-approval-true]} |
116 | 116 |
|
117 | | - [:check-approval :config-deny] |
| 117 | + [:check-approval :approval-deny] |
118 | 118 | {:status :rejected |
119 | 119 | :actions [:set-decision-reason :deliver-approval-false]} |
120 | 120 |
|
|
132 | 132 |
|
133 | 133 | [:execution-approved :execution-start] |
134 | 134 | {:status :executing |
135 | | - :actions []} |
| 135 | + :actions [:send-toolCallRunning]} |
136 | 136 |
|
137 | 137 | [:executing :execution-end] |
138 | 138 | {:status :completed |
|
196 | 196 | :details (:details event-data) |
197 | 197 | :summary (:summary event-data))) |
198 | 198 |
|
| 199 | + :send-toolCallRunning |
| 200 | + (send-content! chat-ctx :assistant |
| 201 | + (assoc-some |
| 202 | + {:type :toolCallRunning |
| 203 | + :id tool-call-id |
| 204 | + :name (:name event-data) |
| 205 | + :origin (:origin event-data) |
| 206 | + :arguments (:arguments event-data)} |
| 207 | + :details (:details event-data) |
| 208 | + :summary (:summary event-data))) |
| 209 | + |
199 | 210 | :send-toolCalled |
200 | 211 | (send-content! chat-ctx :assistant |
201 | 212 | (assoc-some |
|
462 | 473 | ;; assert: In: :check-approval or :stopped |
463 | 474 | (when-not (#{:stopped} (:status (get-tool-call-state @db* chat-id id))) |
464 | 475 | (case approval |
465 | | - :ask (transition-tool-call! db* chat-ctx id :config-ask |
| 476 | + :ask (transition-tool-call! db* chat-ctx id :approval-ask |
466 | 477 | {:state :running |
467 | 478 | :text "Waiting for tool call approval"}) |
468 | | - :allow (transition-tool-call! db* chat-ctx id :config-allow |
| 479 | + :allow (transition-tool-call! db* chat-ctx id :approval-allow |
469 | 480 | {:reason {:code :user-config-allow |
470 | 481 | :text "Tool call allowed by user config"}}) |
471 | | - :deny (transition-tool-call! db* chat-ctx id :config-deny |
| 482 | + :deny (transition-tool-call! db* chat-ctx id :approval-deny |
472 | 483 | {:reason {:code :user-config-deny |
473 | 484 | :text "Tool call denied by user config"}}) |
474 | 485 | (logger/warn logger-tag "Unknown value of approval in config" |
|
479 | 490 | ;; assert: In :execution-approved or :stopped |
480 | 491 | (when-not (#{:stopped} (:status (get-tool-call-state @db* chat-id id))) |
481 | 492 | (assert-chat-not-stopped! chat-ctx) |
482 | | - (transition-tool-call! db* chat-ctx id :execution-start) |
| 493 | + (transition-tool-call! db* chat-ctx id :execution-start |
| 494 | + {:origin origin |
| 495 | + :name name |
| 496 | + :arguments arguments |
| 497 | + :details details |
| 498 | + :summary summary}) |
483 | 499 | ;; assert: In :executing |
484 | 500 | (let [result (f.tools/call-tool! name arguments @db* config messenger behavior) |
485 | 501 | details (f.tools/tool-call-details-after-invocation name arguments details result)] |
|
0 commit comments