Skip to content

Commit fd33d4b

Browse files
committed
Fix cases when tool calls output nothing.
1 parent eb1b838 commit fd33d4b

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

CHANGELOG.md

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

55
- Improve tool call result marking as error when not expected output.
6+
- Fix cases when tool calls output nothing.
67

78
## 0.12.4
89

src/eca/features/chat.clj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,11 @@
281281
:text (or message (ex-message exception))})
282282
(finish-chat-prompt! :idle chat-ctx))})))
283283

284-
(defn ^:private send-mcp-prompt! [{:keys [prompt args]} {:keys [db*] :as chat-ctx}]
284+
(defn ^:private send-mcp-prompt!
285+
[{:keys [prompt args]}
286+
{:keys [db*] :as chat-ctx}]
285287
(let [{:keys [arguments]} (first (filter #(= prompt (:name %)) (f.mcp/all-prompts @db*)))
286-
i (atom -1)
287-
args-vals (reduce
288-
(fn [a {:keys [name]}]
289-
(swap! i inc)
290-
(assoc a name (nth args @i)))
291-
{}
292-
arguments)
288+
args-vals (zipmap (map :name arguments) args)
293289
{:keys [messages]} (f.mcp/get-prompt! prompt args-vals @db*)]
294290
(prompt-messages! messages false chat-ctx)))
295291

src/eca/features/tools/util.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(defn single-text-content [text & [error]]
88
{:error (boolean error)
99
:contents [{:type :text
10-
:content text}]})
10+
:text text}]})
1111

1212
(defn workspace-roots-strs [db]
1313
(->> (:workspace-folders db)

test/eca/features/chat_test.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[clojure.test :refer [deftest is testing]]
44
[eca.features.chat :as f.chat]
55
[eca.features.tools :as f.tools]
6+
[eca.features.tools.mcp :as f.mcp]
67
[eca.llm-api :as llm-api]
78
[eca.test-helper :as h]
89
[matcher-combinators.matchers :as m]
@@ -245,3 +246,23 @@ for allowed directories and then list files"
245246
{:role :assistant :content {:type :text :text "/foo/bar"}}
246247
{:role :system :content {:state :finished :type :progress}}]}
247248
(h/messages))))))
249+
250+
(deftest send-mcp-prompt-test
251+
(testing "Argument mapping for send-mcp-prompt! should map arg values to prompt argument names"
252+
(let [test-arguments [{:name "foo"} {:name "bar"}]
253+
prompt-args (atom nil)
254+
test-chat-ctx {:db* (atom {})}
255+
invoked? (atom nil)]
256+
(with-redefs [f.mcp/all-prompts (fn [_]
257+
[{:name "awesome-prompt" :arguments test-arguments}])
258+
f.mcp/get-prompt! (fn [_ args-map _]
259+
(reset! prompt-args args-map)
260+
{:messages [{:role :user :content "test"}]})
261+
f.chat/prompt-messages! (fn [messages _reason? ctx] (reset! invoked? [messages ctx]))]
262+
(#'f.chat/send-mcp-prompt! {:prompt "awesome-prompt" :args [42 "yo"]} test-chat-ctx)
263+
(is (match?
264+
@prompt-args
265+
{"foo" 42 "bar" "yo"}))
266+
(is (match?
267+
@invoked?
268+
[[{:role :user :content "test"}] test-chat-ctx]))))))

0 commit comments

Comments
 (0)