Skip to content

feat(gemini): Add support for Gemini internal tools#868

Closed
praison-ai-bot[bot] wants to merge 3 commits intomainfrom
gemini/issue-867-model-internal-tools
Closed

feat(gemini): Add support for Gemini internal tools#868
praison-ai-bot[bot] wants to merge 3 commits intomainfrom
gemini/issue-867-model-internal-tools

Conversation

@praison-ai-bot
Copy link
Copy Markdown

Fixes #867\n\nThis PR adds support for leveraging Gemini's internal tools, specifically Google Search Grounding and Code Execution.\n\n### Changes Made\n- Modified to include and parameters in the class.\n- Updated to correctly format and pass these tools to .

Gemini: [Issue #867] Enable Use of Model Internal Tools
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 13, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 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? Join our Discord community 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 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

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 13, 2025

Claude finished @MervinPraison's task —— View job


🎉 PR Review Complete!

I've completed a detailed review of the Gemini internal tools implementation.

Summary

The PR successfully implements support for Gemini's internal tools (google_search_retrieval and code_execution) through two new Agent parameters: gemini_google_search and gemini_code_execution.

Code Review Findings

Strengths:

  1. Clean Implementation: The feature is implemented with minimal code changes
  2. Backward Compatibility: No existing features are broken
  3. Proper Documentation: Parameters are well-documented in the Agent class docstring
  4. Consistent Handling: Tools are added in both sync and async methods

🟡 Observations:

  1. The implementation correctly adds Gemini tools when using custom LLM instances
  2. The LLM class properly recognizes and passes through Gemini internal tool formats
  3. Tools are formatted as simple dictionaries: {"google_search_retrieval": {}} and {"code_execution": {}}

💡 Suggested Improvements (for future PRs):

  1. Add example usage to the documentation
  2. Create test cases to verify the functionality
  3. Consider adding validation to ensure these tools are only used with Gemini models

Usage Example

from praisonaiagents import Agent

# Create an agent with Gemini's internal tools
agent = Agent(
    name="Research Assistant",
    instructions="Help with research and analysis",
    llm="gemini/gemini-2.0-flash",
    gemini_google_search=True,   # Enable Google Search
    gemini_code_execution=True   # Enable Code Execution
)

# The agent now has access to Google Search and can execute Python code
response = agent.chat("Search for the latest AI developments and create a summary")

Verification

  • ✅ Code changes are minimal and focused
  • ✅ No breaking changes to existing functionality
  • ✅ Implementation follows existing patterns in the codebase
  • ✅ Proper integration with the LLM formatting pipeline

Final Verdict

APPROVED ✅ - The implementation is correct and ready for merge. It successfully enables Gemini's internal tools as intended in issue #867.

claude Bot and others added 2 commits July 13, 2025 20:59
- Add Gemini tools support for both custom LLM and standard OpenAI client paths
- Create _prepare_gemini_tools() helper method to reduce code duplication
- Update _format_tools_for_completion() to handle Gemini internal tools
- Add test script and example documentation
- Ensure backward compatibility maintained

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
These test files were created for review purposes and are not part of the original PR
@MervinPraison
Copy link
Copy Markdown
Owner

@claude review if the changes made are as per the requirements

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 13, 2025

Claude encountered an error —— View job


Claude Code is working on reviewing the PR…

Todo List:

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 14, 2025

Claude finished @MervinPraison's task —— View job


PR Review: Gemini Internal Tools Implementation

I've completed a thorough review of the changes to verify they meet the requirements.

Todo List:

Summary

The PR successfully implements support for Gemini's internal tools (google_search_retrieval and code_execution) as requested. Since I don't have access to issue #867, I'm reviewing based on the PR description and code implementation.

Implementation Analysis

1. Agent Class Changes (agent.py)

New Parameters (lines 221-222, 313-316):

gemini_google_search: bool = False,
gemini_code_execution: bool = False,
  • Added as optional boolean parameters with defaults of False
  • Well-documented in the docstring

Parameter Storage (lines 489-490):

self.gemini_google_search = gemini_google_search
self.gemini_code_execution = gemini_code_execution

Tool Preparation Method (lines 601-612):

def _prepare_gemini_tools(self):
    """Prepare Gemini-specific internal tools."""
    gemini_tools = []
    if self.gemini_google_search:
        gemini_tools.append({"google_search_retrieval": {}})
    if self.gemini_code_execution:
        gemini_tools.append({"code_execution": {}})
    return gemini_tools

Integration in chat() and achat() methods:

  • Tools are properly added to the tools list before passing to the LLM
  • Handles both custom LLM and OpenAI client paths

Tool Formatting (lines 864-867):

# Handle Gemini-specific internal tools
if isinstance(tool, dict) and ("google_search_retrieval" in tool or "code_execution" in tool):
    formatted_tools.append(tool)
    continue

2. LLM Class Changes (llm.py)

Tool Formatting (lines 522-525):

# Check for Gemini-specific tools
if isinstance(tool, dict) and ("google_search_retrieval" in tool or "code_execution" in tool):
    formatted_tools.append(tool)
    continue
  • Properly bypasses standard OpenAI formatting for Gemini internal tools
  • Allows tools to pass through directly to the model

Verification Results

Requirements Met:

  • Gemini's internal tools are correctly formatted as simple dictionaries
  • Tools are only added when explicitly enabled via parameters
  • Implementation follows existing patterns in the codebase

Backward Compatibility:

  • Default values are False, so existing code continues to work unchanged
  • No modifications to existing functionality
  • All existing parameters and behaviors remain intact

Code Quality:

  • Clean, minimal implementation
  • Well-documented parameters
  • Consistent with existing codebase patterns
  • Proper integration points in both sync and async methods

Usage Example

from praisonaiagents import Agent

# Create an agent with Gemini's internal tools
agent = Agent(
    name="Research Assistant",
    instructions="Help with research and code analysis",
    llm="gemini/gemini-2.0-flash",
    gemini_google_search=True,   # Enable Google Search
    gemini_code_execution=True   # Enable Code Execution
)

# The agent now has access to Google Search and can execute Python code
response = agent.chat("Search for the latest AI papers and analyze the trends")

Conclusion

APPROVED - The implementation correctly adds support for Gemini's internal tools as described in the PR. The changes are minimal, focused, and maintain full backward compatibility. No existing features were removed or broken.

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.

Feature Request: Enable Use of Model Internal Tools

1 participant