Skip to content

Adding tool combination support#68

Open
aubrypaul wants to merge 2 commits intomainfrom
tool_combination
Open

Adding tool combination support#68
aubrypaul wants to merge 2 commits intomainfrom
tool_combination

Conversation

@aubrypaul
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an option to enable combined tool usage for Chat instances via a chainable configuration method (disabled by default).
  • Bug Fixes

    • Improved browsing/search tool wiring to prevent duplicate tool entries and ensure consistent tool-invocation behavior.

Walkthrough

Adds a tool_combination_enabled flag to Chat with a chainable enableToolCombination(enabled) method; Gemini request payload now includes tool_config.includeServerSideToolInvocations based on the flag and browsing tool wiring was adjusted (removed redundant google_search push).

Changes

Cohort / File(s) Summary
Tool Combination Feature
src/code.gs
Add tool_combination_enabled field and enableToolCombination(enabled) chainable setter. Include tool_config.includeServerSideToolInvocations: tool_combination_enabled in Gemini payload alongside function_calling_config.mode: "AUTO". Adjust browsing tool wiring to remove a redundant tools.push({ google_search: "" }). Removed trailing newline at EOF.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant Chat as Chat (client)
  participant Gemini as Gemini API
  participant Tools as Server-side Tools

  User->>Chat: send message / start chat
  Chat->>Gemini: build request payload
  Note right of Chat: includes function_calling_config.mode = "AUTO"\nand tool_config.includeServerSideToolInvocations = tool_combination_enabled
  Gemini->>Tools: invoke tools if payload requests (google_search, url_context)
  Tools-->>Gemini: tool results
  Gemini-->>Chat: response (may include tool-invocations/results)
  Chat-->>User: final response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a description explaining the purpose and impact of tool combination support, including why this feature was added and how it should be used.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Adding tool combination support' directly matches the main change: introducing a new enableToolCombination() method and tool combination configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tool_combination
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch tool_combination
  • 🛠️ JSDoc Checks: Commit on current branch
  • 🛠️ JSDoc Checks: Create PR

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/code.gs`:
- Around line 306-308: The methods enableToolCombination and enableCompaction
are coercing any truthy value via Boolean(enabled) though their JSDoc promises a
boolean; change them to enforce boolean input by validating typeof enabled ===
"boolean" and either assign enabled directly to the internal flags (e.g.,
tool_combination_enabled, compaction_enabled) or throw a TypeError when a
non-boolean is passed, and return this for chaining; update the implementations
of enableToolCombination and enableCompaction accordingly.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: f8e68d44-3de2-4050-a571-ff1aa506e4d1

📥 Commits

Reviewing files that changed from the base of the PR and between e4acb50 and dd38db2.

📒 Files selected for processing (1)
  • src/code.gs
📜 Review details
🔇 Additional comments (3)
src/code.gs (3)

2457-2457: No actionable issue for EOF newline-only change.


57-57: Good default for feature rollout.

tool_combination_enabled = false at Line 57 is a safe default and preserves existing behavior until explicitly enabled.


764-769: I need the review comment text to rewrite. Please provide the original review comment you would like me to verify and rewrite.

Comment on lines +306 to +308
this.enableToolCombination = function (enabled) {
tool_combination_enabled = Boolean(enabled);
return this;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify call sites and argument shapes passed to enableToolCombination(...)
rg -nP --type=js -C2 '\benableToolCombination\s*\('

Repository: scriptit-fr/GenAIApp

Length of output: 212


🏁 Script executed:

#!/bin/bash
# First, verify the file exists and check the target lines
if [ -f "src/code.gs" ]; then
  echo "=== Code at lines 306-308 ==="
  sed -n '306,308p' src/code.gs
  echo ""
  echo "=== Context around lines 306-308 ==="
  sed -n '300,315p' src/code.gs
else
  echo "File src/code.gs not found"
fi

Repository: scriptit-fr/GenAIApp

Length of output: 868


🏁 Script executed:

#!/bin/bash
# Search for enableToolCombination calls without type filter
echo "=== Calls to enableToolCombination ==="
rg -nC3 'enableToolCombination\s*\(' src/

Repository: scriptit-fr/GenAIApp

Length of output: 102


🏁 Script executed:

#!/bin/bash
# Check file size first to understand what we're working with
wc -l src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Search for any reference to enableToolCombination across all files
echo "=== enableToolCombination references (all files) ==="
rg -n 'enableToolCombination'

Repository: scriptit-fr/GenAIApp

Length of output: 188


🏁 Script executed:

#!/bin/bash
# Search for tool_combination_enabled variable usage
echo "=== tool_combination_enabled usage ==="
rg -n 'tool_combination_enabled' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 281


🏁 Script executed:

#!/bin/bash
# Look for README or examples that might show API usage
echo "=== README and example files ==="
find . -maxdepth 2 -type f \( -name "README*" -o -name "*.md" -o -name "example*" -o -name "test*" \) | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 131


🏁 Script executed:

#!/bin/bash
# Check the structure around the function to understand the API better
echo "=== Full function and surrounding context ==="
sed -n '300,325p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 965


🏁 Script executed:

#!/bin/bash
# Check testFunctions.gs for enableToolCombination usage
echo "=== testFunctions.gs content (search for enableToolCombination) ==="
grep -n 'enableToolCombination' src/testFunctions.gs
if [ $? -ne 0 ]; then
  echo "No enableToolCombination found in testFunctions.gs"
fi

Repository: scriptit-fr/GenAIApp

Length of output: 182


🏁 Script executed:

#!/bin/bash
# Check README for enableToolCombination or API documentation
echo "=== README.md content (search for enableToolCombination) ==="
grep -n 'enableToolCombination' README.md
if [ $? -ne 0 ]; then
  echo "No enableToolCombination found in README.md"
  echo ""
  echo "=== Checking if README documents the Chat API ==="
  grep -n 'Chat\|API\|method' README.md | head -20
fi

Repository: scriptit-fr/GenAIApp

Length of output: 1734


🏁 Script executed:

#!/bin/bash
# Check if there's a pattern for how this library is used - look for method chaining examples
echo "=== Checking for method chaining patterns in testFunctions.gs ==="
head -100 src/testFunctions.gs

Repository: scriptit-fr/GenAIApp

Length of output: 3313


🏁 Script executed:

#!/bin/bash
# Search for enableBrowsing to compare how similar methods handle boolean parameters
echo "=== enableBrowsing implementation ==="
rg -n -A5 'this.enableBrowsing\s*=' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 286


🏁 Script executed:

#!/bin/bash
# Check if there are other enable* methods and their patterns
echo "=== All enable* methods in code.gs ==="
rg -n 'this\.enable[A-Za-z]*\s*=\s*function' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 273


🏁 Script executed:

#!/bin/bash
# Look at full testKnowledgeLink to see more usage patterns
echo "=== More of testFunctions.gs ==="
sed -n '85,120p' src/testFunctions.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1126


🏁 Script executed:

#!/bin/bash
# Check enableCompaction implementation
echo "=== enableCompaction implementation ==="
sed -n '369,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 314


🏁 Script executed:

#!/bin/bash
# Check all three enable* methods side by side to see patterns
echo "=== All enable* methods implementation ==="
sed -n '289,295p' src/code.gs
echo "---"
sed -n '306,312p' src/code.gs
echo "---"
sed -n '369,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 719


🏁 Script executed:

#!/bin/bash
# Check the JSDoc comments for all three enable methods to understand intended API
echo "=== JSDoc for enableBrowsing ==="
sed -n '284,295p' src/code.gs
echo ""
echo "=== JSDoc for enableToolCombination ==="
sed -n '301,312p' src/code.gs
echo ""
echo "=== JSDoc for enableCompaction ==="
sed -n '364,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1444


Fix Boolean coercion in enableToolCombination to match JSDoc specification.

The JSDoc declares @param {boolean} but the implementation accepts any truthy value via Boolean(enabled). This creates a silent type mismatch—callers passing "false" (string) will unintentionally enable the feature since Boolean("false") evaluates to true. A public API with explicit boolean documentation should enforce the type rather than silently coerce it.

The same issue exists in enableCompaction at line 369.

Either remove the Boolean() wrapper and assign enabled directly, or add explicit type validation to reject non-boolean values.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/code.gs` around lines 306 - 308, The methods enableToolCombination and
enableCompaction are coercing any truthy value via Boolean(enabled) though their
JSDoc promises a boolean; change them to enforce boolean input by validating
typeof enabled === "boolean" and either assign enabled directly to the internal
flags (e.g., tool_combination_enabled, compaction_enabled) or throw a TypeError
when a non-boolean is passed, and return this for chaining; update the
implementations of enableToolCombination and enableCompaction accordingly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/code.gs`:
- Around line 764-769: The request payload is adding
includeServerSideToolInvocations unconditionally inside the 'tool_config' object
which causes API 400 errors; modify the code that builds the 'tool_config' (the
object containing function_calling_config) so that
includeServerSideToolInvocations is only added when tool_combination_enabled is
true (e.g., construct tool_config, set function_calling_config always, and
conditionally assign includeServerSideToolInvocations = tool_combination_enabled
only when tool_combination_enabled is truthy).
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 3f74bbec-85f2-4f6a-8716-721a7de34178

📥 Commits

Reviewing files that changed from the base of the PR and between dd38db2 and 988b19e.

📒 Files selected for processing (1)
  • src/code.gs
📜 Review details
🔇 Additional comments (3)
src/code.gs (3)

57-57: Good default for feature flag.

Initializing tool_combination_enabled to false keeps the new behavior opt-in and avoids accidental behavior changes.


306-309: Chainable API addition is consistent.

enableToolCombination(enabled) follows the existing fluent API style and cleanly scopes the flag in Chat.


2457-2457: No concern on EOF newline change.

No functional impact here.

Comment on lines 764 to 769
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
includeServerSideToolInvocations: tool_combination_enabled
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

For Gemini REST APIs (Generative Language v1beta and Vertex AI v1), is tool_config.includeServerSideToolInvocations universally supported across models? Are unknown JSON fields rejected or ignored?

💡 Result:

Is tool_config.includeServerSideToolInvocations supported (Generative Language v1beta / Vertex AI v1)?

No. In the published schemas for these REST APIs, that field doesn’t exist:

  • Generative Language v1beta: ToolConfig only contains function_calling_config (no includeServerSideToolInvocations). [1]
  • Vertex AI v1: ToolConfig only contains function_calling_config and retrieval_config (no includeServerSideToolInvocations). [2]

So it’s not “universally supported across models” in these APIs—it's simply not a recognized request field there.

Are unknown JSON fields rejected or ignored?

They’re rejected (request fails) rather than ignored. Both APIs use protobuf-style JSON parsing and commonly return 400 INVALID_ARGUMENT with messages like “Invalid JSON payload received. Unknown name …: Cannot find field.” when you send unknown fields. Examples:

  • Generative Language v1beta: unknown fields like metadata cause Unknown name ...: Cannot find field. [3]
  • Vertex AI usage also shows unknown fields (e.g., tools, toolConfig when sent to the wrong endpoint/version) being rejected with the same “Unknown name …” error pattern. [4]

Implication: If you send tool_config.includeServerSideToolInvocations to these endpoints, expect an error, not a silent no-op.

Sources: [1] [2] [3] [4]


🏁 Script executed:

# Read the relevant section of the code file
sed -n '750,780p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1472


🏁 Script executed:

# Search for API endpoint/version information in the file
rg -n "googleapis|vertex|generative" src/code.gs | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 821


🏁 Script executed:

# Look for URL patterns or API version strings
rg -n "https?://" src/code.gs | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 1896


Gate includeServerSideToolInvocations to enabled-only to prevent API errors.

The code currently sends includeServerSideToolInvocations unconditionally to both Generative Language v1beta and Vertex AI v1 APIs. This field is not a recognized member of ToolConfig in either API schema. Unknown JSON fields in these APIs are rejected with 400 INVALID_ARGUMENT errors (e.g., "Cannot find field"), causing all requests to fail regardless of whether tool combination is used.

Conditionally set the field only when tool_combination_enabled is true:

💡 Proposed defensive change
         const payload = {
           'contents': contents,
           'model': model,
           'generationConfig': {
             maxOutputTokens: max_tokens,
             temperature: temperature,
           },
           'tool_config': {
             function_calling_config: {
               mode: "AUTO"
-            },
-            includeServerSideToolInvocations: tool_combination_enabled
+            }
           },
           tools: []
         };
+
+        if (tool_combination_enabled) {
+          payload.tool_config.includeServerSideToolInvocations = true;
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
includeServerSideToolInvocations: tool_combination_enabled
},
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/code.gs` around lines 764 - 769, The request payload is adding
includeServerSideToolInvocations unconditionally inside the 'tool_config' object
which causes API 400 errors; modify the code that builds the 'tool_config' (the
object containing function_calling_config) so that
includeServerSideToolInvocations is only added when tool_combination_enabled is
true (e.g., construct tool_config, set function_calling_config always, and
conditionally assign includeServerSideToolInvocations = tool_combination_enabled
only when tool_combination_enabled is truthy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant