Skip to content

Go: add tools for a lot of providers - #17341

Merged
JinHai-CN merged 8 commits into
infiniflow:mainfrom
Haruko386:moon
Jul 24, 2026
Merged

JinHai-CN merged 8 commits into
infiniflow:mainfrom
Haruko386:moon

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Summary

As title #16990

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 24, 2026
@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration and removed 🐞 bug Something isn't working, pull request that fix bug. labels Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This 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.

Changes

Tool-calling support

Layer / File(s) Summary
Model capability declarations
conf/all_models.json, conf/models/*.json
Adds tools.support: true to model entries and normalizes selected model_types arrays.
Google function-calling integration
internal/entity/models/google.go, internal/entity/models/google_test.go
Converts messages and tools to Google SDK types, extracts function calls, wires synchronous and streaming requests, and tests conversions.
Non-streaming response propagation
internal/entity/models/*.go
Accepts tool-call-only responses and populates ChatResponse.ToolCalls.
Streaming response propagation
internal/entity/models/*.go
Accumulates tool-call deltas and finalizes results before stream completion.

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]
Loading

Possibly related PRs

Suggested labels: 💞 feature, size:XL

Poem

A rabbit hops through JSON fields bright,
Tool calls stream through the night;
Deltas gather, results align,
Google functions now combine. 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description matches the template heading but is too generic and provides no useful summary or background context. Replace "As title" with a brief summary of the goal, the affected provider configs and handlers, and any important context for reviewers.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding tool support across many Go providers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386 Haruko386 added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. ci Continue Integration labels Jul 24, 2026
@Haruko386
Haruko386 marked this pull request as draft July 24, 2026 07:13
@Haruko386
Haruko386 marked this pull request as ready for review July 24, 2026 07:13
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jul 24, 2026
@Haruko386 Haruko386 added ci Continue Integration size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. ci Continue Integration labels Jul 24, 2026
@Haruko386
Haruko386 marked this pull request as draft July 24, 2026 07:13
@Haruko386
Haruko386 marked this pull request as ready for review July 24, 2026 07:13
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jul 24, 2026
@Haruko386 Haruko386 added the ci Continue Integration label Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Dead sawTerminal breaks finish_reason-only stream termination in two drivers. Both rewrites removed the finish_reason → sawTerminal assignment from the SSE callback but kept the !done && !sawTerminal truncation guard. Since ParseSSEStream only sets done on a literal [DONE] line, upstreams that terminate with finish_reason alone now fail on complete responses.

  • internal/entity/models/avian.go#L200-L241: re-add if 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 same finish_reason → sawTerminal update 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 win

Return the extracted tool calls.

toolCalls is accepted at Lines 140-142 but never assigned to ChatResponse, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0403d19 and 0ff0f60.

📒 Files selected for processing (69)
  • conf/all_models.json
  • conf/models/302ai.json
  • conf/models/astraflow.json
  • conf/models/avian.json
  • conf/models/baichuan.json
  • conf/models/baidu.json
  • conf/models/cometapi.json
  • conf/models/deepinfra.json
  • conf/models/deepseek.json
  • conf/models/futurmix.json
  • conf/models/gitee.json
  • conf/models/google.json
  • conf/models/groq.json
  • conf/models/hunyuan.json
  • conf/models/jiekouai.json
  • conf/models/jina.json
  • conf/models/longcat.json
  • conf/models/mistral.json
  • conf/models/moonshot.json
  • conf/models/n1n.json
  • conf/models/novita.json
  • conf/models/nvidia.json
  • conf/models/openai.json
  • conf/models/openrouter.json
  • conf/models/orcarouter.json
  • conf/models/ppio.json
  • conf/models/qiniu.json
  • conf/models/stepfun.json
  • conf/models/togetherai.json
  • conf/models/tokenhub.json
  • conf/models/tokenpony.json
  • conf/models/upstage.json
  • conf/models/volcengine.json
  • conf/models/xai.json
  • conf/models/xiaomi.json
  • conf/models/xunfei.json
  • internal/entity/models/302ai.go
  • internal/entity/models/astraflow.go
  • internal/entity/models/avian.go
  • internal/entity/models/baichuan.go
  • internal/entity/models/cohere.go
  • internal/entity/models/cometapi.go
  • internal/entity/models/deepinfra.go
  • internal/entity/models/futurmix.go
  • internal/entity/models/gitee.go
  • internal/entity/models/google.go
  • internal/entity/models/google_test.go
  • internal/entity/models/gpustack.go
  • internal/entity/models/groq.go
  • internal/entity/models/huggingface.go
  • internal/entity/models/hunyuan.go
  • internal/entity/models/jiekouai.go
  • internal/entity/models/lmstudio.go
  • internal/entity/models/localai.go
  • internal/entity/models/longcat.go
  • internal/entity/models/mistral.go
  • internal/entity/models/modelscope.go
  • internal/entity/models/n1n.go
  • internal/entity/models/novita.go
  • internal/entity/models/nvidia.go
  • internal/entity/models/openrouter.go
  • internal/entity/models/orcarouter.go
  • internal/entity/models/stepfun.go
  • internal/entity/models/tokenhub.go
  • internal/entity/models/tokenpony.go
  • internal/entity/models/upstage.go
  • internal/entity/models/vllm.go
  • internal/entity/models/xai.go
  • internal/entity/models/xunfei.go

Comment thread conf/all_models.json
Comment on lines +7748 to +7751
],
"tools": {
"support": true
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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:


🏁 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 -200

Repository: 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:


🌐 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:


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.

Comment thread conf/models/groq.json
Comment on lines 44 to 53
{
"name": "openai/gpt-oss-20b",
"max_tokens": 131072,
"model_types": [
"chat"
]
],
"tools": {
"support": true
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Comment on lines +410 to +422
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())...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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:


🏁 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 || true

Repository: 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:


🌐 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:


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.

Comment on lines 271 to 273
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")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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 from deepseek: to groq:.
  • internal/entity/models/n1n.go#L288-L290: change the prefix from deepseek: to n1n:.
📍 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.

Comment thread internal/entity/models/orcarouter.go Resolved
Comment thread internal/entity/models/upstage.go Resolved
Haruko386 and others added 3 commits July 24, 2026 16:29
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Removed duplicate call to accumulateToolCallDeltas and setSortedToolCallsResult.
@Haruko386 Haruko386 added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 24, 2026
@Haruko386
Haruko386 marked this pull request as draft July 24, 2026 10:24
@Haruko386
Haruko386 marked this pull request as ready for review July 24, 2026 10:24
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jul 24, 2026
@Haruko386 Haruko386 added ci Continue Integration and removed ci Continue Integration labels Jul 24, 2026
@Haruko386 Haruko386 closed this Jul 24, 2026
@Haruko386 Haruko386 reopened this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants