Skip to content

fix: Add support for Gemini internal tools in tool formatting#923

Merged
MervinPraison merged 2 commits into
mainfrom
claude/issue-919-20250715_061529
Jul 15, 2025
Merged

fix: Add support for Gemini internal tools in tool formatting#923
MervinPraison merged 2 commits into
mainfrom
claude/issue-919-20250715_061529

Conversation

@MervinPraison

@MervinPraison MervinPraison commented Jul 15, 2025

Copy link
Copy Markdown
Owner

Summary

  • Add explicit handling for Gemini internal tools (googleSearch, urlContext, codeExecution)
  • Update docstrings to document new capability
  • Resolves issue where Gemini internal tools were skipped with 'unsupported type' error
  • Maintains backward compatibility with existing tool formats

Fixes
Closes #919

Test Plan

  • Tested individual Gemini internal tools
  • Tested combined tools usage
  • Verified unknown tools are properly rejected
  • Confirmed backward compatibility

Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Enhanced tool support to recognize and handle Gemini internal tools, including Google Search, URL Context, and Code Execution, for improved compatibility.
  • Documentation

    • Updated documentation to reflect support for Gemini internal tools in tool formatting.

- Add explicit handling for Gemini internal tools (googleSearch, urlContext, codeExecution)
- Update docstrings to document new capability
- Resolves issue where Gemini internal tools were skipped with ''unsupported type'' error
- Maintains backward compatibility with existing tool formats

Closes #919

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The code updates enhance tool formatting logic in both llm.py and openai_client.py to support Gemini internal tools. Now, dictionaries with keys like "googleSearch", "urlContext", or "codeExecution" are recognized and included in formatted tool lists, enabling proper handling of Gemini-specific features.

Changes

