The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Send failed tool calls to Gemini as errors
Andrei Simionescuaa2ac3b62d89
diff --git a/src/metabase/metabot/self/google/stream_generate_content.clj b/src/metabase/metabot/self/google/stream_generate_content.cljindex a2f78a0a0a3..a69b1cc5c13 100644--- a/src/metabase/metabot/self/google/stream_generate_content.clj+++ b/src/metabase/metabot/self/google/stream_generate_content.clj@@ -109,10 +109,10 @@{:name (or (:function part)(id->name (:id part))"unknown_function")- :response {:output (or (get-in part [:result :output])- (when-let [err (:error part)]- (str "Error: " (:message err)))- (pr-str (:result part)))}}}]}+ ;; Gemini reads a failure under `error` and a result under `output`.+ :response {(if (get-in part [:result :error]) :error :output)+ (or (get-in part [:result :output])+ (pr-str (:result part)))}}}]};; Reasoning is display-only: thought summaries never go back to Gemini. The;; model keeps its reasoning continuity through the functionCall;; thoughtSignatures replayed above. The empty :parts vector is dropped bydiff --git a/test/metabase/metabot/self/google/stream_generate_content_test.clj b/test/metabase/metabot/self/google/stream_generate_content_test.cljindex 32cd6cec10f..9624a98667d 100644--- a/test/metabase/metabot/self/google/stream_generate_content_test.clj+++ b/test/metabase/metabot/self/google/stream_generate_content_test.clj@@ -106,12 +106,14 @@[{:type :tool-output :id "call-1" :function "search" :result {:output "Found 42 results"}}])))))(deftest ^:parallel parts->contents-tool-error-test- (testing "a failed tool output surfaces the error message in the functionResponse"+ (testing "a failed call's text goes under `error`, so Gemini reads it as a failure rather than a result"(is (= [{:role "user":parts [{:functionResponse {:name "search"- :response {:output "Error: boom"}}}]}]+ :response {:error "Card 7 was not found."}}}]}](sgc/parts->contents- [{:type :tool-output :id "call-1" :function "search" :error {:message "boom"}}])))))+ [{:type :tool-output :id "call-1" :function "search"+ :result {:output "Card 7 was not found."+ :error {:class :recoverable :code :x}}}])))))(deftest ^:parallel parts->contents-tool-result-without-output-key-test(testing "a result map that carries no :output is printed rather than sent as an empty response"