Skip to content

Commit ab525f4

Browse files
committed
Adjusted to upstream changes.
The upstream change that mostly impacted this commit is that the config was changed to allow a defaull approval of either :deny, :allow, or :ask. This impacted the way manual approvals and auto-approvals were handled. This necessitated the addition of a new action :deliver-default-approval in the state machine table. During the rebase, I didn't do a good job of properly eliminating the conflicts. So, a part of this commit is fixing the things I should have in the rebase. Removed an unneeded :manual-approve from the event-data of all :tool-prepare transitions. Added a :default-approval to the event-data of :auto-approve transitions.
1 parent 09bd02b commit ab525f4

File tree

2 files changed

+71
-58
lines changed

2 files changed

+71
-58
lines changed

src/eca/features/chat.clj

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
[:check-approval :auto-approve]
106106
{:status :execution-approved
107-
:actions [:deliver-approval-true]}
107+
:actions [:deliver-default-approval]}
108108

109109
[:waiting-approval :user-approve]
110110
{:status :execution-approved
@@ -169,8 +169,7 @@
169169
:id tool-call-id
170170
:name (:name event-data)
171171
:origin (:origin event-data)
172-
:arguments-text (:arguments-text event-data)
173-
:manual-approval (:manual-approval event-data)}
172+
:arguments-text (:arguments-text event-data)}
174173
:summary (:summary event-data)))
175174

176175
:send-toolCallRun
@@ -223,6 +222,10 @@
223222
(deliver (get-in @db* [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :approved?*])
224223
true)
225224

225+
:deliver-default-approval
226+
(deliver (get-in @db* [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :approved?*])
227+
(:default-approval event-data))
228+
226229
;; Logging/metrics actions
227230
:log-rejection
228231
(logger/info logger-tag "Tool call rejected"
@@ -410,7 +413,6 @@
410413
{:name name
411414
:origin (tool-name->origin name all-tools)
412415
:arguments-text arguments-text
413-
:manual-approval (f.tools/manual-approval? name config)
414416
:summary (f.tools/tool-call-summary all-tools name nil)}))
415417
;; TODO: Should this be :on-tool-called instead for consistency?
416418
:on-tools-called (fn [tool-calls]
@@ -425,29 +427,32 @@
425427
details (f.tools/tool-call-details-before-invocation name arguments)
426428
summary (f.tools/tool-call-summary all-tools name arguments)
427429
origin (tool-name->origin name all-tools)
428-
manual-approval? (f.tools/manual-approval? name config)]
429-
;; Inform UI the tool is about to run and store approval promise
430+
approval (f.tools/approval all-tools name arguments db config)
431+
ask? (= :ask approval)]
432+
;; Inform client the tool is about to run and store approval promise
430433
(transition-tool-call! db* chat-ctx id :tool-run
431434
{:approved?* approved?*
432435
:name name
433436
:origin (tool-name->origin name all-tools)
434437
:arguments arguments
435-
:manual-approval manual-approval?
438+
:manual-approval ask?
436439
:details details
437440
:summary summary})
438-
(if manual-approval?
441+
(if ask?
439442
(transition-tool-call! db* chat-ctx id :manual-approve
440443
{:state :running
441444
:text "Waiting for tool call approval"})
442-
(transition-tool-call! db* chat-ctx id :auto-approve))
443-
;; Execute each tool call concurrently - this should be the return value of let
445+
(transition-tool-call! db* chat-ctx id :auto-approve
446+
{:default-approval (= :allow approval)}))
447+
;; Execute each tool call concurrently
444448
(future
445449
(if @approved?* ;TODO: Should there be a timeout here? If so, what would be the state transitions?
446450
;; assert: In :execution-approved state
447451
(do
448452
(assert-chat-not-stopped! chat-ctx)
449453
(transition-tool-call! db* chat-ctx id :execution-start)
450-
(let [result (f.tools/call-tool! name arguments @db* config messenger)]
454+
(let [result (f.tools/call-tool! name arguments @db* config messenger behavior)
455+
details (f.tools/tool-call-details-after-invocation name arguments details result)]
451456
(add-to-history! {:role "tool_call" :content (assoc tool-call
452457
:details details
453458
:summary summary
@@ -467,19 +472,21 @@
467472
:details details
468473
:summary summary})))
469474
;; assert: In :rejected state
470-
(do
475+
(let [[reject-reason reject-text] (if (= :deny approval)
476+
[:user-config "Tool call denied by user config"]
477+
[:user-choice "Tool call rejected by user choice"])]
471478
(add-to-history! {:role "tool_call" :content tool-call})
472479
(add-to-history! {:role "tool_call_output"
473480
:content (assoc tool-call :output {:error true
474481
:contents [{:text reject-text
475482
:type :text}]})})
476483
(transition-tool-call! db* chat-ctx id :send-reject
477-
{:origin origin
478-
:name name
479-
:arguments arguments
480-
:reason :user
481-
:details details
482-
:summary summary})))))))]
484+
{:origin origin
485+
:name name
486+
:arguments arguments
487+
:reason reject-reason
488+
:details details
489+
:summary summary})))))))]
483490
(assert-chat-not-stopped! chat-ctx)
484491
;; Wait for all tool calls to complete before returning
485492
(run! deref calls)

0 commit comments

Comments
 (0)