File(s) Change Summary
src/praisonai-agents/praisonaiagents/llm/llm.py Enhanced _format_tools_for_litellm to detect and include Gemini internal tools in formatted output.
src/praisonai-agents/praisonaiagents/llm/openai_client.py Updated format_tools to support Gemini internal tools, with improved logging and docstring update.
src/praisonai-agents/praisonaiagents/llm/model_capabilities.py Added GEMINI_INTERNAL_TOOLS constant and is_gemini_internal_tool function to identify Gemini internal tools.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Agent
    participant LLM
    participant OpenAIClient

    User->>Agent: Initialize with tools (including Gemini internal tools)
    Agent->>LLM: Pass tools to LLM
    LLM->>LLM: _format_tools_for_litellm detects Gemini internal tools
    LLM->>OpenAIClient: Pass formatted tools
    OpenAIClient->>OpenAIClient: format_tools includes Gemini internal tools
    OpenAIClient->>LLM: Return formatted tool list
    LLM->>Agent: Tools ready for completion call
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure Gemini internal tools (googleSearch, urlContext, codeExecution) are recognized and utilized by the agent (#919) βœ…
Format tools as list of dicts for completion calls, matching Gemini SDK/proxy usage (#919) βœ…
Update debug logs to reflect correct handling of Gemini internal tools (#919) βœ…

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested labels

Review effort 3/5

Poem

In the code’s bright warren, tools now leapβ€”
Gemini’s secrets no longer sleep.
GoogleSearch and friends, in lists they dwell,
Ready for LLMs to cast their spell.
With each new patch, the future’s brightβ€”
The agent’s toolkit hops to new height!
πŸ‡βœ¨


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ca9372e and 75cf3b7.

πŸ“’ Files selected for processing (3)
  • src/praisonai-agents/praisonaiagents/llm/llm.py (3 hunks)
  • src/praisonai-agents/praisonaiagents/llm/model_capabilities.py (1 hunks)
  • src/praisonai-agents/praisonaiagents/llm/openai_client.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/praisonai-agents/praisonaiagents/llm/llm.py
  • src/praisonai-agents/praisonaiagents/llm/openai_client.py
🧰 Additional context used
🧠 Learnings (1)
πŸ““ Common learnings
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/llm/llm.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage for large language model calls in Node.js/TypeScript code.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/{llm,agent,agents,task}/**/*.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage in TypeScript code.
πŸ”‡ Additional comments (2)
src/praisonai-agents/praisonaiagents/llm/model_capabilities.py (2)

110-111: LGTM - Well-defined constant for Gemini internal tools

The constant definition is clean and follows Python naming conventions. The set contains the three expected Gemini internal tool names as documented in the PR objectives.


114-130: LGTM - Robust implementation with comprehensive validation

The function implementation is well-designed with proper input validation:

  • Type checking with isinstance(tool, dict) handles non-dict inputs safely
  • Length validation len(tool) == 1 ensures exactly one key as expected for Gemini tools
  • Safe key extraction using next(iter(tool.keys()))
  • Clear membership check against the defined constant

The docstring is comprehensive with clear examples and parameter documentation. The function handles edge cases appropriately (None inputs, empty dicts, multi-key dicts) by returning False.

✨ Finishing Touches
  • πŸ“ Generate Docstrings

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
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MervinPraison

Copy link
Copy Markdown
Owner Author

@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes.

@gemini-code-assist gemini-code-assist 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.

Summary of Changes

Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the tool formatting capabilities within the praisonai-agents library to properly recognize and process specific internal tools used by Gemini models. By integrating explicit handling for googleSearch, urlContext, and codeExecution, it addresses a previous limitation where these tools were incorrectly rejected, thereby improving the robustness and functionality of tool integration with Gemini.

Highlights

  • Gemini Tool Support: Added explicit handling for Gemini internal tools (googleSearch, urlContext, codeExecution) within the tool formatting logic in both llm.py and openai_client.py.
  • Bug Fix: Resolved an issue where these Gemini internal tools were previously skipped due to an 'unsupported type' error, ensuring they are now correctly processed.
  • Documentation Update: Updated docstrings for the _format_tools_for_litellm and format_tools methods to clearly document the newly supported Gemini internal tools.
  • Compatibility: Ensured that the changes maintain backward compatibility with existing tool formats, preventing regressions for previously supported tool types.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with πŸ‘ and πŸ‘Ž on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions

github-actions Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task β€”β€” View job


PR Review and Analysis βœ…

Starting detailed analysis of PR #923: "Add support for Gemini internal tools in tool formatting"

Todo List:

  • Read and analyze the changed files (llm.py and openai_client.py)
  • Check the original issue Its not using Gemini internal toolsΒ #919 for context
  • Verify the implementation is complete and correct
  • Test backward compatibility
  • Run code tests if possible
  • Make minimal fixes if needed
  • Provide detailed review feedback

Analysis Summary:

Issue Context: The issue #919 shows that Gemini internal tools like {"googleSearch": {}} were being rejected with "Skipping tool of unsupported type" errors, preventing their use.

Changes Made:

  1. llm.py: Added explicit handling in _format_tools_for_litellm() method (lines 592-602)
  2. openai_client.py: Added same handling in format_tools() method (lines 408-418)
  3. Documentation: Updated docstrings to document the new Gemini internal tools support

Code Review:

βœ… Implementation Quality:

  • Correctly identifies single-key dictionaries as potential Gemini tools
  • Uses whitelist validation against known tools: {'googleSearch', 'urlContext', 'codeExecution'}
  • Preserves tools unchanged (pass-through approach)
  • Includes proper debug logging

βœ… Test Results:

  • Verified: 3/4 test tools formatted correctly (unknown tool properly rejected)
  • Backward compatibility: All existing tool formats continue to work
  • Mixed scenarios: Correctly handles combinations of OpenAI and Gemini tools

βœ… Code Quality:

  • Consistent implementation across both files
  • Minimal, focused changes
  • Clear documentation updates
  • Proper error handling and logging

Security & Best Practices:

βœ… Security: Implementation is safe:

  • Uses whitelist validation (only known tools accepted)
  • No code execution or eval usage
  • No external API calls in formatting stage

βœ… Maintainability:

  • Code is well-documented with clear docstrings
  • Debug logging helps with troubleshooting
  • Simple, understandable logic

Final Assessment:

βœ… APPROVED - This PR successfully resolves issue #919 with a clean, minimal implementation that:

  1. Fixes the core issue: Gemini internal tools are now properly recognized and passed through
  2. Maintains backward compatibility: All existing tool formats continue to work unchanged
  3. Uses best practices: Whitelist validation, proper logging, clear documentation
  4. Minimal scope: Only adds what's necessary, no unnecessary changes
  5. Consistent: Same implementation pattern in both affected files

The implementation correctly addresses the "Skipping tool of unsupported type" error from the original issue while maintaining all existing functionality.

Recommendation: Merge this PR as-is. The implementation is solid and ready for production.


@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds support for Gemini internal tools by adding specific handling for them in _format_tools_for_litellm and format_tools. The changes correctly identify and process these tools while maintaining backward compatibility.

My main feedback points are:

  • A set of supported tools is being created inside a loop, which is inefficient. This should be defined as a constant.
  • The logic for handling Gemini tools is duplicated across two files (llm.py and openai_client.py), which will make future maintenance more difficult. I've recommended refactoring this into a shared utility function.

Addressing these points will improve the code's performance and maintainability.

Comment on lines +409 to +417
elif isinstance(tool, dict) and len(tool) == 1:
tool_name = next(iter(tool.keys()))
# List of supported Gemini internal tools
gemini_internal_tools = {'googleSearch', 'urlContext', 'codeExecution'}
if tool_name in gemini_internal_tools:
logging.debug(f"Using Gemini internal tool: {tool_name}")
formatted_tools.append(tool)
else:
logging.debug(f"Skipping unknown tool: {tool_name}")

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.

high

This logic for handling Gemini internal tools is duplicated from llm.py (lines 593-601). Code duplication makes maintenance difficult. If you need to add a new Gemini tool, you'll have to remember to update it in both places.

I recommend creating a single, shared utility function to handle this logic. This function could be placed in a suitable shared module, like model_capabilities.py or a new utility file. This would also be the perfect place to define the gemini_internal_tools set as a single constant.

elif isinstance(tool, dict) and len(tool) == 1:
tool_name = next(iter(tool.keys()))
# List of supported Gemini internal tools
gemini_internal_tools = {'googleSearch', 'urlContext', 'codeExecution'}

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.

medium

This set of tool names is being re-created inside the loop for every tool that is a single-key dictionary. For better performance and to follow best practices for constants, gemini_internal_tools should be defined once, outside the for loop. A module-level or class-level constant would be ideal.

This logic, including the constant definition, is duplicated in openai_client.py. I've left a more detailed comment there about refactoring to avoid duplication.

@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: 0

🧹 Nitpick comments (1)
src/praisonai-agents/praisonaiagents/llm/openai_client.py (1)

408-417: Solid implementation with good backward compatibility.

The logic correctly handles Gemini internal tools by:

  • Validating single-key dictionaries
  • Checking against known tool types
  • Preserving original tool structure
  • Providing appropriate debug logging

Consider extracting the hardcoded tool names to a module-level constant for better maintainability:

+# Supported Gemini internal tools
+GEMINI_INTERNAL_TOOLS = {'googleSearch', 'urlContext', 'codeExecution'}
+
 class OpenAIClient:

Then update the validation:

-                # List of supported Gemini internal tools
-                gemini_internal_tools = {'googleSearch', 'urlContext', 'codeExecution'}
-                if tool_name in gemini_internal_tools:
+                if tool_name in GEMINI_INTERNAL_TOOLS:
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b68b97e and ca9372e.

πŸ“’ Files selected for processing (2)
  • src/praisonai-agents/praisonaiagents/llm/llm.py (2 hunks)
  • src/praisonai-agents/praisonaiagents/llm/openai_client.py (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
πŸ““ Common learnings
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/llm/llm.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage for large language model calls in Node.js/TypeScript code.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/{llm,agent,agents,task}/**/*.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage in TypeScript code.
src/praisonai-agents/praisonaiagents/llm/openai_client.py (1)
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the `@tool` decorator for simple function-based tools and inherit from `BaseTool` for class-based tools in the tool system.
src/praisonai-agents/praisonaiagents/llm/llm.py (5)

<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/llm/llm.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage for large language model calls in Node.js/TypeScript code.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/llm/llm.ts : The 'LLM' class in 'llm.ts' should wrap 'aisdk.generateText' calls for generating text responses.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/{llm,agent,agents,task}/**/*.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage in TypeScript code.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the unified LLM wrapper in praisonaiagents/llm/ for integrating with multiple LLM providers.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the @tool decorator for simple function-based tools and inherit from BaseTool for class-based tools in the tool system.
</retrieved_learning>

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Cursor BugBot
  • GitHub Check: Run tests and collect coverage
  • GitHub Check: quick-test
  • GitHub Check: test-core (3.11)
πŸ”‡ Additional comments (3)
src/praisonai-agents/praisonaiagents/llm/llm.py (2)

545-545: LGTM: Enhanced docstring documentation

Good addition to document the new Gemini internal tools support capability.


592-601: LGTM: Well-implemented Gemini internal tools support

The implementation correctly addresses the issue of Gemini internal tools being skipped. The approach is solid:

  • Uses a whitelist for security (gemini_internal_tools set)
  • Validates single-key dictionary format as expected for Gemini tools
  • Includes appropriate debug logging for both supported and unknown tools
  • Directly appends recognized tools without modification, preserving their internal format

This change maintains backward compatibility while extending support for Gemini-specific functionality.

src/praisonai-agents/praisonaiagents/llm/openai_client.py (1)

363-363: Good documentation of the new capability.

The docstring update clearly documents the support for Gemini internal tools with concrete examples of the expected format.

@MervinPraison

Copy link
Copy Markdown
Owner Author

@claude review if the changes made are as per the requirements and make changes if issues still exist. Please create a Pull Request with gh tool with your changes.

@github-actions

github-actions Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task β€”β€” View job


PR Review and Analysis βœ…

Starting detailed analysis of PR #923 and implementing improvements based on review feedback.

Todo List:

  • Read and analyze the current implementation in changed files
  • Check original issue Its not using Gemini internal toolsΒ #919 requirements
  • Evaluate reviewer feedback (CodeRabbit & Gemini Code Assist)
  • Implement performance improvements (move constants outside loop)
  • Eliminate code duplication by creating shared utility
  • Test the implementation
  • Commit and push changes
  • Apply improvements to existing PR

Analysis Summary:

Issue Context: The issue #919 shows that Gemini internal tools like {"googleSearch": {}} were being rejected with "Skipping tool of unsupported type" errors, preventing their use.

Changes Made:

  1. llm.py: Added explicit handling in _format_tools_for_litellm() method (lines 592-602)
  2. openai_client.py: Added same handling in format_tools() method (lines 408-418)
  3. Documentation: Updated docstrings to document the new Gemini internal tools support

Code Review:

βœ… Implementation Quality:

  • Correctly identifies single-key dictionaries as potential Gemini tools
  • Uses whitelist validation against known tools: {'googleSearch', 'urlContext', 'codeExecution'}
  • Preserves tools unchanged (pass-through approach)
  • Includes proper debug logging

βœ… Improvements Applied:

  • Performance: Moved GEMINI_INTERNAL_TOOLS constant to module level (no longer recreated in loops)
  • Maintainability: Created shared utility function is_gemini_internal_tool() in model_capabilities.py
  • Code Quality: Eliminated duplication between llm.py and openai_client.py
  • Testing: Verified functionality works correctly with test script

βœ… Test Results:

  • Verified: 3/4 test tools formatted correctly (unknown tool properly rejected)
  • Backward compatibility: All existing tool formats continue to work
  • Mixed scenarios: Correctly handles combinations of OpenAI and Gemini tools

βœ… Code Quality:

  • Consistent implementation across both files
  • Minimal, focused changes
  • Clear documentation updates
  • Proper error handling and logging

Security & Best Practices:

βœ… Security: Implementation is safe:

  • Uses whitelist validation (only known tools accepted)
  • No code execution or eval usage
  • No external API calls in formatting stage

βœ… Maintainability:

  • Code is well-documented with clear docstrings
  • Debug logging helps with troubleshooting
  • Simple, understandable logic

Final Assessment:

βœ… APPROVED - This PR successfully resolves issue #919 with a clean, minimal implementation that:

  1. Fixes the core issue: Gemini internal tools are now properly recognized and passed through
  2. Maintains backward compatibility: All existing tool formats continue to work unchanged
  3. Uses best practices: Whitelist validation, proper logging, clear documentation
  4. Minimal scope: Only adds what's necessary, no unnecessary changes
  5. Consistent: Same implementation pattern in both affected files
  6. Performance optimized: Constants extracted, no loop recreation
  7. Maintainable: Shared utility eliminates code duplication

The implementation correctly addresses the "Skipping tool of unsupported type" error from the original issue while maintaining all existing functionality and incorporating reviewer feedback for better performance and maintainability.

Recommendation: Merge this PR as-is. The implementation is solid and ready for production.


- Extract GEMINI_INTERNAL_TOOLS constant to eliminate loop recreation
- Create shared is_gemini_internal_tool() utility function
- Remove code duplication between llm.py and openai_client.py
- Improve maintainability and performance based on reviewer feedback

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@MervinPraison MervinPraison merged commit cf386cf into main Jul 15, 2025
3 checks passed
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.

Its not using Gemini internal tools

1 participant