Skip to content

Commit 3a83e3d

Browse files
committed
Send as much information as possible with toolCallRejected.
In order to do that, we have to store the necessary information in the tool call state, as early as possible. In general, however, the arguments to the tool call are not available until the :tool-run event, so the recepients of toolCallRejected have to be able to handle a null value of the arguments. Replaced the :init-decision-reason action by the :init-tool-call-state actions which initializes other aspects of the tool call as well. Added a :init-arguments action to initialize the arguments to the tool call when they are known during the :tool-run event. Added comments specifying that all :send-* actions should typically be last, and that the status is updated before any actions are run.
1 parent 714ef76 commit 3a83e3d

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/eca/features/chat.clj

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
- promise init & delivery
8787
- logging/metrics
8888
89-
Note: all actions are run in the order specified.
89+
Note: all actions are run in the order specified. So, generally, the :send-* actions should be last.
90+
Note: The :status is updated before any actions are run, so the actions have the latest :status.
9091
9192
Note: all choices (i.e. conditionals) have to be made in code and result
9293
in different events sent to the state machine.
@@ -95,15 +96,15 @@
9596
{;; Note: transition-tool-call! treats no existing state as :initial state
9697
[:initial :tool-prepare]
9798
{:status :preparing
98-
:actions [:send-toolCallPrepare :init-decision-reason]}
99+
:actions [:init-tool-call-state :send-toolCallPrepare]}
99100

100101
[:preparing :tool-prepare]
101102
{:status :preparing
102103
:actions [:send-toolCallPrepare]} ; Multiple prepares allowed
103104

104105
[:preparing :tool-run]
105106
{:status :check-approval
106-
:actions [:init-approval-promise :send-toolCallRun]}
107+
:actions [:init-arguments :init-approval-promise :send-toolCallRun]}
107108
;; TODO: What happens if the promise is created, but no deref happens since the call is stopped?
108109

109110
[:check-approval :approval-ask]
@@ -246,10 +247,21 @@
246247
(deliver (get-in @db* [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :approved?*])
247248
true)
248249

249-
:init-decision-reason
250-
(swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :decision-reason]
251-
{:reason {:code :none
252-
:text "No reason"}})
250+
:init-tool-call-state
251+
(swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id]
252+
{;; :status is initialized by the state transition machinery
253+
;; :approval* is initialized by the :init-approval-promise action
254+
;; :arguments is initialized by the :init-arguments action
255+
;; :start-time is initialized by the :set-start-time action
256+
:name (:name event-data)
257+
:arguments (:arguments event-data)
258+
:origin (:origin event-data)
259+
:decision-reason {:code :none
260+
:text "No reason"}})
261+
262+
:init-arguments
263+
(swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id]
264+
:arguments (:arguments event-data))
253265

254266
:set-decision-reason
255267
(swap! db* assoc-in [:chats (:chat-id chat-ctx) :tool-calls tool-call-id :decision-reason]

0 commit comments

Comments
 (0)