Repository navigation
Go: add tools for a lot of providers - #17341
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds per-model tool-support metadata, propagates non-streaming and streaming tool calls through provider drivers, and adds Google function-calling conversion, request wiring, streaming capture, and tests. ChangesTool-calling support
Estimated code review effort: 4 (Complex) | ~75 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant ChatModel
participant SSEStream
participant ChatModelConfig
Caller->>ChatModel: Start streaming chat
ChatModel->>SSEStream: ParseSSEStream(events)
loop Each event
SSEStream-->>ChatModel: delta
ChatModel->>ChatModel: accumulateToolCallDeltas(delta)
end
ChatModel->>ChatModelConfig: setSortedToolCallsResult(...)
ChatModel-->>Caller: [DONE]
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/entity/models/avian.go (1)
200-241: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDead
sawTerminalbreaks finish_reason-only stream termination in two drivers. Both rewrites removed thefinish_reason→sawTerminalassignment from the SSE callback but kept the!done && !sawTerminaltruncation guard. SinceParseSSEStreamonly setsdoneon a literal[DONE]line, upstreams that terminate withfinish_reasonalone now fail on complete responses.
internal/entity/models/avian.go#L200-L241: re-addif finishReason, ok := firstChoice["finish_reason"].(string); ok && finishReason != "" { sawTerminal = true }inside the callback before the guard at Line 239.internal/entity/models/cometapi.go#L289-L330: re-add the samefinish_reason→sawTerminalupdate inside the callback (Lines 291-323) before the guard at Line 328.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/avian.go` around lines 200 - 241, Restore finish_reason-based termination tracking in the SSE callbacks: in internal/entity/models/avian.go lines 200-241, update sawTerminal from a non-empty firstChoice["finish_reason"] before the existing truncation guard; apply the same change in internal/entity/models/cometapi.go lines 289-330. Preserve the existing done and !done && !sawTerminal validation.internal/entity/models/deepinfra.go (1)
139-157: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReturn the extracted tool calls.
toolCallsis accepted at Lines 140-142 but never assigned toChatResponse, so DeepInfra tool-only and mixed responses silently lose function calls.Proposed fix
chatResponse := &ChatResponse{ - Answer: &content, + Answer: &content, + ToolCalls: toolCalls, }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/deepinfra.go` around lines 139 - 157, Assign the extracted toolCalls to the ChatResponse being constructed in the response parsing flow, ensuring both tool-only and mixed messages preserve their function calls while retaining the existing content and reasoning handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@conf/all_models.json`:
- Around line 7748-7751: Update the Gemma 2/3 model entries in the tools
configuration to disable tools.support unless the serving provider explicitly
guarantees native tool calling; set it false for google/gemma-2-2b-it and
google/gemma-3-27b-it while preserving other model capabilities.
In `@conf/models/groq.json`:
- Around line 44-53: The model configuration contains duplicate
openai/gpt-oss-20b entries. Remove the redundant entry, or replace it with the
intended distinct model after verifying the source, while retaining only one
correctly configured openai/gpt-oss-20b definition.
In `@internal/entity/models/google.go`:
- Around line 410-422: Update the GenerateContentStream handling in the
tool-call accumulation flow to preserve a stable function-call ID across
incremental responses. Accumulate partial function-call chunks and emit only the
terminal completed call, or deduplicate merged calls by their existing call ID
before appending to toolCalls; do not generate a new per-response index that
splits one streamed call into multiple toolCalls.
In `@internal/entity/models/groq.go`:
- Around line 271-273: Correct the provider prefixes in the stream truncation
error: update the error in internal/entity/models/groq.go at lines 271-273 to
use “groq:”, and the corresponding error in internal/entity/models/n1n.go at
lines 288-290 to use “n1n:”; leave the remainder of each message and handling
unchanged.
In `@internal/entity/models/orcarouter.go`:
- Around line 125-126: Non-streaming tool calls are extracted but discarded from
both driver responses. Update the ChatResponse literals in
internal/entity/models/orcarouter.go lines 132-135 and
internal/entity/models/stepfun.go lines 131-134 to populate ToolCalls from the
existing toolCalls variable, keeping both implementations consistent.
In `@internal/entity/models/upstage.go`:
- Around line 221-224: Remove the duplicate accumulateToolCallDeltas call in the
relevant Upstage SSE delta-processing flow, keeping exactly one accumulation per
delta. Also remove the duplicate finalization call in the corresponding
finalization block near the referenced secondary location, preserving one
finalization invocation.
---
Outside diff comments:
In `@internal/entity/models/avian.go`:
- Around line 200-241: Restore finish_reason-based termination tracking in the
SSE callbacks: in internal/entity/models/avian.go lines 200-241, update
sawTerminal from a non-empty firstChoice["finish_reason"] before the existing
truncation guard; apply the same change in internal/entity/models/cometapi.go
lines 289-330. Preserve the existing done and !done && !sawTerminal validation.
In `@internal/entity/models/deepinfra.go`:
- Around line 139-157: Assign the extracted toolCalls to the ChatResponse being
constructed in the response parsing flow, ensuring both tool-only and mixed
messages preserve their function calls while retaining the existing content and
reasoning handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c8113e1b-0827-4c73-ae55-cf335c0795d9
📒 Files selected for processing (69)
conf/all_models.jsonconf/models/302ai.jsonconf/models/astraflow.jsonconf/models/avian.jsonconf/models/baichuan.jsonconf/models/baidu.jsonconf/models/cometapi.jsonconf/models/deepinfra.jsonconf/models/deepseek.jsonconf/models/futurmix.jsonconf/models/gitee.jsonconf/models/google.jsonconf/models/groq.jsonconf/models/hunyuan.jsonconf/models/jiekouai.jsonconf/models/jina.jsonconf/models/longcat.jsonconf/models/mistral.jsonconf/models/moonshot.jsonconf/models/n1n.jsonconf/models/novita.jsonconf/models/nvidia.jsonconf/models/openai.jsonconf/models/openrouter.jsonconf/models/orcarouter.jsonconf/models/ppio.jsonconf/models/qiniu.jsonconf/models/stepfun.jsonconf/models/togetherai.jsonconf/models/tokenhub.jsonconf/models/tokenpony.jsonconf/models/upstage.jsonconf/models/volcengine.jsonconf/models/xai.jsonconf/models/xiaomi.jsonconf/models/xunfei.jsoninternal/entity/models/302ai.gointernal/entity/models/astraflow.gointernal/entity/models/avian.gointernal/entity/models/baichuan.gointernal/entity/models/cohere.gointernal/entity/models/cometapi.gointernal/entity/models/deepinfra.gointernal/entity/models/futurmix.gointernal/entity/models/gitee.gointernal/entity/models/google.gointernal/entity/models/google_test.gointernal/entity/models/gpustack.gointernal/entity/models/groq.gointernal/entity/models/huggingface.gointernal/entity/models/hunyuan.gointernal/entity/models/jiekouai.gointernal/entity/models/lmstudio.gointernal/entity/models/localai.gointernal/entity/models/longcat.gointernal/entity/models/mistral.gointernal/entity/models/modelscope.gointernal/entity/models/n1n.gointernal/entity/models/novita.gointernal/entity/models/nvidia.gointernal/entity/models/openrouter.gointernal/entity/models/orcarouter.gointernal/entity/models/stepfun.gointernal/entity/models/tokenhub.gointernal/entity/models/tokenpony.gointernal/entity/models/upstage.gointernal/entity/models/vllm.gointernal/entity/models/xai.gointernal/entity/models/xunfei.go
| ], | ||
| "tools": { | ||
| "support": true | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Does google/gemma-2-2b-it officially support native function calling / tool calling?
💡 Result:
No, the google/gemma-2-2b-it model does not officially support native function calling or tool calling [1][2][3]. While Google has released specialized models like FunctionGemma (a version of the Gemma 3 270M model) explicitly designed for function calling [4][5], the standard instruction-tuned Gemma 2 models (including 2b-it) lack built-in, native training for this capability [2][3]. Developers often compensate for this limitation by using techniques such as few-shot prompting, ReAct patterns, or fine-tuning the model on specific function-calling datasets [1][6][7][2]. Additionally, although the official gemma Python library includes a ToolSampler class that allows for tool-use experimentation, the documentation explicitly notes that Gemma 1, 2, and 3 models were not specifically trained for tool use and that this feature is considered a proof-of-concept rather than an officially supported capability [3].
Citations:
- 1: https://github.com/chiruu12/Fine-tuning-google-gemma-2-2b-it
- 2: https://developers.googleblog.com/beyond-the-chatbot-agentic-ai-with-gemma/
- 3: https://gemma-llm.readthedocs.io/en/latest/colab_tool_use.html
- 4: https://blog.google/innovation-and-ai/technology/developers-tools/functiongemma/
- 5: https://ai.google.dev/gemma/docs/functiongemma
- 6: https://github.com/rodrigo-pedro/gemma-function-calling
- 7: https://github.com/google-gemma/cookbook/blob/main/Gemma/%5BGemma_2%5DFinetune_with_Function_Calling.ipynb
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Relevant model entries:"
python3 - <<'PY'
import json
from pathlib import Path
p=Path("conf/all_models.json")
data=json.loads(p.read_text())
keys=["google/gemma-2-2b-it","google/gemma-3-27b-it"]
for key in keys:
print(f"\n--- {key} ---")
for provider, models in data.get("models", {}).items():
for m in (models if isinstance(models, list) else []):
if isinstance(m, dict) and m.get("name") == key:
print(provider, json.dumps(m, indent=2, sort_keys=True))
PY
echo
echo "Locate model_service.go tools support references:"
rg -n "is_tools|tools|Gemma|gem" internal service conf/all_models.json -g '!**/*.md' | head -200Repository: infiniflow/ragflow
Length of output: 2023
🌐 Web query:
Google AI Studio Gemma 2 function calling supported google/gemma-2-2b-it
💡 Result:
The google/gemma-2-2b-it model does not have native support for function calling [1][2]. While the model is highly capable of instruction following, it was not specifically trained to generate structured tool-call outputs, and using it for such tasks often requires workarounds like advanced prompting, in-context learning (e.g., few-shot prompting), or the use of agentic frameworks like LangChain to manage tool interactions [1][3]. If you require native function calling capabilities within the Gemma family, Google provides the FunctionGemma model. FunctionGemma is a specialized, smaller model (270M parameters) explicitly fine-tuned for reliable function calling, tool use, and API interaction [4][5][6]. Alternatively, for larger tasks or scenarios where a more powerful model is required, Gemini-series models natively support function calling [7][8]. In the open-source community, there are also various community-maintained, fine-tuned versions of gemma-2-2b-it specifically adapted for function calling, which can be found on platforms like Hugging Face [9][10][11]. However, these are not official Google-supported function-calling models [4].
Citations:
- 1: https://developers.googleblog.com/en/beyond-the-chatbot-agentic-ai-with-gemma/
- 2: https://github.com/chiruu12/Fine-tuning-google-gemma-2-2b-it
- 3: https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/%5BGemma_2%5DFunction_Calling_with_Groq_Langchain.ipynb
- 4: https://ai.google.dev/gemma/docs/functiongemma
- 5: https://ai.google.dev/gemma/docs/functiongemma/formatting-and-best-practices
- 6: https://ai.google.dev/gemma/docs/functiongemma/full-function-calling-sequence-with-functiongemma
- 7: https://aistudio.google.com/
- 8: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/function-calling
- 9: https://huggingface.co/google-cloud-partnership/gemma-2-2b-it-function_calling
- 10: https://huggingface.co/qgallouedec/gemma-2-2B-it-thinking-function_calling
- 11: https://huggingface.co/bodhicitta/gemma-2b-function-call
🌐 Web query:
Google AI Studio Gemma 3 function calling supported google/gemma-3-27b-it
💡 Result:
The google/gemma-3-27b-it model does not have native, built-in function calling support in Google AI Studio [1]. Unlike Gemini models, which support function calling as a native API feature, Gemma 3 is an open-weights model that requires manual implementation for tool use [1][2]. To perform function calling with gemma-3-27b-it, you must implement a workaround [1][3]: 1. Instruction Prompting: Because there are no dedicated tool-use tokens or API-level function definitions, you must instruct the model within the system or user prompt to output function calls in a specific, parsable format (e.g., wrapped in custom tags like tool_code) [4][1][3]. 2. Manual Parsing: Your application code must parse the model's text response, identify the function call, execute the function locally, and then send the output back to the model as a new turn in the conversation [4][1][3]. While Google provides FunctionGemma—a separate, smaller specialized model (270M parameters) specifically tuned for function calling—this is distinct from the 27B-IT model [5][6]. For agentic workflows using gemma-3-27b-it, developers typically use custom mixins or integration logic to convert tool declarations into prompt instructions and parse the resulting text [1].
Citations:
- 1: https://github.com/google/adk-python/blob/4d8fbf71/src/google/adk/models/gemma_llm.py
- 2: https://huggingface.co/google/gemma-3-27b-it/discussions/24
- 3: https://www.philschmid.de/gemma-function-calling
- 4: https://github.com/philschmid/gemini-samples/blob/main/examples/gemma-function-calling.ipynb
- 5: https://ai.google.dev/gemma/docs/functiongemma/formatting-and-best-practices
- 6: https://ai.google.dev/gemma/docs/functiongemma
Disable tool support for Gemma 2/3 entries unless the serving provider guarantees it.
google/gemma-2-2b-it lacks native/official function calling, and google/gemma-3-27b-it relies on prompt-based/manual tool parsing rather than built-in tool support. With tools.support: true, this entry advertises structured tool-call capability via the downstream is_tools path for models that should not reliably produce it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@conf/all_models.json` around lines 7748 - 7751, Update the Gemma 2/3 model
entries in the tools configuration to disable tools.support unless the serving
provider explicitly guarantees native tool calling; set it false for
google/gemma-2-2b-it and google/gemma-3-27b-it while preserving other model
capabilities.
| { | ||
| "name": "openai/gpt-oss-20b", | ||
| "max_tokens": 131072, | ||
| "model_types": [ | ||
| "chat" | ||
| ] | ||
| ], | ||
| "tools": { | ||
| "support": true | ||
| } | ||
| }, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Duplicate model entry: openai/gpt-oss-20b listed twice.
The entry at lines 74-83 duplicates the one at lines 44-53 exactly (same name, max_tokens, model_types, tools). This is likely a copy-paste error; verify whether this was meant to be a different model.
🔧 Proposed fix
{
"name": "groq/compound-mini",
"max_tokens": 131072,
"model_types": [
"chat"
],
"tools": {
"support": true
}
},
- {
- "name": "openai/gpt-oss-20b",
- "max_tokens": 131072,
- "model_types": [
- "chat"
- ],
- "tools": {
- "support": true
- }
- },
{
"name": "meta-llama/llama-4-scout-17b-16e-instruct",Also applies to: 74-83
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@conf/models/groq.json` around lines 44 - 53, The model configuration contains
duplicate openai/gpt-oss-20b entries. Remove the redundant entry, or replace it
with the intended distinct model after verifying the source, while retaining
only one correctly configured openai/gpt-oss-20b definition.
| var toolCalls []map[string]interface{} | ||
|
|
||
| for response, err := range client.Models.GenerateContentStream( | ||
| ctx, | ||
| modelName, | ||
| contents, | ||
| nil, | ||
| googleGenerateContentConfig(chatModelConfig), | ||
| ) { | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| toolCalls = append(toolCalls, googleToolCalls(response.FunctionCalls())...) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
google.golang.org/genai streaming FunctionCalls delivered per chunk or accumulated
💡 Result:
When using the Google Gen AI Go SDK (google.golang.org/genai), streaming function calls are delivered as a series of incremental updates. To reconstruct the complete function call with its final arguments, you must accumulate these partial fragments [1][2]. Key mechanisms for handling these streamed function calls include: 1. Partial Arguments (PartialArgs): When streaming is enabled (via streamFunctionCallArguments: true), the response chunks contain a FunctionCall object with a PartialArgs field [1]. These fragments provide incremental pieces of the function arguments, which are typically structured by JSON paths [1]. 2. Continuation Indicators (WillContinue): The WillContinue boolean field indicates whether the model expects to send more fragments for a specific function call [1]. A value of true means the function call is still in progress across subsequent chunks, while false (or the absence of the field) signals that the final piece has been received and the function call is complete [1]. 3. Manual or SDK-managed Accumulation: Developers must aggregate these deltas to reconstruct the full arguments [2]. Internal implementation patterns within the Google ecosystem (such as the streamingResponseAggregator used in related libraries) demonstrate maintaining a buffer for the function name, ID, and argument map, which is then "flushed" or finalized once WillContinue becomes false [3][4][5]. Recent updates to the googleapis/go-genai repository have explicitly added functionality to handle the accumulation of these streamed function call arguments [6]. You should ensure you are using a version of the SDK that supports this, and consult the library's internal stream_aggregator patterns if implementing your own accumulation logic to correctly map and merge the partial argument fragments [3][4].
Citations:
- 1: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/function-calling
- 2: https://ai.google.dev/gemini-api/docs/function-calling
- 3: https://github.com/google/adk-go/blob/ea1865bd/internal/llminternal/stream_aggregator.go
- 4: https://github.com/google/adk-go/blob/f73905c8/internal/llminternal/stream_aggregator.go
- 5: https://github.com/google/adk-go/blob/f73905c8/internal/llminternal/stream_aggregator_test.go
- 6: googleapis/go-genai@7431ee7
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== locate google.go and relevant symbols =="
git ls-files | grep -E '(^|/)google\.go$|go\.mod$|go\.sum$' || true
printf '\n== google.go outline around stream/helper ==\n'
ast-grep outline internal/entity/models/google.go --match googleToolCalls --view expanded || true
printf '\n== relevant source lines 320-430 ==\n'
sed -n '320,430p' internal/entity/models/google.go | nl -ba -v320
printf '\n== google module/version references =="n'
rg -n 'google/golang/org/genai|googleapis/go-genai' go.mod go.sum 2>/dev/null || trueRepository: infiniflow/ragflow
Length of output: 2023
🌐 Web query:
googleapis go-genai streaming FunctionCalls stream chunks duplicate calls or partials ID generated
💡 Result:
In the googleapis/go-genai SDK, streaming function calls are handled by receiving a sequence of chunks that contain partial arguments [1][2]. Historically, this required developers to manually aggregate these partial deltas to reconstruct the complete function call [3][4]. Recent updates to the go-genai library (as of July 2026) have introduced built-in accumulation logic to address these challenges [1][2]. Key points regarding the current implementation: 1. Automatic Accumulation: A fix and new internal component (e.g., streamed_function_calls.go) have been implemented to accumulate streamed function-call partial arguments into final Args values automatically during GenerateContentStream and Live Session.Receive operations [1][2]. This reduces the need for manual reconstruction of partials [1]. 2. Handling Partial Chunks: The SDK manages the assembly of function calls by tracking their state (name, ID, and partial arguments) as they stream [1][5]. When the model indicates it has finished providing arguments (often signaled by WillContinue metadata), the SDK flushes the aggregated function call into the conversation sequence [5]. 3. Avoiding Duplicates: The internal logic is designed to merge completed function calls into chat history while preserving the order of completed calls [1]. By accumulating arguments internally rather than treating every partial chunk as a distinct call, the SDK avoids the common issue of triggering duplicate function calls or misinterpreting fragmented JSON arguments [1]. 4. Known Issues: Prior to these recent updates, users reported issues with Chat.SendStream failing to properly support or handle parallel function calls, sometimes resulting in INVALID_ARGUMENT errors when the model requested multiple functions simultaneously [6]. Ensuring you are using the latest version of the go-genai module is critical to benefit from the accumulated fixes [1][2]. If you are encountering issues with duplicated or partial function calls, verify that your environment is using the latest version of google.golang.org/genai to ensure the updated accumulation logic is active [1][7].
Citations:
- 1: fix: accumulate streamed function call arguments googleapis/go-genai#837
- 2: googleapis/go-genai@d780e28
- 3: https://ai.google.dev/gemini-api/docs/function-calling
- 4: https://ai.google.dev/gemini-api/docs/function-calling.md.txt
- 5: https://github.com/google/adk-go/blob/f73905c8/internal/llminternal/stream_aggregator.go
- 6: Chat.SendStream does not seem to support parallel function calling googleapis/go-genai#692
- 7: https://pkg.go.dev/google.golang.org%2Fgenai
🌐 Web query:
site:pkg.go.dev/google.golang.org/genai FunctionCall ID PartialArgs WillContinue Streaming FunctionCalls
💡 Result:
The requested terms (FunctionCall, ID, PartialArgs, WillContinue) do not appear in the provided search results, and broad searches did not return specific technical definitions for these fields in the context of streaming LLM function calls. Consequently, there is no authoritative or specific technical documentation available within the provided sources to explain these parameters. In general API design, such fields are typically used to manage stateful streaming, where ID correlates chunks to a specific request, PartialArgs indicates incremental argument construction, and WillContinue serves as a flag for multi-chunk payloads, but this is a generalized interpretation not confirmed by the search results.
Citations:
🌐 Web query:
github googleapis go-genai streamed_function_calls.go streaming chunks FunctionCalls
💡 Result:
The file streamed_function_calls.go in the googleapis/go-genai repository is a component dedicated to handling the accumulation of partial function call arguments during streaming responses [1][2]. In the context of the Google Gen AI Go SDK (google.golang.org/genai), when streaming is enabled for function calling, the model sends function calls as a sequence of partial updates rather than a complete object in a single event [3]. Because these arguments are sent in chunks, they must be aggregated by the client before the function can be executed [3]. Key details regarding this implementation include: 1. Purpose: The streamed_function_calls.go file provides the logic to correctly reconstruct and accumulate these partial argument chunks into a complete, usable function call object [1][2]. 2. Configuration: To enable this behavior, users must explicitly configure the GenerateContentConfig with StreamFunctionCallArguments set to true within the FunctionCallingConfig [4]. 3. Usage: While the SDK provides mechanisms for this, users have reported challenges, such as issues with parallel function calling when using stream-based interfaces [5]. 4. Context: The go-genai repository is the current, active SDK for Google's generative models [6][7]. It replaces the legacy github.com/google/generative-ai-go/genai SDK, which reached its end-of-life on November 30, 2025 [8]. If you are implementing function calling with streaming, you should rely on the accumulation logic provided by the official go-genai SDK to ensure that partial JSON chunks are correctly parsed and combined before you attempt to process the function arguments [1][4][3].
Citations:
- 1: googleapis/go-genai@7431ee7
- 2: googleapis/go-genai@d780e28
- 3: https://ai.google.dev/gemini-api/docs/function-calling
- 4: https://github.com/googleapis/go-genai/blob/b7bfe9b2253f1a948c9128ff73ef45af7819ba9d/models_test.go
- 5: Chat.SendStream does not seem to support parallel function calling googleapis/go-genai#692
- 6: https://github.com/googleapis/go-genai
- 7: https://pkg.go.dev/google.golang.org/genai
- 8: https://pkg.go.dev/github.com/google/generative-ai-go/genai
Keep streamed tool-call ID synthesis stable.
Streaming function-call chunks are incremental updates and can arrive across multiple GenerateContentStream responses; a new per-call index in the generated tool response can add these as separate toolCalls instead of a single final call. Accum/emit only the terminal completed function call with a stable ID, or dedupe by call ID before appending.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/entity/models/google.go` around lines 410 - 422, Update the
GenerateContentStream handling in the tool-call accumulation flow to preserve a
stable function-call ID across incremental responses. Accumulate partial
function-call chunks and emit only the terminal completed call, or deduplicate
merged calls by their existing call ID before appending to toolCalls; do not
generate a new per-response index that splits one streamed call into multiple
toolCalls.
| if !done && !sawTerminal { | ||
| return fmt.Errorf("groq: stream ended before [DONE] or finish_reason") | ||
| return fmt.Errorf("deepseek: stream ended before [DONE] or finish_reason") | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Truncation error message mislabeled deepseek: in two drivers. Both files copy the same "deepseek: stream ended before [DONE] or finish_reason" string into the wrong provider's method, which will misdirect debugging.
internal/entity/models/groq.go#L271-L273: change the prefix fromdeepseek:togroq:.internal/entity/models/n1n.go#L288-L290: change the prefix fromdeepseek:ton1n:.
📍 Affects 2 files
internal/entity/models/groq.go#L271-L273(this comment)internal/entity/models/n1n.go#L288-L290
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/entity/models/groq.go` around lines 271 - 273, Correct the provider
prefixes in the stream truncation error: update the error in
internal/entity/models/groq.go at lines 271-273 to use “groq:”, and the
corresponding error in internal/entity/models/n1n.go at lines 288-290 to use
“n1n:”; leave the remainder of each message and handling unchanged.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Removed duplicate call to accumulateToolCallDeltas and setSortedToolCallsResult.
Summary
As title #16990