Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-gemini): end MALFORMED_FUNCTION_CALL and LANGUAGE finishes with RUN_ERROR #2234

Mergedpcbeingused33(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2234/headmerged by AlemTuzlak View on GitHub

Showing 7 changed files with 39 additions and 10 deletions (loading 3).

x
0 of 7 viewed, 7 left
5 additions and 0 deletions.changeset/gemini-abnormal-finish-reason.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-gemini': patch
+---
+​
+End a Gemini stream that finishes with `MALFORMED_FUNCTION_CALL` or `LANGUAGE` with a `RUN_ERROR` instead of a `RUN_FINISHED` with `stop`, so an agent no longer stops silently with no output or tool call.
1 addition and 1 deletiondocs/adapters/gemini.mdModified
View file
@@ -418,7 +418,7 @@
- Text: `SAFETY`, `RECITATION`, `BLOCKLIST`, `PROHIBITED_CONTENT`, and `SPII`.
- Image: `IMAGE_SAFETY`, `IMAGE_PROHIBITED_CONTENT`, and `IMAGE_RECITATION`.
​
-A filtered structured output ends with `RUN_ERROR` and code `content_filter` instead. A reply cut at `maxOutputTokens` ends with `RUN_ERROR` and code `max_tokens`.
+A filtered structured output ends with `RUN_ERROR` and code `content_filter` instead. A reply cut at `maxOutputTokens` ends with `RUN_ERROR` and code `max_tokens`. A reply the model could not complete ends with `RUN_ERROR` too: `MALFORMED_FUNCTION_CALL` gives code `malformed_function_call` and `LANGUAGE` gives code `language`.
​
### Models
​
33 additions and 9 deletionspackages/ai-gemini/src/adapters/text.tsModified
View file
@@ -132,6 +132,27 @@
FinishReason.IMAGE_RECITATION,
​
+// Finish reasons where Gemini ended the turn without a usable answer (a
+// function call it could not form, or an unsupported language). Ending these
+// as a normal `stop` would make an agent loop stop silently with no output or
+// tool call, so they end the run with a RUN_ERROR. OTHER stays a normal stop.
+const ABNORMAL_FINISH_REASONS = new Map<FinishReason, [string, string]>([