Skip to content

Commit 0e54554

Browse files
committed
Add toolCallRunning content to chat/contentReceived.
1 parent 5ebb8a1 commit 0e54554

File tree

4 files changed

+104
-52
lines changed

4 files changed

+104
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add nix flake build.
66
- Stop prompt does not change the status of the last running toolCall. #65
7+
- Add `toolCallRunning` content to `chat/contentReceived`.
78

89
## 0.47.0
910

docs/protocol.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ type ChatContent =
393393
| ReasonFinishedContent
394394
| ToolCallPrepareContent
395395
| ToolCallRunContent
396+
| ToolCallRunningContent
396397
| ToolCalledContent
397398
| ToolCallRejectedContent;
398399

@@ -561,7 +562,7 @@ interface ToolCallPrepareContent {
561562
}
562563

563564
/**
564-
* Tool call final request that LLM may trigger, sent once per id.
565+
* Tool call that LLM will run, sent once per id.
565566
*/
566567
interface ToolCallRunContent {
567568
type: 'toolCallRun';
@@ -601,6 +602,42 @@ interface ToolCallRunContent {
601602
details?: ToolCallDetails;
602603
}
603604

605+
/**
606+
* Tool call that server is running to report to LLM later, sent once per id.
607+
*/
608+
interface ToolCallRunningContent {
609+
type: 'toolCallRunning';
610+
611+
origin: ToolCallOrigin;
612+
613+
/**
614+
* id of the tool call
615+
*/
616+
id: string;
617+
618+
/**
619+
* Name of the tool
620+
*/
621+
name: string;
622+
623+
/*
624+
* Arguments of this tool call
625+
*/
626+
arguments: {[key: string]: string};
627+
628+
/**
629+
* Summary text to present about this tool call,
630+
* ex: 'Reading file "foo"...'.
631+
*/
632+
summary?: string;
633+
634+
/**
635+
* Extra details about this call.
636+
* Clients may use this to present different UX for this tool call.
637+
*/
638+
details?: ToolCallDetails;
639+
}
640+
604641
/**
605642
* Tool call result that LLM trigerred and was executed already, sent once per id.
606643
*/

src/eca/features/chat.clj

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
Note: all choices (i.e. conditionals) have to be made in code and result
9292
in different events sent to the state machine.
9393
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."
9595
{;; Note: transition-tool-call! treats no existing state as :initial state
9696
[:initial :tool-prepare]
9797
{:status :preparing
@@ -106,15 +106,15 @@
106106
:actions [:init-approval-promise :send-toolCallRun]}
107107
;; TODO: What happens if the promise is created, but no deref happens since the call is stopped?
108108

109-
[:check-approval :config-ask]
109+
[:check-approval :approval-ask]
110110
{:status :waiting-approval
111111
:actions [:send-progress]}
112112

113-
[:check-approval :config-allow]
113+
[:check-approval :approval-allow]
114114
{:status :execution-approved
115115
:actions [:set-decision-reason :deliver-approval-true]}
116116

117-
[:check-approval :config-deny]
117+
[:check-approval :approval-deny]
118118
{:status :rejected
119119
:actions [:set-decision-reason :deliver-approval-false]}
120120

@@ -132,7 +132,7 @@
132132

133133
[:execution-approved :execution-start]
134134
{:status :executing
135-
:actions []}
135+
:actions [:send-toolCallRunning]}
136136

137137
[:executing :execution-end]
138138
{:status :completed
@@ -196,6 +196,17 @@
196196
:details (:details event-data)
197197
:summary (:summary event-data)))
198198

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+
199210
:send-toolCalled
200211
(send-content! chat-ctx :assistant
201212
(assoc-some
@@ -462,13 +473,13 @@
462473
;; assert: In: :check-approval or :stopped
463474
(when-not (#{:stopped} (:status (get-tool-call-state @db* chat-id id)))
464475
(case approval
465-
:ask (transition-tool-call! db* chat-ctx id :config-ask
476+
:ask (transition-tool-call! db* chat-ctx id :approval-ask
466477
{:state :running
467478
: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
469480
{:reason {:code :user-config-allow
470481
: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
472483
{:reason {:code :user-config-deny
473484
:text "Tool call denied by user config"}})
474485
(logger/warn logger-tag "Unknown value of approval in config"
@@ -479,7 +490,12 @@
479490
;; assert: In :execution-approved or :stopped
480491
(when-not (#{:stopped} (:status (get-tool-call-state @db* chat-id id)))
481492
(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})
483499
;; assert: In :executing
484500
(let [result (f.tools/call-tool! name arguments @db* config messenger behavior)
485501
details (f.tools/tool-call-details-after-invocation name arguments details result)]

0 commit comments

Comments
 (0)